Christoph Lameter | 2e892f4 | 2006-12-13 00:34:23 -0800 | [diff] [blame] | 1 | #ifndef _LINUX_SLAB_DEF_H |
| 2 | #define _LINUX_SLAB_DEF_H |
| 3 | |
Hannes Frederic Sowa | 809fa97 | 2014-01-22 02:29:41 +0100 | [diff] [blame] | 4 | #include <linux/reciprocal_div.h> |
| 5 | |
Christoph Lameter | 2e892f4 | 2006-12-13 00:34:23 -0800 | [diff] [blame] | 6 | /* |
| 7 | * Definitions unique to the original Linux SLAB allocator. |
Pekka Enberg | 8eae985 | 2008-05-09 20:32:44 +0200 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | struct kmem_cache { |
Fam Zheng | 24755e2 | 2014-01-21 09:12:42 +0800 | [diff] [blame] | 11 | /* 1) Cache tunables. Protected by slab_mutex */ |
Pekka Enberg | 8eae985 | 2008-05-09 20:32:44 +0200 | [diff] [blame] | 12 | unsigned int batchcount; |
| 13 | unsigned int limit; |
| 14 | unsigned int shared; |
| 15 | |
Christoph Lameter | 3b0efdf | 2012-06-13 10:24:57 -0500 | [diff] [blame] | 16 | unsigned int size; |
Hannes Frederic Sowa | 809fa97 | 2014-01-22 02:29:41 +0100 | [diff] [blame] | 17 | struct reciprocal_value reciprocal_buffer_size; |
Eric Dumazet | b56efcf | 2011-07-20 19:04:23 +0200 | [diff] [blame] | 18 | /* 2) touched by every alloc & free from the backend */ |
Pekka Enberg | 8eae985 | 2008-05-09 20:32:44 +0200 | [diff] [blame] | 19 | |
| 20 | unsigned int flags; /* constant flags */ |
| 21 | unsigned int num; /* # of objs per slab */ |
| 22 | |
Eric Dumazet | b56efcf | 2011-07-20 19:04:23 +0200 | [diff] [blame] | 23 | /* 3) cache_grow/shrink */ |
Pekka Enberg | 8eae985 | 2008-05-09 20:32:44 +0200 | [diff] [blame] | 24 | /* order of pgs per slab (2^n) */ |
| 25 | unsigned int gfporder; |
| 26 | |
| 27 | /* force GFP flags, e.g. GFP_DMA */ |
Glauber Costa | a618e89 | 2012-06-14 16:17:21 +0400 | [diff] [blame] | 28 | gfp_t allocflags; |
Pekka Enberg | 8eae985 | 2008-05-09 20:32:44 +0200 | [diff] [blame] | 29 | |
| 30 | size_t colour; /* cache colouring range */ |
| 31 | unsigned int colour_off; /* colour offset */ |
Joonsoo Kim | 8456a64 | 2013-10-24 10:07:49 +0900 | [diff] [blame] | 32 | struct kmem_cache *freelist_cache; |
| 33 | unsigned int freelist_size; |
Pekka Enberg | 8eae985 | 2008-05-09 20:32:44 +0200 | [diff] [blame] | 34 | |
| 35 | /* constructor func */ |
| 36 | void (*ctor)(void *obj); |
| 37 | |
Eric Dumazet | b56efcf | 2011-07-20 19:04:23 +0200 | [diff] [blame] | 38 | /* 4) cache creation/removal */ |
Pekka Enberg | 8eae985 | 2008-05-09 20:32:44 +0200 | [diff] [blame] | 39 | const char *name; |
Christoph Lameter | 3b0efdf | 2012-06-13 10:24:57 -0500 | [diff] [blame] | 40 | struct list_head list; |
| 41 | int refcount; |
| 42 | int object_size; |
| 43 | int align; |
Pekka Enberg | 8eae985 | 2008-05-09 20:32:44 +0200 | [diff] [blame] | 44 | |
Eric Dumazet | b56efcf | 2011-07-20 19:04:23 +0200 | [diff] [blame] | 45 | /* 5) statistics */ |
Pekka Enberg | 8eae985 | 2008-05-09 20:32:44 +0200 | [diff] [blame] | 46 | #ifdef CONFIG_DEBUG_SLAB |
| 47 | unsigned long num_active; |
| 48 | unsigned long num_allocations; |
| 49 | unsigned long high_mark; |
| 50 | unsigned long grown; |
| 51 | unsigned long reaped; |
| 52 | unsigned long errors; |
| 53 | unsigned long max_freeable; |
| 54 | unsigned long node_allocs; |
| 55 | unsigned long node_frees; |
| 56 | unsigned long node_overflow; |
| 57 | atomic_t allochit; |
| 58 | atomic_t allocmiss; |
| 59 | atomic_t freehit; |
| 60 | atomic_t freemiss; |
| 61 | |
| 62 | /* |
| 63 | * If debugging is enabled, then the allocator can add additional |
Christoph Lameter | 3b0efdf | 2012-06-13 10:24:57 -0500 | [diff] [blame] | 64 | * fields and/or padding to every object. size contains the total |
Pekka Enberg | 8eae985 | 2008-05-09 20:32:44 +0200 | [diff] [blame] | 65 | * object size including these internal fields, the following two |
| 66 | * variables contain the offset to the user object and its size. |
| 67 | */ |
| 68 | int obj_offset; |
Pekka Enberg | 8eae985 | 2008-05-09 20:32:44 +0200 | [diff] [blame] | 69 | #endif /* CONFIG_DEBUG_SLAB */ |
Glauber Costa | ba6c496 | 2012-12-18 14:22:27 -0800 | [diff] [blame] | 70 | #ifdef CONFIG_MEMCG_KMEM |
| 71 | struct memcg_cache_params *memcg_params; |
| 72 | #endif |
Pekka Enberg | 8eae985 | 2008-05-09 20:32:44 +0200 | [diff] [blame] | 73 | |
Eric Dumazet | b56efcf | 2011-07-20 19:04:23 +0200 | [diff] [blame] | 74 | /* 6) per-cpu/per-node data, touched during every alloc/free */ |
Pekka Enberg | 8eae985 | 2008-05-09 20:32:44 +0200 | [diff] [blame] | 75 | /* |
Eric Dumazet | b56efcf | 2011-07-20 19:04:23 +0200 | [diff] [blame] | 76 | * We put array[] at the end of kmem_cache, because we want to size |
| 77 | * this array to nr_cpu_ids slots instead of NR_CPUS |
Pekka Enberg | 8eae985 | 2008-05-09 20:32:44 +0200 | [diff] [blame] | 78 | * (see kmem_cache_init()) |
Eric Dumazet | b56efcf | 2011-07-20 19:04:23 +0200 | [diff] [blame] | 79 | * We still use [NR_CPUS] and not [1] or [0] because cache_cache |
| 80 | * is statically defined, so we reserve the max number of cpus. |
Christoph Lameter | 3c58346 | 2012-11-28 16:23:01 +0000 | [diff] [blame] | 81 | * |
| 82 | * We also need to guarantee that the list is able to accomodate a |
| 83 | * pointer for each node since "nodelists" uses the remainder of |
| 84 | * available pointers. |
Pekka Enberg | 8eae985 | 2008-05-09 20:32:44 +0200 | [diff] [blame] | 85 | */ |
Christoph Lameter | 6a67368 | 2013-01-10 19:14:19 +0000 | [diff] [blame] | 86 | struct kmem_cache_node **node; |
Christoph Lameter | 3c58346 | 2012-11-28 16:23:01 +0000 | [diff] [blame] | 87 | struct array_cache *array[NR_CPUS + MAX_NUMNODES]; |
Pekka Enberg | 8eae985 | 2008-05-09 20:32:44 +0200 | [diff] [blame] | 88 | /* |
Eric Dumazet | b56efcf | 2011-07-20 19:04:23 +0200 | [diff] [blame] | 89 | * Do not add fields after array[] |
Pekka Enberg | 8eae985 | 2008-05-09 20:32:44 +0200 | [diff] [blame] | 90 | */ |
| 91 | }; |
| 92 | |
Christoph Lameter | 2e892f4 | 2006-12-13 00:34:23 -0800 | [diff] [blame] | 93 | #endif /* _LINUX_SLAB_DEF_H */ |