Deleted Added
full compact
uma_int.h (249312) uma_int.h (249313)
1/*-
2 * Copyright (c) 2002-2005, 2009 Jeffrey Roberson <jeff@FreeBSD.org>
3 * Copyright (c) 2004, 2005 Bosko Milekic <bmilekic@FreeBSD.org>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 10 unchanged lines hidden (view full) ---

19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 *
1/*-
2 * Copyright (c) 2002-2005, 2009 Jeffrey Roberson <jeff@FreeBSD.org>
3 * Copyright (c) 2004, 2005 Bosko Milekic <bmilekic@FreeBSD.org>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 10 unchanged lines hidden (view full) ---

19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 *
27 * $FreeBSD: head/sys/vm/uma_int.h 249312 2013-04-09 17:25:15Z glebius $
27 * $FreeBSD: head/sys/vm/uma_int.h 249313 2013-04-09 17:43:48Z glebius $
28 *
29 */
30
31/*
32 * This file includes definitions, structures, prototypes, and inlines that
33 * should not be used outside of the actual implementation of UMA.
34 */
35

--- 143 unchanged lines hidden (view full) ---

179 void *ub_bucket[]; /* actual allocation storage */
180};
181
182typedef struct uma_bucket * uma_bucket_t;
183
184struct uma_cache {
185 uma_bucket_t uc_freebucket; /* Bucket we're freeing to */
186 uma_bucket_t uc_allocbucket; /* Bucket to allocate from */
28 *
29 */
30
31/*
32 * This file includes definitions, structures, prototypes, and inlines that
33 * should not be used outside of the actual implementation of UMA.
34 */
35

--- 143 unchanged lines hidden (view full) ---

179 void *ub_bucket[]; /* actual allocation storage */
180};
181
182typedef struct uma_bucket * uma_bucket_t;
183
184struct uma_cache {
185 uma_bucket_t uc_freebucket; /* Bucket we're freeing to */
186 uma_bucket_t uc_allocbucket; /* Bucket to allocate from */
187 u_int64_t uc_allocs; /* Count of allocations */
188 u_int64_t uc_frees; /* Count of frees */
187 uint64_t uc_allocs; /* Count of allocations */
188 uint64_t uc_frees; /* Count of frees */
189} UMA_ALIGN;
190
191typedef struct uma_cache * uma_cache_t;
192
193/*
194 * Keg management structure
195 *
196 * TODO: Optimize for cache line size
197 *
198 */
199struct uma_keg {
200 struct mtx uk_lock; /* Lock for the keg */
201 struct uma_hash uk_hash;
202
203 LIST_HEAD(,uma_zone) uk_zones; /* Keg's zones */
204 LIST_HEAD(,uma_slab) uk_part_slab; /* partially allocated slabs */
205 LIST_HEAD(,uma_slab) uk_free_slab; /* empty slab list */
206 LIST_HEAD(,uma_slab) uk_full_slab; /* full slabs */
207
189} UMA_ALIGN;
190
191typedef struct uma_cache * uma_cache_t;
192
193/*
194 * Keg management structure
195 *
196 * TODO: Optimize for cache line size
197 *
198 */
199struct uma_keg {
200 struct mtx uk_lock; /* Lock for the keg */
201 struct uma_hash uk_hash;
202
203 LIST_HEAD(,uma_zone) uk_zones; /* Keg's zones */
204 LIST_HEAD(,uma_slab) uk_part_slab; /* partially allocated slabs */
205 LIST_HEAD(,uma_slab) uk_free_slab; /* empty slab list */
206 LIST_HEAD(,uma_slab) uk_full_slab; /* full slabs */
207
208 u_int32_t uk_recurse; /* Allocation recursion count */
209 u_int32_t uk_align; /* Alignment mask */
210 u_int32_t uk_pages; /* Total page count */
211 u_int32_t uk_free; /* Count of items free in slabs */
212 u_int32_t uk_size; /* Requested size of each item */
213 u_int32_t uk_rsize; /* Real size of each item */
214 u_int32_t uk_maxpages; /* Maximum number of pages to alloc */
208 uint32_t uk_recurse; /* Allocation recursion count */
209 uint32_t uk_align; /* Alignment mask */
210 uint32_t uk_pages; /* Total page count */
211 uint32_t uk_free; /* Count of items free in slabs */
212 uint32_t uk_size; /* Requested size of each item */
213 uint32_t uk_rsize; /* Real size of each item */
214 uint32_t uk_maxpages; /* Maximum number of pages to alloc */
215
216 uma_init uk_init; /* Keg's init routine */
217 uma_fini uk_fini; /* Keg's fini routine */
218 uma_alloc uk_allocf; /* Allocation function */
219 uma_free uk_freef; /* Free routine */
220
221 u_long uk_offset; /* Next free offset from base KVA */
222 vm_offset_t uk_kva; /* Zone base KVA */
223 uma_zone_t uk_slabzone; /* Slab zone backing us, if OFFPAGE */
224
215
216 uma_init uk_init; /* Keg's init routine */
217 uma_fini uk_fini; /* Keg's fini routine */
218 uma_alloc uk_allocf; /* Allocation function */
219 uma_free uk_freef; /* Free routine */
220
221 u_long uk_offset; /* Next free offset from base KVA */
222 vm_offset_t uk_kva; /* Zone base KVA */
223 uma_zone_t uk_slabzone; /* Slab zone backing us, if OFFPAGE */
224
225 u_int16_t uk_slabsize; /* Slab size for this keg */
226 u_int16_t uk_pgoff; /* Offset to uma_slab struct */
227 u_int16_t uk_ppera; /* pages per allocation from backend */
228 u_int16_t uk_ipers; /* Items per slab */
229 u_int32_t uk_flags; /* Internal flags */
225 uint16_t uk_slabsize; /* Slab size for this keg */
226 uint16_t uk_pgoff; /* Offset to uma_slab struct */
227 uint16_t uk_ppera; /* pages per allocation from backend */
228 uint16_t uk_ipers; /* Items per slab */
229 uint32_t uk_flags; /* Internal flags */
230
231 /* Least used fields go to the last cache line. */
232 const char *uk_name; /* Name of creating zone. */
233 LIST_ENTRY(uma_keg) uk_link; /* List of all kegs */
234};
235typedef struct uma_keg * uma_keg_t;
236
237/* Page management structure */
238
239/* Sorry for the union, but space efficiency is important */
240struct uma_slab_head {
241 uma_keg_t us_keg; /* Keg we live in */
242 union {
243 LIST_ENTRY(uma_slab) _us_link; /* slabs in zone */
244 unsigned long _us_size; /* Size of allocation */
245 } us_type;
246 SLIST_ENTRY(uma_slab) us_hlink; /* Link for hash table */
230
231 /* Least used fields go to the last cache line. */
232 const char *uk_name; /* Name of creating zone. */
233 LIST_ENTRY(uma_keg) uk_link; /* List of all kegs */
234};
235typedef struct uma_keg * uma_keg_t;
236
237/* Page management structure */
238
239/* Sorry for the union, but space efficiency is important */
240struct uma_slab_head {
241 uma_keg_t us_keg; /* Keg we live in */
242 union {
243 LIST_ENTRY(uma_slab) _us_link; /* slabs in zone */
244 unsigned long _us_size; /* Size of allocation */
245 } us_type;
246 SLIST_ENTRY(uma_slab) us_hlink; /* Link for hash table */
247 u_int8_t *us_data; /* First item */
248 u_int16_t us_freecount; /* How many are free? */
249 u_int8_t us_flags; /* Page flags see uma.h */
250 u_int8_t us_firstfree; /* First free item index */
247 uint8_t *us_data; /* First item */
248 uint16_t us_freecount; /* How many are free? */
249 uint8_t us_flags; /* Page flags see uma.h */
250 uint8_t us_firstfree; /* First free item index */
251};
252
253/* The standard slab structure */
254struct uma_slab {
255 struct uma_slab_head us_head; /* slab header data */
256 struct {
251};
252
253/* The standard slab structure */
254struct uma_slab {
255 struct uma_slab_head us_head; /* slab header data */
256 struct {
257 u_int8_t us_item;
257 uint8_t us_item;
258 } us_freelist[1]; /* actual number bigger */
259};
260
261/*
262 * The slab structure for UMA_ZONE_REFCNT zones for whose items we
263 * maintain reference counters in the slab for.
264 */
265struct uma_slab_refcnt {
266 struct uma_slab_head us_head; /* slab header data */
267 struct {
258 } us_freelist[1]; /* actual number bigger */
259};
260
261/*
262 * The slab structure for UMA_ZONE_REFCNT zones for whose items we
263 * maintain reference counters in the slab for.
264 */
265struct uma_slab_refcnt {
266 struct uma_slab_head us_head; /* slab header data */
267 struct {
268 u_int8_t us_item;
269 u_int32_t us_refcnt;
268 uint8_t us_item;
269 uint32_t us_refcnt;
270 } us_freelist[1]; /* actual number bigger */
271};
272
273#define us_keg us_head.us_keg
274#define us_link us_head.us_type._us_link
275#define us_size us_head.us_type._us_size
276#define us_hlink us_head.us_hlink
277#define us_data us_head.us_data

--- 40 unchanged lines hidden (view full) ---

318 struct uma_klink uz_klink; /* klink for first keg. */
319
320 uma_slaballoc uz_slab; /* Allocate a slab from the backend. */
321 uma_ctor uz_ctor; /* Constructor for each allocation */
322 uma_dtor uz_dtor; /* Destructor */
323 uma_init uz_init; /* Initializer for each item */
324 uma_fini uz_fini; /* Discards memory */
325
270 } us_freelist[1]; /* actual number bigger */
271};
272
273#define us_keg us_head.us_keg
274#define us_link us_head.us_type._us_link
275#define us_size us_head.us_type._us_size
276#define us_hlink us_head.us_hlink
277#define us_data us_head.us_data

