60#include <sys/kernel.h>
62#include <sys/vmmeter.h>
64#include <sys/smr_types.h>
83#define VM_RADIX_WIDTH 4
85#define VM_RADIX_WIDTH 3
88#define VM_RADIX_COUNT (1 << VM_RADIX_WIDTH)
89#define VM_RADIX_MASK (VM_RADIX_COUNT - 1)
90#define VM_RADIX_LIMIT \
91 (howmany(sizeof(vm_pindex_t) * NBBY, VM_RADIX_WIDTH) - 1)
94#define VM_RADIX_ISLEAF 0x1
95#define VM_RADIX_FLAGS 0x1
96#define VM_RADIX_PAD VM_RADIX_FLAGS
99#define VM_RADIX_UNITLEVEL(lev) \
100 ((vm_pindex_t)1 << ((lev) * VM_RADIX_WIDTH))
107struct vm_radix_node {
108 vm_pindex_t rn_owner;
124static struct vm_radix_node *
127 struct vm_radix_node *rnode;
138 if (rnode->rn_last != 0) {
143 rnode->rn_owner = owner;
144 rnode->rn_count = count;
145 rnode->rn_clev = clevel;
158 KASSERT(rnode->rn_count == 0,
159 (
"vm_radix_node_put: rnode %p has %d children", rnode,
164 KASSERT(smr_unserialized_load(&rnode->rn_child[slot],
true) ==
165 NULL, (
"vm_radix_node_put: rnode %p has a child", rnode));
169 rnode->rn_last = last + 1;
184static __inline vm_pindex_t
200static __inline
struct vm_radix_node *
206 return (smr_unserialized_load(p,
true));
208 return (smr_serialized_load(p,
true));
212 __assert_unreachable();
222 smr_unserialized_store(p, v,
true);
225 smr_serialized_store(p, v,
true);
228 panic(
"vm_radix_node_store: Not supported in smr section.");
235static __inline
struct vm_radix_node *
256static __inline boolean_t
266static __inline vm_page_t
291static __inline uint16_t
296 KASSERT(index1 != index2, (
"%s: passing the same key value %jx",
297 __func__, (uintmax_t)index1));
309static __inline boolean_t
315 return (idx != rnode->rn_owner);
327 struct vm_radix_node *child;
331 (
"vm_radix_reclaim_allnodes_int: bad count in rnode %p", rnode));
332 for (slot = 0; rnode->rn_count != 0; slot++) {
344#ifndef UMA_MD_SMALL_ALLOC
362 ((vm_paddr_t)
vm_cnt.v_page_count * PAGE_SIZE) / (PAGE_SIZE +
363 sizeof(
struct vm_radix_node))))
364 panic(
"%s: unable to reserve KVA", __func__);
376 sizeof(
struct vm_radix_node), NULL, NULL, NULL, NULL,
388 vm_pindex_t index, newind;
389 struct vm_radix_node *rnode, *tmp;
395 index = page->pindex;
406 parentp = (smrnode_t *)&rtree->
rt_root;
410 if (m->pindex == index)
411 panic(
"%s: key %jx is already present",
412 __func__, (uintmax_t)index);
427 parentp = &rnode->rn_child[slot];
443 newind = rnode->rn_owner;
465 struct vm_radix_node *rnode;
477static __always_inline vm_page_t
481 struct vm_radix_node *rnode;
486 while (rnode != NULL) {
489 if (m->pindex == index)
539 struct vm_radix_node *child, *rnode;
550 if (m->pindex >= index)
565 if (index > rnode->rn_owner) {
567 KASSERT(++loops < 1000,
568 (
"vm_radix_lookup_ge: too many loops"));
578 rnode = stack[--tos];
591 index = rnode->rn_owner;
593 (
"vm_radix_lookup_ge: keybarr failed"));
599 if (m->pindex >= index)
601 }
else if (child != NULL)
618 if (m->pindex >= index)
620 }
else if (child != NULL)
625 (
"vm_radix_lookup_ge: child is radix node"));
633 KASSERT(rnode->rn_clev > 0,
634 (
"vm_radix_lookup_ge: pushing leaf's parent"));
636 (
"vm_radix_lookup_ge: stack overflow"));
637 stack[tos++] = rnode;
651 struct vm_radix_node *child, *rnode;
662 if (m->pindex <= index)
677 if (index > rnode->rn_owner) {
682 KASSERT(++loops < 1000,
683 (
"vm_radix_lookup_le: too many loops"));
693 rnode = stack[--tos];
695 rnode->rn_clev) == 0);
707 (
"vm_radix_lookup_le: keybarr failed"));
713 if (m->pindex <= index)
715 }
else if (child != NULL)
732 if (m->pindex <= index)
734 }
else if (child != NULL)
739 (
"vm_radix_lookup_le: child is radix node"));
747 KASSERT(rnode->rn_clev > 0,
748 (
"vm_radix_lookup_le: pushing leaf's parent"));
750 (
"vm_radix_lookup_le: stack overflow"));
751 stack[tos++] = rnode;
763 struct vm_radix_node *rnode, *parent, *tmp;
770 if (m->pindex != index)
783 if (m->pindex != index)
787 if (rnode->rn_count > 1)
794 (
"%s: invalid node configuration", __func__));
801 &parent->rn_child[slot],
LOCKED) == rnode,
802 (
"%s: invalid child value", __func__));
827 struct vm_radix_node *root;
844 struct vm_radix_node *rnode, *tmp;
849 index = newpage->pindex;
852 panic(
"%s: replacing page on an empty trie", __func__);
855 if (m->pindex != index)
856 panic(
"%s: original replacing root key not found",
866 if (m->pindex == index) {
868 (
struct vm_radix_node *)((uintptr_t)newpage |
877 panic(
"%s: original replacing page not found", __func__);
890DB_SHOW_COMMAND(radixnode, db_show_radixnode)
892 struct vm_radix_node *rnode, *tmp;
897 rnode = (
struct vm_radix_node *)addr;
898 db_printf(
"radixnode %p, owner %jx, children count %u, level %u:\n",
899 (
void *)rnode, (uintmax_t)rnode->rn_owner, rnode->rn_count,
904 db_printf(
"slot: %d, val: %p, page: %p, clev: %d\n",
void uma_zwait(uma_zone_t zone)
void * uma_zalloc_smr(uma_zone_t zone, int flags)
smr_t uma_zone_get_smr(uma_zone_t zone)
void uma_zfree_smr(uma_zone_t zone, void *item)
uma_zone_t uma_zcreate(const char *name, size_t size, uma_ctor ctor, uma_dtor dtor, uma_init uminit, uma_fini fini, int align, uint32_t flags)
int uma_zone_reserve_kva(uma_zone_t zone, int nitems)
struct vmmeter __read_mostly vm_cnt
static __inline struct vm_radix_node * vm_radix_root_load(struct vm_radix *rtree, enum vm_radix_access access)
static __inline boolean_t vm_radix_keybarr(struct vm_radix_node *rnode, vm_pindex_t idx)
static __inline void vm_radix_root_store(struct vm_radix *rtree, struct vm_radix_node *rnode, enum vm_radix_access access)
static uma_zone_t vm_radix_node_zone
static void vm_radix_reclaim_allnodes_int(struct vm_radix_node *rnode)
typedef SMR_POINTER(struct vm_radix_node *)
#define VM_RADIX_UNITLEVEL(lev)
void vm_radix_reclaim_allnodes(struct vm_radix *rtree)
static __always_inline vm_page_t _vm_radix_lookup(struct vm_radix *rtree, vm_pindex_t index, enum vm_radix_access access)
static smr_t vm_radix_smr
static __inline void vm_radix_addpage(struct vm_radix_node *rnode, vm_pindex_t index, uint16_t clev, vm_page_t page, enum vm_radix_access access)
void vm_radix_zinit(void)
static __inline vm_page_t vm_radix_topage(struct vm_radix_node *rnode)
int vm_radix_insert(struct vm_radix *rtree, vm_page_t page)
static __inline vm_pindex_t vm_radix_trimkey(vm_pindex_t index, uint16_t level)
static __inline struct vm_radix_node * vm_radix_node_load(smrnode_t *p, enum vm_radix_access access)
static __inline void vm_radix_node_put(struct vm_radix_node *rnode, int8_t last)
vm_page_t vm_radix_lookup_ge(struct vm_radix *rtree, vm_pindex_t index)
vm_page_t vm_radix_replace(struct vm_radix *rtree, vm_page_t newpage)
vm_page_t vm_radix_remove(struct vm_radix *rtree, vm_pindex_t index)
boolean_t vm_radix_is_singleton(struct vm_radix *rtree)
static __inline int vm_radix_slot(vm_pindex_t index, uint16_t level)
static __inline boolean_t vm_radix_isleaf(struct vm_radix_node *rnode)
vm_page_t vm_radix_lookup_unlocked(struct vm_radix *rtree, vm_pindex_t index)
vm_page_t vm_radix_lookup(struct vm_radix *rtree, vm_pindex_t index)
vm_page_t vm_radix_lookup_le(struct vm_radix *rtree, vm_pindex_t index)
static struct vm_radix_node * vm_radix_node_get(vm_pindex_t owner, uint16_t count, uint16_t clevel)
static __inline uint16_t vm_radix_keydiff(vm_pindex_t index1, vm_pindex_t index2)
void vm_radix_reserve_kva(void)
static void vm_radix_node_store(smrnode_t *p, struct vm_radix_node *v, enum vm_radix_access access)