18355f576SJeff Roberson /* 2f461cf22SJeff Roberson * Copyright (c) 2002, Jeffrey Roberson <jeff@freebsd.org> 38355f576SJeff Roberson * All rights reserved. 48355f576SJeff Roberson * 58355f576SJeff Roberson * Redistribution and use in source and binary forms, with or without 68355f576SJeff Roberson * modification, are permitted provided that the following conditions 78355f576SJeff Roberson * are met: 88355f576SJeff Roberson * 1. Redistributions of source code must retain the above copyright 98355f576SJeff Roberson * notice unmodified, this list of conditions, and the following 108355f576SJeff Roberson * disclaimer. 118355f576SJeff Roberson * 2. Redistributions in binary form must reproduce the above copyright 128355f576SJeff Roberson * notice, this list of conditions and the following disclaimer in the 138355f576SJeff Roberson * documentation and/or other materials provided with the distribution. 148355f576SJeff Roberson * 158355f576SJeff Roberson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 168355f576SJeff Roberson * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 178355f576SJeff Roberson * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 188355f576SJeff Roberson * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 198355f576SJeff Roberson * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 208355f576SJeff Roberson * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 218355f576SJeff Roberson * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 228355f576SJeff Roberson * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 238355f576SJeff Roberson * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 248355f576SJeff Roberson * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 258355f576SJeff Roberson * 268355f576SJeff Roberson * $FreeBSD$ 278355f576SJeff Roberson * 288355f576SJeff Roberson */ 298355f576SJeff Roberson 308355f576SJeff Roberson /* 318355f576SJeff Roberson * uma.h - External definitions for the Universal Memory Allocator 328355f576SJeff Roberson * 338355f576SJeff Roberson */ 348355f576SJeff Roberson 358355f576SJeff Roberson #ifndef VM_UMA_H 368355f576SJeff Roberson #define VM_UMA_H 378355f576SJeff Roberson 388355f576SJeff Roberson #include <sys/param.h> /* For NULL */ 398355f576SJeff Roberson #include <sys/malloc.h> /* For M_* */ 408355f576SJeff Roberson 418355f576SJeff Roberson /* User visable parameters */ 428355f576SJeff Roberson #define UMA_SMALLEST_UNIT (PAGE_SIZE / 256) /* Smallest item allocated */ 438355f576SJeff Roberson 448355f576SJeff Roberson /* Types and type defs */ 458355f576SJeff Roberson 468355f576SJeff Roberson struct uma_zone; 478355f576SJeff Roberson /* Opaque type used as a handle to the zone */ 488355f576SJeff Roberson typedef struct uma_zone * uma_zone_t; 498355f576SJeff Roberson 508355f576SJeff Roberson /* 518355f576SJeff Roberson * Item constructor 528355f576SJeff Roberson * 538355f576SJeff Roberson * Arguments: 548355f576SJeff Roberson * item A pointer to the memory which has been allocated. 558355f576SJeff Roberson * arg The arg field passed to uma_zalloc_arg 568355f576SJeff Roberson * size The size of the allocated item 57b23f72e9SBrian Feldman * flags See zalloc flags 588355f576SJeff Roberson * 598355f576SJeff Roberson * Returns: 60b23f72e9SBrian Feldman * 0 on success 61b23f72e9SBrian Feldman * errno on failure 628355f576SJeff Roberson * 638355f576SJeff Roberson * Discussion: 648355f576SJeff Roberson * The constructor is called just before the memory is returned 6529b4d526SSheldon Hearn * to the user. It may block if necessary. 668355f576SJeff Roberson */ 67b23f72e9SBrian Feldman typedef int (*uma_ctor)(void *mem, int size, void *arg, int flags); 688355f576SJeff Roberson 698355f576SJeff Roberson /* 708355f576SJeff Roberson * Item destructor 718355f576SJeff Roberson * 728355f576SJeff Roberson * Arguments: 738355f576SJeff Roberson * item A pointer to the memory which has been allocated. 748355f576SJeff Roberson * size The size of the item being destructed. 758355f576SJeff Roberson * arg Argument passed through uma_zfree_arg 768355f576SJeff Roberson * 778355f576SJeff Roberson * Returns: 788355f576SJeff Roberson * Nothing 798355f576SJeff Roberson * 808355f576SJeff Roberson * Discussion: 818355f576SJeff Roberson * The destructor may perform operations that differ from those performed 828355f576SJeff Roberson * by the initializer, but it must leave the object in the same state. 838355f576SJeff Roberson * This IS type stable storage. This is called after EVERY zfree call. 848355f576SJeff Roberson */ 858355f576SJeff Roberson typedef void (*uma_dtor)(void *mem, int size, void *arg); 868355f576SJeff Roberson 878355f576SJeff Roberson /* 888355f576SJeff Roberson * Item initializer 898355f576SJeff Roberson * 908355f576SJeff Roberson * Arguments: 918355f576SJeff Roberson * item A pointer to the memory which has been allocated. 928355f576SJeff Roberson * size The size of the item being initialized. 93b23f72e9SBrian Feldman * flags See zalloc flags 948355f576SJeff Roberson * 958355f576SJeff Roberson * Returns: 96b23f72e9SBrian Feldman * 0 on success 97b23f72e9SBrian Feldman * errno on failure 988355f576SJeff Roberson * 998355f576SJeff Roberson * Discussion: 1008355f576SJeff Roberson * The initializer is called when the memory is cached in the uma zone. 1018355f576SJeff Roberson * this should be the same state that the destructor leaves the object in. 1028355f576SJeff Roberson */ 103b23f72e9SBrian Feldman typedef int (*uma_init)(void *mem, int size, int flags); 1048355f576SJeff Roberson 1058355f576SJeff Roberson /* 1068355f576SJeff Roberson * Item discard function 1078355f576SJeff Roberson * 1088355f576SJeff Roberson * Arguments: 1098355f576SJeff Roberson * item A pointer to memory which has been 'freed' but has not left the 1108355f576SJeff Roberson * zone's cache. 1118355f576SJeff Roberson * size The size of the item being discarded. 1128355f576SJeff Roberson * 1138355f576SJeff Roberson * Returns: 1148355f576SJeff Roberson * Nothing 1158355f576SJeff Roberson * 1168355f576SJeff Roberson * Discussion: 1178355f576SJeff Roberson * This routine is called when memory leaves a zone and is returned to the 1188355f576SJeff Roberson * system for other uses. It is the counter part to the init function. 1198355f576SJeff Roberson */ 1208355f576SJeff Roberson typedef void (*uma_fini)(void *mem, int size); 1218355f576SJeff Roberson 1228355f576SJeff Roberson /* 1238355f576SJeff Roberson * What's the difference between initializing and constructing? 1248355f576SJeff Roberson * 1258355f576SJeff Roberson * The item is initialized when it is cached, and this is the state that the 1268355f576SJeff Roberson * object should be in when returned to the allocator. The purpose of this is 1278355f576SJeff Roberson * to remove some code which would otherwise be called on each allocation by 1288355f576SJeff Roberson * utilizing a known, stable state. This differs from the constructor which 1298355f576SJeff Roberson * will be called on EVERY allocation. 1308355f576SJeff Roberson * 1318355f576SJeff Roberson * For example, in the initializer you may want to initialize embeded locks, 1328355f576SJeff Roberson * NULL list pointers, set up initial states, magic numbers, etc. This way if 13329b4d526SSheldon Hearn * the object is held in the allocator and re-used it won't be necessary to 1348355f576SJeff Roberson * re-initialize it. 1358355f576SJeff Roberson * 1368355f576SJeff Roberson * The constructor may be used to lock a data structure, link it on to lists, 1378355f576SJeff Roberson * bump reference counts or total counts of outstanding structures, etc. 1388355f576SJeff Roberson * 1398355f576SJeff Roberson */ 1408355f576SJeff Roberson 1418355f576SJeff Roberson 1428355f576SJeff Roberson /* Function proto types */ 1438355f576SJeff Roberson 1448355f576SJeff Roberson /* 1458355f576SJeff Roberson * Create a new uma zone 1468355f576SJeff Roberson * 1478355f576SJeff Roberson * Arguments: 1488355f576SJeff Roberson * name The text name of the zone for debugging and stats, this memory 1498355f576SJeff Roberson * should not be freed until the zone has been deallocated. 1508355f576SJeff Roberson * size The size of the object that is being created. 1518355f576SJeff Roberson * ctor The constructor that is called when the object is allocated 1528355f576SJeff Roberson * dtor The destructor that is called when the object is freed. 1538355f576SJeff Roberson * init An initializer that sets up the initial state of the memory. 1548355f576SJeff Roberson * fini A discard function that undoes initialization done by init. 1558355f576SJeff Roberson * ctor/dtor/init/fini may all be null, see notes above. 1568355f576SJeff Roberson * align A bitmask that corisponds to the requested alignment 1578355f576SJeff Roberson * eg 4 would be 0x3 1588355f576SJeff Roberson * flags A set of parameters that control the behavior of the zone 1598355f576SJeff Roberson * 1608355f576SJeff Roberson * Returns: 1618355f576SJeff Roberson * A pointer to a structure which is intended to be opaque to users of 1628355f576SJeff Roberson * the interface. The value may be null if the wait flag is not set. 1638355f576SJeff Roberson */ 164c3bdc05fSAndrew R. Reiter uma_zone_t uma_zcreate(char *name, size_t size, uma_ctor ctor, uma_dtor dtor, 1658355f576SJeff Roberson uma_init uminit, uma_fini fini, int align, 1668355f576SJeff Roberson u_int16_t flags); 1678355f576SJeff Roberson 168b60f5b79SJeff Roberson /* 169099a0e58SBosko Milekic * Create a secondary uma zone 170099a0e58SBosko Milekic * 171099a0e58SBosko Milekic * Arguments: 172099a0e58SBosko Milekic * name The text name of the zone for debugging and stats, this memory 173099a0e58SBosko Milekic * should not be freed until the zone has been deallocated. 174099a0e58SBosko Milekic * ctor The constructor that is called when the object is allocated 175099a0e58SBosko Milekic * dtor The destructor that is called when the object is freed. 176099a0e58SBosko Milekic * zinit An initializer that sets up the initial state of the memory 177099a0e58SBosko Milekic * as the object passes from the Keg's slab to the Zone's cache. 178099a0e58SBosko Milekic * zfini A discard function that undoes initialization done by init 179099a0e58SBosko Milekic * as the object passes from the Zone's cache to the Keg's slab. 180099a0e58SBosko Milekic * 181099a0e58SBosko Milekic * ctor/dtor/zinit/zfini may all be null, see notes above. 182099a0e58SBosko Milekic * Note that the zinit and zfini specified here are NOT 183099a0e58SBosko Milekic * exactly the same as the init/fini specified to uma_zcreate() 184099a0e58SBosko Milekic * when creating a master zone. These zinit/zfini are called 185099a0e58SBosko Milekic * on the TRANSITION from keg to zone (and vice-versa). Once 186099a0e58SBosko Milekic * these are set, the primary zone may alter its init/fini 187099a0e58SBosko Milekic * (which are called when the object passes from VM to keg) 188099a0e58SBosko Milekic * using uma_zone_set_init/fini()) as well as its own 189099a0e58SBosko Milekic * zinit/zfini (unset by default for master zone) with 190099a0e58SBosko Milekic * uma_zone_set_zinit/zfini() (note subtle 'z' prefix). 191099a0e58SBosko Milekic * 192b83e441bSBosko Milekic * master A reference to this zone's Master Zone (Primary Zone), 193b83e441bSBosko Milekic * which contains the backing Keg for the Secondary Zone 194b83e441bSBosko Milekic * being added. 195099a0e58SBosko Milekic * 196099a0e58SBosko Milekic * Returns: 197099a0e58SBosko Milekic * A pointer to a structure which is intended to be opaque to users of 198099a0e58SBosko Milekic * the interface. The value may be null if the wait flag is not set. 199099a0e58SBosko Milekic */ 200099a0e58SBosko Milekic uma_zone_t uma_zsecond_create(char *name, uma_ctor ctor, uma_dtor dtor, 201099a0e58SBosko Milekic uma_init zinit, uma_fini zfini, uma_zone_t master); 202099a0e58SBosko Milekic 203099a0e58SBosko Milekic /* 204b60f5b79SJeff Roberson * Definitions for uma_zcreate flags 205b60f5b79SJeff Roberson * 206b60f5b79SJeff Roberson * These flags share space with UMA_ZFLAGs in uma_int.h. Be careful not to 207b60f5b79SJeff Roberson * overlap when adding new features. 0xf000 is in use by uma_int.h. 208b60f5b79SJeff Roberson */ 2098355f576SJeff Roberson #define UMA_ZONE_PAGEABLE 0x0001 /* Return items not fully backed by 2108355f576SJeff Roberson physical memory XXX Not yet */ 2118355f576SJeff Roberson #define UMA_ZONE_ZINIT 0x0002 /* Initialize with zeros */ 2128355f576SJeff Roberson #define UMA_ZONE_STATIC 0x0004 /* Staticly sized zone */ 2138355f576SJeff Roberson #define UMA_ZONE_OFFPAGE 0x0008 /* Force the slab structure allocation 2148355f576SJeff Roberson off of the real memory */ 2158355f576SJeff Roberson #define UMA_ZONE_MALLOC 0x0010 /* For use by malloc(9) only! */ 2168355f576SJeff Roberson #define UMA_ZONE_NOFREE 0x0020 /* Do not free slabs of this type! */ 21728bc4419SJeff Roberson #define UMA_ZONE_MTXCLASS 0x0040 /* Create a new lock class */ 21899571dc3SJeff Roberson #define UMA_ZONE_VM 0x0080 /* 21999571dc3SJeff Roberson * Used for internal vm datastructures 22099571dc3SJeff Roberson * only. 22199571dc3SJeff Roberson */ 22299571dc3SJeff Roberson #define UMA_ZONE_HASH 0x0100 /* 22399571dc3SJeff Roberson * Use a hash table instead of caching 22499571dc3SJeff Roberson * information in the vm_page. 22599571dc3SJeff Roberson */ 226099a0e58SBosko Milekic #define UMA_ZONE_SECONDARY 0x0200 /* Zone is a Secondary Zone */ 227099a0e58SBosko Milekic #define UMA_ZONE_REFCNT 0x0400 /* Allocate refcnts in slabs */ 228099a0e58SBosko Milekic #define UMA_ZONE_MAXBUCKET 0x0800 /* Use largest buckets */ 2298355f576SJeff Roberson 2308355f576SJeff Roberson /* Definitions for align */ 2318355f576SJeff Roberson #define UMA_ALIGN_PTR (sizeof(void *) - 1) /* Alignment fit for ptr */ 2328355f576SJeff Roberson #define UMA_ALIGN_LONG (sizeof(long) - 1) /* "" long */ 2338355f576SJeff Roberson #define UMA_ALIGN_INT (sizeof(int) - 1) /* "" int */ 2348355f576SJeff Roberson #define UMA_ALIGN_SHORT (sizeof(short) - 1) /* "" short */ 2358355f576SJeff Roberson #define UMA_ALIGN_CHAR (sizeof(char) - 1) /* "" char */ 2368355f576SJeff Roberson #define UMA_ALIGN_CACHE (16 - 1) /* Cache line size align */ 2378355f576SJeff Roberson 2388355f576SJeff Roberson /* 2399c2cd7e5SJeff Roberson * Destroys an empty uma zone. If the zone is not empty uma complains loudly. 2408355f576SJeff Roberson * 2418355f576SJeff Roberson * Arguments: 2428355f576SJeff Roberson * zone The zone we want to destroy. 2438355f576SJeff Roberson * 2448355f576SJeff Roberson */ 2459c2cd7e5SJeff Roberson void uma_zdestroy(uma_zone_t zone); 2468355f576SJeff Roberson 2478355f576SJeff Roberson /* 2488355f576SJeff Roberson * Allocates an item out of a zone 2498355f576SJeff Roberson * 2508355f576SJeff Roberson * Arguments: 2518355f576SJeff Roberson * zone The zone we are allocating from 2528355f576SJeff Roberson * arg This data is passed to the ctor function 2532cc35ff9SJeff Roberson * flags See sys/malloc.h for available flags. 2548355f576SJeff Roberson * 2558355f576SJeff Roberson * Returns: 2568355f576SJeff Roberson * A non null pointer to an initialized element from the zone is 257a163d034SWarner Losh * garanteed if the wait flag is M_WAITOK, otherwise a null pointer may be 2588355f576SJeff Roberson * returned if the zone is empty or the ctor failed. 2598355f576SJeff Roberson */ 2608355f576SJeff Roberson 2612cc35ff9SJeff Roberson void *uma_zalloc_arg(uma_zone_t zone, void *arg, int flags); 2628355f576SJeff Roberson 2638355f576SJeff Roberson /* 2648355f576SJeff Roberson * Allocates an item out of a zone without supplying an argument 2658355f576SJeff Roberson * 2668355f576SJeff Roberson * This is just a wrapper for uma_zalloc_arg for convenience. 2678355f576SJeff Roberson * 2688355f576SJeff Roberson */ 2692cc35ff9SJeff Roberson static __inline void *uma_zalloc(uma_zone_t zone, int flags); 2708355f576SJeff Roberson 2718355f576SJeff Roberson static __inline void * 2722cc35ff9SJeff Roberson uma_zalloc(uma_zone_t zone, int flags) 2738355f576SJeff Roberson { 2742cc35ff9SJeff Roberson return uma_zalloc_arg(zone, NULL, flags); 2758355f576SJeff Roberson } 2768355f576SJeff Roberson 2778355f576SJeff Roberson /* 2788355f576SJeff Roberson * Frees an item back into the specified zone. 2798355f576SJeff Roberson * 2808355f576SJeff Roberson * Arguments: 2818355f576SJeff Roberson * zone The zone the item was originally allocated out of. 2828355f576SJeff Roberson * item The memory to be freed. 2838355f576SJeff Roberson * arg Argument passed to the destructor 2848355f576SJeff Roberson * 2858355f576SJeff Roberson * Returns: 2868355f576SJeff Roberson * Nothing. 2878355f576SJeff Roberson */ 2888355f576SJeff Roberson 2898355f576SJeff Roberson void uma_zfree_arg(uma_zone_t zone, void *item, void *arg); 2908355f576SJeff Roberson 2918355f576SJeff Roberson /* 2928355f576SJeff Roberson * Frees an item back to a zone without supplying an argument 2938355f576SJeff Roberson * 2948355f576SJeff Roberson * This is just a wrapper for uma_zfree_arg for convenience. 2958355f576SJeff Roberson * 2968355f576SJeff Roberson */ 2978355f576SJeff Roberson static __inline void uma_zfree(uma_zone_t zone, void *item); 2988355f576SJeff Roberson 2998355f576SJeff Roberson static __inline void 3008355f576SJeff Roberson uma_zfree(uma_zone_t zone, void *item) 3018355f576SJeff Roberson { 302f6e34b82SMark Murray uma_zfree_arg(zone, item, NULL); 3038355f576SJeff Roberson } 3048355f576SJeff Roberson 3058355f576SJeff Roberson /* 3068355f576SJeff Roberson * XXX The rest of the prototypes in this header are h0h0 magic for the VM. 3078355f576SJeff Roberson * If you think you need to use it for a normal zone you're probably incorrect. 3088355f576SJeff Roberson */ 3098355f576SJeff Roberson 3108355f576SJeff Roberson /* 3118355f576SJeff Roberson * Backend page supplier routines 3128355f576SJeff Roberson * 3138355f576SJeff Roberson * Arguments: 3148355f576SJeff Roberson * zone The zone that is requesting pages 3158355f576SJeff Roberson * size The number of bytes being requested 3168355f576SJeff Roberson * pflag Flags for these memory pages, see below. 3178355f576SJeff Roberson * wait Indicates our willingness to block. 3188355f576SJeff Roberson * 3198355f576SJeff Roberson * Returns: 3208355f576SJeff Roberson * A pointer to the alloced memory or NULL on failure. 3218355f576SJeff Roberson */ 3228355f576SJeff Roberson 3238355f576SJeff Roberson typedef void *(*uma_alloc)(uma_zone_t zone, int size, u_int8_t *pflag, int wait); 3248355f576SJeff Roberson 3258355f576SJeff Roberson /* 3268355f576SJeff Roberson * Backend page free routines 3278355f576SJeff Roberson * 3288355f576SJeff Roberson * Arguments: 3298355f576SJeff Roberson * item A pointer to the previously allocated pages 3308355f576SJeff Roberson * size The original size of the allocation 3318355f576SJeff Roberson * pflag The flags for the slab. See UMA_SLAB_* below 3328355f576SJeff Roberson * 3338355f576SJeff Roberson * Returns: 3348355f576SJeff Roberson * None 3358355f576SJeff Roberson */ 3368355f576SJeff Roberson typedef void (*uma_free)(void *item, int size, u_int8_t pflag); 3378355f576SJeff Roberson 3388355f576SJeff Roberson 3398355f576SJeff Roberson 3408355f576SJeff Roberson /* 3418355f576SJeff Roberson * Sets up the uma allocator. (Called by vm_mem_init) 3428355f576SJeff Roberson * 3438355f576SJeff Roberson * Arguments: 3448355f576SJeff Roberson * bootmem A pointer to memory used to bootstrap the system. 3458355f576SJeff Roberson * 3468355f576SJeff Roberson * Returns: 3478355f576SJeff Roberson * Nothing 3488355f576SJeff Roberson * 3498355f576SJeff Roberson * Discussion: 3508355f576SJeff Roberson * This memory is used for zones which allocate things before the 3518355f576SJeff Roberson * backend page supplier can give us pages. It should be 3528355f576SJeff Roberson * UMA_SLAB_SIZE * UMA_BOOT_PAGES bytes. (see uma_int.h) 3538355f576SJeff Roberson * 3548355f576SJeff Roberson */ 3558355f576SJeff Roberson 3568355f576SJeff Roberson void uma_startup(void *bootmem); 3578355f576SJeff Roberson 3588355f576SJeff Roberson /* 3598355f576SJeff Roberson * Finishes starting up the allocator. This should 3608355f576SJeff Roberson * be called when kva is ready for normal allocs. 3618355f576SJeff Roberson * 3628355f576SJeff Roberson * Arguments: 36399571dc3SJeff Roberson * None 3648355f576SJeff Roberson * 3658355f576SJeff Roberson * Returns: 3668355f576SJeff Roberson * Nothing 3678355f576SJeff Roberson * 3688355f576SJeff Roberson * Discussion: 36999571dc3SJeff Roberson * uma_startup2 is called by kmeminit() to enable us of uma for malloc. 3708355f576SJeff Roberson */ 3718355f576SJeff Roberson 37299571dc3SJeff Roberson void uma_startup2(void); 3738355f576SJeff Roberson 3748355f576SJeff Roberson /* 3758355f576SJeff Roberson * Reclaims unused memory for all zones 3768355f576SJeff Roberson * 3778355f576SJeff Roberson * Arguments: 3788355f576SJeff Roberson * None 3798355f576SJeff Roberson * Returns: 3808355f576SJeff Roberson * None 3818355f576SJeff Roberson * 3828355f576SJeff Roberson * This should only be called by the page out daemon. 3838355f576SJeff Roberson */ 3848355f576SJeff Roberson 3858355f576SJeff Roberson void uma_reclaim(void); 3868355f576SJeff Roberson 3878355f576SJeff Roberson /* 3888355f576SJeff Roberson * Switches the backing object of a zone 3898355f576SJeff Roberson * 3908355f576SJeff Roberson * Arguments: 3918355f576SJeff Roberson * zone The zone to update 3928355f576SJeff Roberson * obj The obj to use for future allocations 3938355f576SJeff Roberson * size The size of the object to allocate 3948355f576SJeff Roberson * 3958355f576SJeff Roberson * Returns: 3968355f576SJeff Roberson * 0 if kva space can not be allocated 3978355f576SJeff Roberson * 1 if successful 3988355f576SJeff Roberson * 3998355f576SJeff Roberson * Discussion: 4008355f576SJeff Roberson * A NULL object can be used and uma will allocate one for you. Setting 4018355f576SJeff Roberson * the size will limit the amount of memory allocated to this zone. 4028355f576SJeff Roberson * 4038355f576SJeff Roberson */ 4048355f576SJeff Roberson struct vm_object; 4058355f576SJeff Roberson int uma_zone_set_obj(uma_zone_t zone, struct vm_object *obj, int size); 4068355f576SJeff Roberson 407736ee590SJeff Roberson /* 408736ee590SJeff Roberson * Sets a high limit on the number of items allowed in a zone 409736ee590SJeff Roberson * 410736ee590SJeff Roberson * Arguments: 411736ee590SJeff Roberson * zone The zone to limit 412736ee590SJeff Roberson * 413736ee590SJeff Roberson * Returns: 414736ee590SJeff Roberson * Nothing 415736ee590SJeff Roberson */ 416736ee590SJeff Roberson void uma_zone_set_max(uma_zone_t zone, int nitems); 4178355f576SJeff Roberson 4188355f576SJeff Roberson /* 419099a0e58SBosko Milekic * The following two routines (uma_zone_set_init/fini) 420099a0e58SBosko Milekic * are used to set the backend init/fini pair which acts on an 421099a0e58SBosko Milekic * object as it becomes allocated and is placed in a slab within 422099a0e58SBosko Milekic * the specified zone's backing keg. These should probably not 423099a0e58SBosko Milekic * be changed once allocations have already begun and only 424099a0e58SBosko Milekic * immediately upon zone creation. 425099a0e58SBosko Milekic */ 426099a0e58SBosko Milekic void uma_zone_set_init(uma_zone_t zone, uma_init uminit); 427099a0e58SBosko Milekic void uma_zone_set_fini(uma_zone_t zone, uma_fini fini); 428099a0e58SBosko Milekic 429099a0e58SBosko Milekic /* 430099a0e58SBosko Milekic * The following two routines (uma_zone_set_zinit/zfini) are 431099a0e58SBosko Milekic * used to set the zinit/zfini pair which acts on an object as 432099a0e58SBosko Milekic * it passes from the backing Keg's slab cache to the 433099a0e58SBosko Milekic * specified Zone's bucket cache. These should probably not 434099a0e58SBosko Milekic * be changed once allocations have already begun and 435099a0e58SBosko Milekic * only immediately upon zone creation. 436099a0e58SBosko Milekic */ 437099a0e58SBosko Milekic void uma_zone_set_zinit(uma_zone_t zone, uma_init zinit); 438099a0e58SBosko Milekic void uma_zone_set_zfini(uma_zone_t zone, uma_fini zfini); 439099a0e58SBosko Milekic 440099a0e58SBosko Milekic /* 4418355f576SJeff Roberson * Replaces the standard page_alloc or obj_alloc functions for this zone 4428355f576SJeff Roberson * 4438355f576SJeff Roberson * Arguments: 4448355f576SJeff Roberson * zone The zone whos back end allocator is being changed. 4458355f576SJeff Roberson * allocf A pointer to the allocation function 4468355f576SJeff Roberson * 4478355f576SJeff Roberson * Returns: 4488355f576SJeff Roberson * Nothing 4498355f576SJeff Roberson * 4508355f576SJeff Roberson * Discussion: 4518355f576SJeff Roberson * This could be used to implement pageable allocation, or perhaps 4528355f576SJeff Roberson * even DMA allocators if used in conjunction with the OFFPAGE 4538355f576SJeff Roberson * zone flag. 4548355f576SJeff Roberson */ 4558355f576SJeff Roberson 4568355f576SJeff Roberson void uma_zone_set_allocf(uma_zone_t zone, uma_alloc allocf); 4578355f576SJeff Roberson 4588355f576SJeff Roberson /* 4598355f576SJeff Roberson * Used for freeing memory provided by the allocf above 4608355f576SJeff Roberson * 4618355f576SJeff Roberson * Arguments: 4628355f576SJeff Roberson * zone The zone that intends to use this free routine. 4638355f576SJeff Roberson * freef The page freeing routine. 4648355f576SJeff Roberson * 4658355f576SJeff Roberson * Returns: 4668355f576SJeff Roberson * Nothing 4678355f576SJeff Roberson */ 4688355f576SJeff Roberson 4698355f576SJeff Roberson void uma_zone_set_freef(uma_zone_t zone, uma_free freef); 4708355f576SJeff Roberson 4718355f576SJeff Roberson /* 4728355f576SJeff Roberson * These flags are setable in the allocf and visable in the freef. 4738355f576SJeff Roberson */ 4748355f576SJeff Roberson #define UMA_SLAB_BOOT 0x01 /* Slab alloced from boot pages */ 4758355f576SJeff Roberson #define UMA_SLAB_KMEM 0x02 /* Slab alloced from kmem_map */ 4768355f576SJeff Roberson #define UMA_SLAB_PRIV 0x08 /* Slab alloced from priv allocator */ 477c235bfa5SJeff Roberson #define UMA_SLAB_OFFP 0x10 /* Slab is managed separately */ 4788355f576SJeff Roberson #define UMA_SLAB_MALLOC 0x20 /* Slab is a large malloc slab */ 4798355f576SJeff Roberson /* 0x40 and 0x80 are available */ 4808355f576SJeff Roberson 4818355f576SJeff Roberson /* 4828355f576SJeff Roberson * Used to pre-fill a zone with some number of items 4838355f576SJeff Roberson * 4848355f576SJeff Roberson * Arguments: 4858355f576SJeff Roberson * zone The zone to fill 4868355f576SJeff Roberson * itemcnt The number of items to reserve 4878355f576SJeff Roberson * 4888355f576SJeff Roberson * Returns: 4898355f576SJeff Roberson * Nothing 4908355f576SJeff Roberson * 4918355f576SJeff Roberson * NOTE: This is blocking and should only be done at startup 4928355f576SJeff Roberson */ 4938355f576SJeff Roberson void uma_prealloc(uma_zone_t zone, int itemcnt); 4948355f576SJeff Roberson 495099a0e58SBosko Milekic /* 496099a0e58SBosko Milekic * Used to lookup the reference counter allocated for an item 497099a0e58SBosko Milekic * from a UMA_ZONE_REFCNT zone. For UMA_ZONE_REFCNT zones, 498099a0e58SBosko Milekic * reference counters are allocated for items and stored in 499099a0e58SBosko Milekic * the underlying slab header. 500099a0e58SBosko Milekic * 501099a0e58SBosko Milekic * Arguments: 502099a0e58SBosko Milekic * zone The UMA_ZONE_REFCNT zone to which the item belongs. 503099a0e58SBosko Milekic * item The address of the item for which we want a refcnt. 504099a0e58SBosko Milekic * 505099a0e58SBosko Milekic * Returns: 506099a0e58SBosko Milekic * A pointer to a u_int32_t reference counter. 507099a0e58SBosko Milekic */ 508099a0e58SBosko Milekic u_int32_t *uma_find_refcnt(uma_zone_t zone, void *item); 5098355f576SJeff Roberson 5108355f576SJeff Roberson #endif 511