Christoph Lameter | 81819f0 | 2007-05-06 14:49:36 -0700 | [diff] [blame] | 1 | #ifndef _LINUX_SLUB_DEF_H |
| 2 | #define _LINUX_SLUB_DEF_H |
| 3 | |
| 4 | /* |
| 5 | * SLUB : A Slab allocator without object queues. |
| 6 | * |
Christoph Lameter | cde5353 | 2008-07-04 09:59:22 -0700 | [diff] [blame] | 7 | * (C) 2007 SGI, Christoph Lameter |
Christoph Lameter | 81819f0 | 2007-05-06 14:49:36 -0700 | [diff] [blame] | 8 | */ |
Christoph Lameter | 81819f0 | 2007-05-06 14:49:36 -0700 | [diff] [blame] | 9 | #include <linux/kobject.h> |
| 10 | |
Christoph Lameter | 8ff12cf | 2008-02-07 17:47:41 -0800 | [diff] [blame] | 11 | enum stat_item { |
| 12 | ALLOC_FASTPATH, /* Allocation from cpu slab */ |
| 13 | ALLOC_SLOWPATH, /* Allocation by getting a new cpu slab */ |
Zhi Yong Wu | a941f83 | 2013-11-08 20:47:36 +0800 | [diff] [blame] | 14 | FREE_FASTPATH, /* Free to cpu slab */ |
Christoph Lameter | 8ff12cf | 2008-02-07 17:47:41 -0800 | [diff] [blame] | 15 | FREE_SLOWPATH, /* Freeing not to cpu slab */ |
| 16 | FREE_FROZEN, /* Freeing to frozen slab */ |
| 17 | FREE_ADD_PARTIAL, /* Freeing moves slab to partial list */ |
| 18 | FREE_REMOVE_PARTIAL, /* Freeing removes last object */ |
Alex Shi | 8028dce | 2012-02-03 23:34:56 +0800 | [diff] [blame] | 19 | ALLOC_FROM_PARTIAL, /* Cpu slab acquired from node partial list */ |
Christoph Lameter | 8ff12cf | 2008-02-07 17:47:41 -0800 | [diff] [blame] | 20 | ALLOC_SLAB, /* Cpu slab acquired from page allocator */ |
| 21 | ALLOC_REFILL, /* Refill cpu slab from slab freelist */ |
Christoph Lameter | e36a265 | 2011-06-01 12:25:57 -0500 | [diff] [blame] | 22 | ALLOC_NODE_MISMATCH, /* Switching cpu slab */ |
Christoph Lameter | 8ff12cf | 2008-02-07 17:47:41 -0800 | [diff] [blame] | 23 | FREE_SLAB, /* Slab freed to the page allocator */ |
| 24 | CPUSLAB_FLUSH, /* Abandoning of the cpu slab */ |
| 25 | DEACTIVATE_FULL, /* Cpu slab was full when deactivated */ |
| 26 | DEACTIVATE_EMPTY, /* Cpu slab was empty when deactivated */ |
| 27 | DEACTIVATE_TO_HEAD, /* Cpu slab was moved to the head of partials */ |
| 28 | DEACTIVATE_TO_TAIL, /* Cpu slab was moved to the tail of partials */ |
| 29 | DEACTIVATE_REMOTE_FREES,/* Slab contained remotely freed objects */ |
Christoph Lameter | 03e404a | 2011-06-01 12:25:58 -0500 | [diff] [blame] | 30 | DEACTIVATE_BYPASS, /* Implicit deactivation */ |
Christoph Lameter | 65c3376 | 2008-04-14 19:11:40 +0300 | [diff] [blame] | 31 | ORDER_FALLBACK, /* Number of times fallback was necessary */ |
Christoph Lameter | 4fdccdf | 2011-03-22 13:35:00 -0500 | [diff] [blame] | 32 | CMPXCHG_DOUBLE_CPU_FAIL,/* Failure of this_cpu_cmpxchg_double */ |
Christoph Lameter | b789ef5 | 2011-06-01 12:25:49 -0500 | [diff] [blame] | 33 | CMPXCHG_DOUBLE_FAIL, /* Number of times that cmpxchg double did not match */ |
Christoph Lameter | 49e2258 | 2011-08-09 16:12:27 -0500 | [diff] [blame] | 34 | CPU_PARTIAL_ALLOC, /* Used cpu partial on alloc */ |
Alex Shi | 8028dce | 2012-02-03 23:34:56 +0800 | [diff] [blame] | 35 | CPU_PARTIAL_FREE, /* Refill cpu partial on free */ |
| 36 | CPU_PARTIAL_NODE, /* Refill cpu partial from node partial */ |
| 37 | CPU_PARTIAL_DRAIN, /* Drain cpu partial to node partial */ |
Christoph Lameter | 8ff12cf | 2008-02-07 17:47:41 -0800 | [diff] [blame] | 38 | NR_SLUB_STAT_ITEMS }; |
| 39 | |
Christoph Lameter | dfb4f09 | 2007-10-16 01:26:05 -0700 | [diff] [blame] | 40 | struct kmem_cache_cpu { |
Christoph Lameter | 8a5ec0b | 2011-02-25 11:38:54 -0600 | [diff] [blame] | 41 | void **freelist; /* Pointer to next available object */ |
Christoph Lameter | 8a5ec0b | 2011-02-25 11:38:54 -0600 | [diff] [blame] | 42 | unsigned long tid; /* Globally unique transaction id */ |
Christoph Lameter | da89b79 | 2008-01-07 23:20:31 -0800 | [diff] [blame] | 43 | struct page *page; /* The slab from which we are allocating */ |
Christoph Lameter | 49e2258 | 2011-08-09 16:12:27 -0500 | [diff] [blame] | 44 | struct page *partial; /* Partially allocated frozen slabs */ |
Christoph Lameter | 8ff12cf | 2008-02-07 17:47:41 -0800 | [diff] [blame] | 45 | #ifdef CONFIG_SLUB_STATS |
| 46 | unsigned stat[NR_SLUB_STAT_ITEMS]; |
| 47 | #endif |
Christoph Lameter | 4c93c355 | 2007-10-16 01:26:08 -0700 | [diff] [blame] | 48 | }; |
Christoph Lameter | dfb4f09 | 2007-10-16 01:26:05 -0700 | [diff] [blame] | 49 | |
Christoph Lameter | 81819f0 | 2007-05-06 14:49:36 -0700 | [diff] [blame] | 50 | /* |
Christoph Lameter | 834f3d1 | 2008-04-14 19:11:31 +0300 | [diff] [blame] | 51 | * Word size structure that can be atomically updated or read and that |
| 52 | * contains both the order and the number of objects that a slab of the |
| 53 | * given order would contain. |
| 54 | */ |
| 55 | struct kmem_cache_order_objects { |
| 56 | unsigned long x; |
| 57 | }; |
| 58 | |
| 59 | /* |
Christoph Lameter | 81819f0 | 2007-05-06 14:49:36 -0700 | [diff] [blame] | 60 | * Slab cache management. |
| 61 | */ |
| 62 | struct kmem_cache { |
Namhyung Kim | 1b5ad24 | 2010-08-07 14:29:22 +0200 | [diff] [blame] | 63 | struct kmem_cache_cpu __percpu *cpu_slab; |
Christoph Lameter | 81819f0 | 2007-05-06 14:49:36 -0700 | [diff] [blame] | 64 | /* Used for retriving partial slabs etc */ |
| 65 | unsigned long flags; |
Christoph Lameter | 1a757fe | 2011-02-25 11:38:51 -0600 | [diff] [blame] | 66 | unsigned long min_partial; |
Christoph Lameter | 81819f0 | 2007-05-06 14:49:36 -0700 | [diff] [blame] | 67 | int size; /* The size of an object including meta data */ |
Christoph Lameter | 3b0efdf | 2012-06-13 10:24:57 -0500 | [diff] [blame] | 68 | int object_size; /* The size of an object without meta data */ |
Christoph Lameter | 81819f0 | 2007-05-06 14:49:36 -0700 | [diff] [blame] | 69 | int offset; /* Free pointer offset. */ |
Alex Shi | 9f26490 | 2011-09-01 11:32:18 +0800 | [diff] [blame] | 70 | int cpu_partial; /* Number of per cpu partial objects to keep around */ |
Christoph Lameter | 834f3d1 | 2008-04-14 19:11:31 +0300 | [diff] [blame] | 71 | struct kmem_cache_order_objects oo; |
Christoph Lameter | 81819f0 | 2007-05-06 14:49:36 -0700 | [diff] [blame] | 72 | |
Christoph Lameter | 81819f0 | 2007-05-06 14:49:36 -0700 | [diff] [blame] | 73 | /* Allocation and freeing of slabs */ |
Christoph Lameter | 205ab99 | 2008-04-14 19:11:40 +0300 | [diff] [blame] | 74 | struct kmem_cache_order_objects max; |
Christoph Lameter | 65c3376 | 2008-04-14 19:11:40 +0300 | [diff] [blame] | 75 | struct kmem_cache_order_objects min; |
Christoph Lameter | b7a49f0 | 2008-02-14 14:21:32 -0800 | [diff] [blame] | 76 | gfp_t allocflags; /* gfp flags to use on each alloc */ |
Christoph Lameter | 81819f0 | 2007-05-06 14:49:36 -0700 | [diff] [blame] | 77 | int refcount; /* Refcount for slab cache destroy */ |
Alexey Dobriyan | 51cc506 | 2008-07-25 19:45:34 -0700 | [diff] [blame] | 78 | void (*ctor)(void *); |
Christoph Lameter | 81819f0 | 2007-05-06 14:49:36 -0700 | [diff] [blame] | 79 | int inuse; /* Offset to metadata */ |
| 80 | int align; /* Alignment */ |
Lai Jiangshan | ab9a0f1 | 2011-03-10 15:21:48 +0800 | [diff] [blame] | 81 | int reserved; /* Reserved bytes at the end of slabs */ |
Christoph Lameter | 81819f0 | 2007-05-06 14:49:36 -0700 | [diff] [blame] | 82 | const char *name; /* Name (only for display!) */ |
| 83 | struct list_head list; /* List of slab caches */ |
Joonsoo Kim | d86bd1b | 2016-03-15 14:55:12 -0700 | [diff] [blame] | 84 | int red_left_pad; /* Left redzone padding size */ |
Christoph Lameter | ab4d5ed | 2010-10-05 13:57:26 -0500 | [diff] [blame] | 85 | #ifdef CONFIG_SYSFS |
Christoph Lameter | 81819f0 | 2007-05-06 14:49:36 -0700 | [diff] [blame] | 86 | struct kobject kobj; /* For sysfs */ |
Christoph Lameter | 0c71001 | 2007-07-17 04:03:24 -0700 | [diff] [blame] | 87 | #endif |
Johannes Weiner | 127424c | 2016-01-20 15:02:32 -0800 | [diff] [blame] | 88 | #ifdef CONFIG_MEMCG |
Vladimir Davydov | f7ce319 | 2015-02-12 14:59:20 -0800 | [diff] [blame] | 89 | struct memcg_cache_params memcg_params; |
Glauber Costa | 107dab5 | 2012-12-18 14:23:05 -0800 | [diff] [blame] | 90 | int max_attr_size; /* for propagation, maximum size of a stored attr */ |
Vladimir Davydov | 9a41707 | 2014-04-07 15:39:31 -0700 | [diff] [blame] | 91 | #ifdef CONFIG_SYSFS |
| 92 | struct kset *memcg_kset; |
| 93 | #endif |
Glauber Costa | ba6c496 | 2012-12-18 14:22:27 -0800 | [diff] [blame] | 94 | #endif |
Christoph Lameter | 81819f0 | 2007-05-06 14:49:36 -0700 | [diff] [blame] | 95 | |
| 96 | #ifdef CONFIG_NUMA |
Christoph Lameter | 9824601 | 2008-01-07 23:20:26 -0800 | [diff] [blame] | 97 | /* |
| 98 | * Defragmentation by allocating from a remote node. |
| 99 | */ |
| 100 | int remote_node_defrag_ratio; |
Christoph Lameter | 81819f0 | 2007-05-06 14:49:36 -0700 | [diff] [blame] | 101 | #endif |
Christoph Lameter | 7340cc8 | 2010-09-28 08:10:26 -0500 | [diff] [blame] | 102 | struct kmem_cache_node *node[MAX_NUMNODES]; |
Christoph Lameter | 81819f0 | 2007-05-06 14:49:36 -0700 | [diff] [blame] | 103 | }; |
| 104 | |
Christoph Lameter | 41a2128 | 2014-05-06 12:50:08 -0700 | [diff] [blame] | 105 | #ifdef CONFIG_SYSFS |
| 106 | #define SLAB_SUPPORTS_SYSFS |
| 107 | void sysfs_slab_remove(struct kmem_cache *); |
| 108 | #else |
| 109 | static inline void sysfs_slab_remove(struct kmem_cache *s) |
| 110 | { |
| 111 | } |
| 112 | #endif |
| 113 | |
Andrey Ryabinin | 75c66de | 2015-02-13 14:39:35 -0800 | [diff] [blame] | 114 | void object_err(struct kmem_cache *s, struct page *page, |
| 115 | u8 *object, char *reason); |
| 116 | |
Alexander Potapenko | 7ed2f9e | 2016-03-25 14:21:59 -0700 | [diff] [blame] | 117 | static inline void *nearest_obj(struct kmem_cache *cache, struct page *page, |
| 118 | void *x) { |
| 119 | void *object = x - (x - page_address(page)) % cache->size; |
| 120 | void *last_object = page_address(page) + |
| 121 | (page->objects - 1) * cache->size; |
| 122 | if (unlikely(object > last_object)) |
| 123 | return last_object; |
| 124 | else |
| 125 | return object; |
| 126 | } |
| 127 | |
Christoph Lameter | 81819f0 | 2007-05-06 14:49:36 -0700 | [diff] [blame] | 128 | #endif /* _LINUX_SLUB_DEF_H */ |