1139825Simp/*- 2251709Sjeff * Copyright (c) 2002-2005, 2009, 2013 Jeffrey Roberson <jeff@FreeBSD.org> 3148078Srwatson * Copyright (c) 2004, 2005 Bosko Milekic <bmilekic@FreeBSD.org> 4148078Srwatson * All rights reserved. 592654Sjeff * 692654Sjeff * Redistribution and use in source and binary forms, with or without 792654Sjeff * modification, are permitted provided that the following conditions 892654Sjeff * are met: 992654Sjeff * 1. Redistributions of source code must retain the above copyright 1092654Sjeff * notice unmodified, this list of conditions, and the following 1192654Sjeff * disclaimer. 1292654Sjeff * 2. Redistributions in binary form must reproduce the above copyright 1392654Sjeff * notice, this list of conditions and the following disclaimer in the 1492654Sjeff * documentation and/or other materials provided with the distribution. 1592654Sjeff * 1692654Sjeff * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1792654Sjeff * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1892654Sjeff * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1992654Sjeff * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2092654Sjeff * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2192654Sjeff * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2292654Sjeff * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2392654Sjeff * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2492654Sjeff * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2592654Sjeff * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2692654Sjeff * 2792654Sjeff * $FreeBSD: stable/10/sys/vm/uma_int.h 316835 2017-04-14 14:11:59Z avg $ 2892654Sjeff * 2992654Sjeff */ 3092654Sjeff 3192654Sjeff/* 3292654Sjeff * This file includes definitions, structures, prototypes, and inlines that 3392654Sjeff * should not be used outside of the actual implementation of UMA. 3492654Sjeff */ 3592654Sjeff 3692654Sjeff/* 3792654Sjeff * Here's a quick description of the relationship between the objects: 3892654Sjeff * 39129906Sbmilekic * Kegs contain lists of slabs which are stored in either the full bin, empty 4092654Sjeff * bin, or partially allocated bin, to reduce fragmentation. They also contain 4192654Sjeff * the user supplied value for size, which is adjusted for alignment purposes 42129906Sbmilekic * and rsize is the result of that. The Keg also stores information for 4392654Sjeff * managing a hash of page addresses that maps pages to uma_slab_t structures 4492654Sjeff * for pages that don't have embedded uma_slab_t's. 4592654Sjeff * 4692654Sjeff * The uma_slab_t may be embedded in a UMA_SLAB_SIZE chunk of memory or it may 4792654Sjeff * be allocated off the page from a special slab zone. The free list within a 48251709Sjeff * slab is managed with a bitmask. For item sizes that would yield more than 49251709Sjeff * 10% memory waste we potentially allocate a separate uma_slab_t if this will 50251709Sjeff * improve the number of items per slab that will fit. 5192654Sjeff * 5292654Sjeff * The only really gross cases, with regards to memory waste, are for those 5392654Sjeff * items that are just over half the page size. You can get nearly 50% waste, 5492654Sjeff * so you fall back to the memory footprint of the power of two allocator. I 5592654Sjeff * have looked at memory allocation sizes on many of the machines available to 5692654Sjeff * me, and there does not seem to be an abundance of allocations at this range 5792654Sjeff * so at this time it may not make sense to optimize for it. This can, of 5892654Sjeff * course, be solved with dynamic slab sizes. 5992654Sjeff * 60129906Sbmilekic * Kegs may serve multiple Zones but by far most of the time they only serve 61129906Sbmilekic * one. When a Zone is created, a Keg is allocated and setup for it. While 62129906Sbmilekic * the backing Keg stores slabs, the Zone caches Buckets of items allocated 63129906Sbmilekic * from the slabs. Each Zone is equipped with an init/fini and ctor/dtor 64129906Sbmilekic * pair, as well as with its own set of small per-CPU caches, layered above 65129906Sbmilekic * the Zone's general Bucket cache. 66129906Sbmilekic * 67169431Srwatson * The PCPU caches are protected by critical sections, and may be accessed 68169431Srwatson * safely only from their associated CPU, while the Zones backed by the same 69169431Srwatson * Keg all share a common Keg lock (to coalesce contention on the backing 70169431Srwatson * slabs). The backing Keg typically only serves one Zone but in the case of 71169431Srwatson * multiple Zones, one of the Zones is considered the Master Zone and all 72169431Srwatson * Zone-related stats from the Keg are done in the Master Zone. For an 73169431Srwatson * example of a Multi-Zone setup, refer to the Mbuf allocation code. 7492654Sjeff */ 7592654Sjeff 7692654Sjeff/* 7792654Sjeff * This is the representation for normal (Non OFFPAGE slab) 7892654Sjeff * 7992654Sjeff * i == item 8092654Sjeff * s == slab pointer 8192654Sjeff * 8292654Sjeff * <---------------- Page (UMA_SLAB_SIZE) ------------------> 8392654Sjeff * ___________________________________________________________ 8492654Sjeff * | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ___________ | 8592654Sjeff * ||i||i||i||i||i||i||i||i||i||i||i||i||i||i||i| |slab header|| 8692654Sjeff * ||_||_||_||_||_||_||_||_||_||_||_||_||_||_||_| |___________|| 8792654Sjeff * |___________________________________________________________| 8892654Sjeff * 8992654Sjeff * 9092654Sjeff * This is an OFFPAGE slab. These can be larger than UMA_SLAB_SIZE. 9192654Sjeff * 9292654Sjeff * ___________________________________________________________ 9392654Sjeff * | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | 9492654Sjeff * ||i||i||i||i||i||i||i||i||i||i||i||i||i||i||i||i||i||i||i| | 9592654Sjeff * ||_||_||_||_||_||_||_||_||_||_||_||_||_||_||_||_||_||_||_| | 9692654Sjeff * |___________________________________________________________| 9792654Sjeff * ___________ ^ 9892654Sjeff * |slab header| | 9992654Sjeff * |___________|---* 10092654Sjeff * 10192654Sjeff */ 10292654Sjeff 10392654Sjeff#ifndef VM_UMA_INT_H 10492654Sjeff#define VM_UMA_INT_H 10592654Sjeff 10692654Sjeff#define UMA_SLAB_SIZE PAGE_SIZE /* How big are our slabs? */ 10792654Sjeff#define UMA_SLAB_MASK (PAGE_SIZE - 1) /* Mask to get back to the page */ 10892654Sjeff#define UMA_SLAB_SHIFT PAGE_SHIFT /* Number of bits PAGE_MASK */ 10992654Sjeff 110222163Salc#define UMA_BOOT_PAGES 64 /* Pages allocated for startup */ 11192654Sjeff 112249264Sglebius/* Max waste percentage before going to off page slab management */ 113249264Sglebius#define UMA_MAX_WASTE 10 11492654Sjeff 11592654Sjeff/* 11692654Sjeff * I doubt there will be many cases where this is exceeded. This is the initial 11792654Sjeff * size of the hash table for uma_slabs that are managed off page. This hash 11892654Sjeff * does expand by powers of two. Currently it doesn't get smaller. 11992654Sjeff */ 12092654Sjeff#define UMA_HASH_SIZE_INIT 32 12192654Sjeff 12292654Sjeff/* 12392654Sjeff * I should investigate other hashing algorithms. This should yield a low 12492654Sjeff * number of collisions if the pages are relatively contiguous. 12592654Sjeff */ 12692654Sjeff 127251709Sjeff#define UMA_HASH(h, s) ((((uintptr_t)s) >> UMA_SLAB_SHIFT) & (h)->uh_hashmask) 12892654Sjeff 12992654Sjeff#define UMA_HASH_INSERT(h, s, mem) \ 13092654Sjeff SLIST_INSERT_HEAD(&(h)->uh_slab_hash[UMA_HASH((h), \ 131200129Santoine (mem))], (s), us_hlink) 13292654Sjeff#define UMA_HASH_REMOVE(h, s, mem) \ 13392654Sjeff SLIST_REMOVE(&(h)->uh_slab_hash[UMA_HASH((h), \ 134200129Santoine (mem))], (s), uma_slab, us_hlink) 13592654Sjeff 13692654Sjeff/* Hash table for freed address -> slab translation */ 13792654Sjeff 13892654SjeffSLIST_HEAD(slabhead, uma_slab); 13992654Sjeff 14092654Sjeffstruct uma_hash { 14192654Sjeff struct slabhead *uh_slab_hash; /* Hash table for slabs */ 14292654Sjeff int uh_hashsize; /* Current size of the hash table */ 14392654Sjeff int uh_hashmask; /* Mask used during hashing */ 14492654Sjeff}; 14592654Sjeff 14692654Sjeff/* 147205266Skmacy * align field or structure to cache line 148205266Skmacy */ 149205487Skmacy#if defined(__amd64__) 150205487Skmacy#define UMA_ALIGN __aligned(CACHE_LINE_SIZE) 151205487Skmacy#else 152205298Skmacy#define UMA_ALIGN 153205487Skmacy#endif 154205266Skmacy 155205266Skmacy/* 15692654Sjeff * Structures for per cpu queues. 15792654Sjeff */ 15892654Sjeff 15992654Sjeffstruct uma_bucket { 16092654Sjeff LIST_ENTRY(uma_bucket) ub_link; /* Link into the zone */ 161120218Sjeff int16_t ub_cnt; /* Count of free items. */ 162120218Sjeff int16_t ub_entries; /* Max items. */ 163120218Sjeff void *ub_bucket[]; /* actual allocation storage */ 164205487Skmacy}; 16592654Sjeff 16692654Sjefftypedef struct uma_bucket * uma_bucket_t; 16792654Sjeff 16892654Sjeffstruct uma_cache { 16992654Sjeff uma_bucket_t uc_freebucket; /* Bucket we're freeing to */ 17092654Sjeff uma_bucket_t uc_allocbucket; /* Bucket to allocate from */ 171249313Sglebius uint64_t uc_allocs; /* Count of allocations */ 172249313Sglebius uint64_t uc_frees; /* Count of frees */ 173205266Skmacy} UMA_ALIGN; 17492654Sjeff 17592654Sjefftypedef struct uma_cache * uma_cache_t; 17692654Sjeff 17792654Sjeff/* 178129906Sbmilekic * Keg management structure 179129906Sbmilekic * 180129906Sbmilekic * TODO: Optimize for cache line size 181129906Sbmilekic * 182129906Sbmilekic */ 183129906Sbmilekicstruct uma_keg { 184252040Sjeff struct mtx_padalign uk_lock; /* Lock for the keg */ 185129906Sbmilekic struct uma_hash uk_hash; 186129906Sbmilekic 187129906Sbmilekic LIST_HEAD(,uma_zone) uk_zones; /* Keg's zones */ 188129906Sbmilekic LIST_HEAD(,uma_slab) uk_part_slab; /* partially allocated slabs */ 189129906Sbmilekic LIST_HEAD(,uma_slab) uk_free_slab; /* empty slab list */ 190129906Sbmilekic LIST_HEAD(,uma_slab) uk_full_slab; /* full slabs */ 191129906Sbmilekic 192249313Sglebius uint32_t uk_align; /* Alignment mask */ 193249313Sglebius uint32_t uk_pages; /* Total page count */ 194249313Sglebius uint32_t uk_free; /* Count of items free in slabs */ 195252226Sjeff uint32_t uk_reserve; /* Number of reserved items. */ 196249313Sglebius uint32_t uk_size; /* Requested size of each item */ 197249313Sglebius uint32_t uk_rsize; /* Real size of each item */ 198249313Sglebius uint32_t uk_maxpages; /* Maximum number of pages to alloc */ 199129906Sbmilekic 200129906Sbmilekic uma_init uk_init; /* Keg's init routine */ 201129906Sbmilekic uma_fini uk_fini; /* Keg's fini routine */ 202129906Sbmilekic uma_alloc uk_allocf; /* Allocation function */ 203129906Sbmilekic uma_free uk_freef; /* Free routine */ 204129906Sbmilekic 205247360Sattilio u_long uk_offset; /* Next free offset from base KVA */ 206247360Sattilio vm_offset_t uk_kva; /* Zone base KVA */ 207129906Sbmilekic uma_zone_t uk_slabzone; /* Slab zone backing us, if OFFPAGE */ 208129906Sbmilekic 209249313Sglebius uint16_t uk_pgoff; /* Offset to uma_slab struct */ 210249313Sglebius uint16_t uk_ppera; /* pages per allocation from backend */ 211249313Sglebius uint16_t uk_ipers; /* Items per slab */ 212249313Sglebius uint32_t uk_flags; /* Internal flags */ 213249264Sglebius 214249264Sglebius /* Least used fields go to the last cache line. */ 215249264Sglebius const char *uk_name; /* Name of creating zone. */ 216249264Sglebius LIST_ENTRY(uma_keg) uk_link; /* List of all kegs */ 217129906Sbmilekic}; 218187681Sjefftypedef struct uma_keg * uma_keg_t; 219129906Sbmilekic 220251709Sjeff/* 221251709Sjeff * Free bits per-slab. 222251709Sjeff */ 223251709Sjeff#define SLAB_SETSIZE (PAGE_SIZE / UMA_SMALLEST_UNIT) 224251709SjeffBITSET_DEFINE(slabbits, SLAB_SETSIZE); 225129906Sbmilekic 226251709Sjeff/* 227251709Sjeff * The slab structure manages a single contiguous allocation from backing 228251709Sjeff * store and subdivides it into individually allocatable items. 229251709Sjeff */ 230251709Sjeffstruct uma_slab { 231129906Sbmilekic uma_keg_t us_keg; /* Keg we live in */ 232129906Sbmilekic union { 233129906Sbmilekic LIST_ENTRY(uma_slab) _us_link; /* slabs in zone */ 234129906Sbmilekic unsigned long _us_size; /* Size of allocation */ 235129906Sbmilekic } us_type; 236129906Sbmilekic SLIST_ENTRY(uma_slab) us_hlink; /* Link for hash table */ 237249313Sglebius uint8_t *us_data; /* First item */ 238251709Sjeff struct slabbits us_free; /* Free bitmask. */ 239251709Sjeff#ifdef INVARIANTS 240251709Sjeff struct slabbits us_debugfree; /* Debug bitmask. */ 241251709Sjeff#endif 242249313Sglebius uint16_t us_freecount; /* How many are free? */ 243249313Sglebius uint8_t us_flags; /* Page flags see uma.h */ 244251709Sjeff uint8_t us_pad; /* Pad to 32bits, unused. */ 245129906Sbmilekic}; 246129906Sbmilekic 247251709Sjeff#define us_link us_type._us_link 248251709Sjeff#define us_size us_type._us_size 249129906Sbmilekic 250129906Sbmilekic/* 251129906Sbmilekic * The slab structure for UMA_ZONE_REFCNT zones for whose items we 252129906Sbmilekic * maintain reference counters in the slab for. 253129906Sbmilekic */ 254129906Sbmilekicstruct uma_slab_refcnt { 255251709Sjeff struct uma_slab us_head; /* slab header data */ 256251709Sjeff uint32_t us_refcnt[0]; /* Actually larger. */ 257129906Sbmilekic}; 258129906Sbmilekic 259129906Sbmilekictypedef struct uma_slab * uma_slab_t; 260129906Sbmilekictypedef struct uma_slab_refcnt * uma_slabrefcnt_t; 261187681Sjefftypedef uma_slab_t (*uma_slaballoc)(uma_zone_t, uma_keg_t, int); 262129906Sbmilekic 263187681Sjeffstruct uma_klink { 264187681Sjeff LIST_ENTRY(uma_klink) kl_link; 265187681Sjeff uma_keg_t kl_keg; 266187681Sjeff}; 267187681Sjefftypedef struct uma_klink *uma_klink_t; 268187681Sjeff 269132842Sbmilekic/* 27092654Sjeff * Zone management structure 27192654Sjeff * 27292654Sjeff * TODO: Optimize for cache line size 27392654Sjeff * 27492654Sjeff */ 27592654Sjeffstruct uma_zone { 276252040Sjeff struct mtx_padalign uz_lock; /* Lock for the zone */ 277252040Sjeff struct mtx_padalign *uz_lockptr; 278252040Sjeff const char *uz_name; /* Text name of the zone */ 27992654Sjeff 280129906Sbmilekic LIST_ENTRY(uma_zone) uz_link; /* List of all zones in keg */ 281251894Sjeff LIST_HEAD(,uma_bucket) uz_buckets; /* full buckets */ 28292654Sjeff 283187681Sjeff LIST_HEAD(,uma_klink) uz_kegs; /* List of kegs. */ 284187681Sjeff struct uma_klink uz_klink; /* klink for first keg. */ 285187681Sjeff 286187681Sjeff uma_slaballoc uz_slab; /* Allocate a slab from the backend. */ 28792654Sjeff uma_ctor uz_ctor; /* Constructor for each allocation */ 28892654Sjeff uma_dtor uz_dtor; /* Destructor */ 28992654Sjeff uma_init uz_init; /* Initializer for each item */ 290251826Sjeff uma_fini uz_fini; /* Finalizer for each item. */ 291251826Sjeff uma_import uz_import; /* Import new memory to cache. */ 292251826Sjeff uma_release uz_release; /* Release memory from cache. */ 293251826Sjeff void *uz_arg; /* Import/release argument. */ 294129906Sbmilekic 295249313Sglebius uint32_t uz_flags; /* Flags inherited from kegs */ 296249313Sglebius uint32_t uz_size; /* Size inherited from kegs */ 297205266Skmacy 298251826Sjeff volatile u_long uz_allocs UMA_ALIGN; /* Total number of allocations */ 299251826Sjeff volatile u_long uz_fails; /* Total number of alloc failures */ 300251826Sjeff volatile u_long uz_frees; /* Total number of frees */ 301249313Sglebius uint64_t uz_sleeps; /* Total number of alloc sleeps */ 302260300Smav uint16_t uz_count; /* Amount of items in full bucket */ 303260300Smav uint16_t uz_count_min; /* Minimal amount of items there */ 304129906Sbmilekic 305243998Spjd /* The next three fields are used to print a rate-limited warnings. */ 306243998Spjd const char *uz_warning; /* Warning to print on failure */ 307243998Spjd struct timeval uz_ratecheck; /* Warnings rate-limiting */ 308243998Spjd 30992654Sjeff /* 31092654Sjeff * This HAS to be the last item because we adjust the zone size 31192654Sjeff * based on NCPU and then allocate the space for the zones. 31292654Sjeff */ 313281943Sscottl struct uma_cache uz_cpu[1]; /* Per cpu caches */ 31492654Sjeff}; 31592654Sjeff 316120223Sjeff/* 317120223Sjeff * These flags must not overlap with the UMA_ZONE flags specified in uma.h. 318120223Sjeff */ 319187681Sjeff#define UMA_ZFLAG_MULTI 0x04000000 /* Multiple kegs in the zone. */ 320187681Sjeff#define UMA_ZFLAG_DRAINING 0x08000000 /* Running zone_drain. */ 321252226Sjeff#define UMA_ZFLAG_BUCKET 0x10000000 /* Bucket zone. */ 322148072Ssilby#define UMA_ZFLAG_INTERNAL 0x20000000 /* No offpage no PCPU. */ 323148072Ssilby#define UMA_ZFLAG_FULL 0x40000000 /* Reached uz_maxpages */ 324148072Ssilby#define UMA_ZFLAG_CACHEONLY 0x80000000 /* Don't ask VM for buckets. */ 32594631Sjeff 326252226Sjeff#define UMA_ZFLAG_INHERIT \ 327252226Sjeff (UMA_ZFLAG_INTERNAL | UMA_ZFLAG_CACHEONLY | UMA_ZFLAG_BUCKET) 328187681Sjeff 329251826Sjeffstatic inline uma_keg_t 330251826Sjeffzone_first_keg(uma_zone_t zone) 331251826Sjeff{ 332252040Sjeff uma_klink_t klink; 333251826Sjeff 334252040Sjeff klink = LIST_FIRST(&zone->uz_kegs); 335252040Sjeff return (klink != NULL) ? klink->kl_keg : NULL; 336251826Sjeff} 337251826Sjeff 338205266Skmacy#undef UMA_ALIGN 339205266Skmacy 340148690Srwatson#ifdef _KERNEL 34192654Sjeff/* Internal prototypes */ 342249313Sglebiusstatic __inline uma_slab_t hash_sfind(struct uma_hash *hash, uint8_t *data); 343287945Srstonevoid *uma_large_malloc(vm_size_t size, int wait); 34492654Sjeffvoid uma_large_free(uma_slab_t slab); 34592654Sjeff 34692654Sjeff/* Lock Macros */ 34792654Sjeff 348187681Sjeff#define KEG_LOCK_INIT(k, lc) \ 34995758Sjeff do { \ 35095758Sjeff if ((lc)) \ 351187681Sjeff mtx_init(&(k)->uk_lock, (k)->uk_name, \ 352187681Sjeff (k)->uk_name, MTX_DEF | MTX_DUPOK); \ 35395758Sjeff else \ 354187681Sjeff mtx_init(&(k)->uk_lock, (k)->uk_name, \ 35595758Sjeff "UMA zone", MTX_DEF | MTX_DUPOK); \ 35695758Sjeff } while (0) 357252040Sjeff 358187681Sjeff#define KEG_LOCK_FINI(k) mtx_destroy(&(k)->uk_lock) 359187681Sjeff#define KEG_LOCK(k) mtx_lock(&(k)->uk_lock) 360187681Sjeff#define KEG_UNLOCK(k) mtx_unlock(&(k)->uk_lock) 36192654Sjeff 362252040Sjeff#define ZONE_LOCK_INIT(z, lc) \ 363252040Sjeff do { \ 364252040Sjeff if ((lc)) \ 365252040Sjeff mtx_init(&(z)->uz_lock, (z)->uz_name, \ 366252040Sjeff (z)->uz_name, MTX_DEF | MTX_DUPOK); \ 367252040Sjeff else \ 368252040Sjeff mtx_init(&(z)->uz_lock, (z)->uz_name, \ 369252040Sjeff "UMA zone", MTX_DEF | MTX_DUPOK); \ 370252040Sjeff } while (0) 371252040Sjeff 372252040Sjeff#define ZONE_LOCK(z) mtx_lock((z)->uz_lockptr) 373252040Sjeff#define ZONE_TRYLOCK(z) mtx_trylock((z)->uz_lockptr) 374252040Sjeff#define ZONE_UNLOCK(z) mtx_unlock((z)->uz_lockptr) 375252040Sjeff#define ZONE_LOCK_FINI(z) mtx_destroy(&(z)->uz_lock) 376252040Sjeff 37792654Sjeff/* 37892654Sjeff * Find a slab within a hash table. This is used for OFFPAGE zones to lookup 37992654Sjeff * the slab structure. 38092654Sjeff * 38192654Sjeff * Arguments: 38292654Sjeff * hash The hash table to search. 38392654Sjeff * data The base page of the item. 38492654Sjeff * 38592654Sjeff * Returns: 38692654Sjeff * A pointer to a slab if successful, else NULL. 38792654Sjeff */ 38892654Sjeffstatic __inline uma_slab_t 389249313Sglebiushash_sfind(struct uma_hash *hash, uint8_t *data) 39092654Sjeff{ 39192654Sjeff uma_slab_t slab; 39292654Sjeff int hval; 39392654Sjeff 39492654Sjeff hval = UMA_HASH(hash, data); 39592654Sjeff 39692654Sjeff SLIST_FOREACH(slab, &hash->uh_slab_hash[hval], us_hlink) { 397249313Sglebius if ((uint8_t *)slab->us_data == data) 39892654Sjeff return (slab); 39992654Sjeff } 40092654Sjeff return (NULL); 40192654Sjeff} 40292654Sjeff 403103531Sjeffstatic __inline uma_slab_t 404103531Sjeffvtoslab(vm_offset_t va) 405103531Sjeff{ 406103531Sjeff vm_page_t p; 40792654Sjeff 408103531Sjeff p = PHYS_TO_VM_PAGE(pmap_kextract(va)); 409255626Skib return ((uma_slab_t)p->plinks.s.pv); 410103531Sjeff} 411103531Sjeff 412103531Sjeffstatic __inline void 413103531Sjeffvsetslab(vm_offset_t va, uma_slab_t slab) 414103531Sjeff{ 415103531Sjeff vm_page_t p; 416103531Sjeff 417138114Scognet p = PHYS_TO_VM_PAGE(pmap_kextract(va)); 418254182Skib p->plinks.s.pv = slab; 419103531Sjeff} 420103531Sjeff 421106277Sjeff/* 422106277Sjeff * The following two functions may be defined by architecture specific code 423106277Sjeff * if they can provide more effecient allocation functions. This is useful 424106277Sjeff * for using direct mapped addresses. 425106277Sjeff */ 426287945Srstonevoid *uma_small_alloc(uma_zone_t zone, vm_size_t bytes, uint8_t *pflag, 427287945Srstone int wait); 428287945Srstonevoid uma_small_free(void *mem, vm_size_t size, uint8_t flags); 429148690Srwatson#endif /* _KERNEL */ 430106277Sjeff 43192654Sjeff#endif /* VM_UMA_INT_H */ 432