--- 40 unchanged lines hidden (view full) ---

318 struct uma_klink uz_klink; /* klink for first keg. */
319
320 uma_slaballoc uz_slab; /* Allocate a slab from the backend. */
321 uma_ctor uz_ctor; /* Constructor for each allocation */
322 uma_dtor uz_dtor; /* Destructor */
323 uma_init uz_init; /* Initializer for each item */
324 uma_fini uz_fini; /* Discards memory */
325
326 u_int32_t uz_flags; /* Flags inherited from kegs */
327 u_int32_t uz_size; /* Size inherited from kegs */
326 uint32_t uz_flags; /* Flags inherited from kegs */
327 uint32_t uz_size; /* Size inherited from kegs */
328
328
329 u_int64_t uz_allocs UMA_ALIGN; /* Total number of allocations */
330 u_int64_t uz_frees; /* Total number of frees */
331 u_int64_t uz_fails; /* Total number of alloc failures */
332 u_int64_t uz_sleeps; /* Total number of alloc sleeps */
329 uint64_t uz_allocs UMA_ALIGN; /* Total number of allocations */
330 uint64_t uz_frees; /* Total number of frees */
331 uint64_t uz_fails; /* Total number of alloc failures */
332 uint64_t uz_sleeps; /* Total number of alloc sleeps */
333 uint16_t uz_fills; /* Outstanding bucket fills */
334 uint16_t uz_count; /* Highest amount of items in bucket */
335
336 /* The next three fields are used to print a rate-limited warnings. */
337 const char *uz_warning; /* Warning to print on failure */
338 struct timeval uz_ratecheck; /* Warnings rate-limiting */
339
340 /*

--- 16 unchanged lines hidden (view full) ---

357
358#define UMA_ZFLAG_INHERIT (UMA_ZFLAG_INTERNAL | UMA_ZFLAG_CACHEONLY | \
359 UMA_ZFLAG_BUCKET)
360
361#undef UMA_ALIGN
362
363#ifdef _KERNEL
364/* Internal prototypes */
333 uint16_t uz_fills; /* Outstanding bucket fills */
334 uint16_t uz_count; /* Highest amount of items in bucket */
335
336 /* The next three fields are used to print a rate-limited warnings. */
337 const char *uz_warning; /* Warning to print on failure */
338 struct timeval uz_ratecheck; /* Warnings rate-limiting */
339
340 /*

--- 16 unchanged lines hidden (view full) ---

357
358#define UMA_ZFLAG_INHERIT (UMA_ZFLAG_INTERNAL | UMA_ZFLAG_CACHEONLY | \
359 UMA_ZFLAG_BUCKET)
360
361#undef UMA_ALIGN
362
363#ifdef _KERNEL
364/* Internal prototypes */
365static __inline uma_slab_t hash_sfind(struct uma_hash *hash, u_int8_t *data);
365static __inline uma_slab_t hash_sfind(struct uma_hash *hash, uint8_t *data);
366void *uma_large_malloc(int size, int wait);
367void uma_large_free(uma_slab_t slab);
368
369/* Lock Macros */
370
371#define KEG_LOCK_INIT(k, lc) \
372 do { \
373 if ((lc)) \

--- 17 unchanged lines hidden (view full) ---

391 * Arguments:
392 * hash The hash table to search.
393 * data The base page of the item.
394 *
395 * Returns:
396 * A pointer to a slab if successful, else NULL.
397 */
398static __inline uma_slab_t
366void *uma_large_malloc(int size, int wait);
367void uma_large_free(uma_slab_t slab);
368
369/* Lock Macros */
370
371#define KEG_LOCK_INIT(k, lc) \
372 do { \
373 if ((lc)) \

--- 17 unchanged lines hidden (view full) ---

391 * Arguments:
392 * hash The hash table to search.
393 * data The base page of the item.
394 *
395 * Returns:
396 * A pointer to a slab if successful, else NULL.
397 */
398static __inline uma_slab_t
399hash_sfind(struct uma_hash *hash, u_int8_t *data)
399hash_sfind(struct uma_hash *hash, uint8_t *data)
400{
401 uma_slab_t slab;
402 int hval;
403
404 hval = UMA_HASH(hash, data);
405
406 SLIST_FOREACH(slab, &hash->uh_slab_hash[hval], us_hlink) {
400{
401 uma_slab_t slab;
402 int hval;
403
404 hval = UMA_HASH(hash, data);
405
406 SLIST_FOREACH(slab, &hash->uh_slab_hash[hval], us_hlink) {
407 if ((u_int8_t *)slab->us_data == data)
407 if ((uint8_t *)slab->us_data == data)
408 return (slab);
409 }
410 return (NULL);
411}
412
413static __inline uma_slab_t
414vtoslab(vm_offset_t va)
415{

--- 29 unchanged lines hidden (view full) ---

445 p->flags &= ~PG_SLAB;
446}
447
448/*
449 * The following two functions may be defined by architecture specific code
450 * if they can provide more effecient allocation functions. This is useful
451 * for using direct mapped addresses.
452 */
408 return (slab);
409 }
410 return (NULL);
411}
412
413static __inline uma_slab_t
414vtoslab(vm_offset_t va)
415{

--- 29 unchanged lines hidden (view full) ---

445 p->flags &= ~PG_SLAB;
446}
447
448/*
449 * The following two functions may be defined by architecture specific code
450 * if they can provide more effecient allocation functions. This is useful
451 * for using direct mapped addresses.
452 */
453void *uma_small_alloc(uma_zone_t zone, int bytes, u_int8_t *pflag, int wait);
454void uma_small_free(void *mem, int size, u_int8_t flags);
453void *uma_small_alloc(uma_zone_t zone, int bytes, uint8_t *pflag, int wait);
454void uma_small_free(void *mem, int size, uint8_t flags);
455#endif /* _KERNEL */
456
457#endif /* VM_UMA_INT_H */
455#endif /* _KERNEL */
456
457#endif /* VM_UMA_INT_H */