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 */ |
Christoph Lameter | ab4d5ed | 2010-10-05 13:57:26 -0500 | [diff] [blame] | 84 | #ifdef CONFIG_SYSFS |
Christoph Lameter | 81819f0 | 2007-05-06 14:49:36 -0700 | [diff] [blame] | 85 | struct kobject kobj; /* For sysfs */ |
Christoph Lameter | 0c71001 | 2007-07-17 04:03:24 -0700 | [diff] [blame] | 86 | #endif |
Glauber Costa | ba6c496 | 2012-12-18 14:22:27 -0800 | [diff] [blame] | 87 | #ifdef CONFIG_MEMCG_KMEM |
Vladimir Davydov | f7ce319 | 2015-02-12 14:59:20 -0800 | [diff] [blame] | 88 | struct memcg_cache_params memcg_params; |
Glauber Costa | 107dab5 | 2012-12-18 14:23:05 -0800 | [diff] [blame] | 89 | int max_attr_size; /* for propagation, maximum size of a stored attr */ |
Vladimir Davydov | 9a41707 | 2014-04-07 15:39:31 -0700 | [diff] [blame] | 90 | #ifdef CONFIG_SYSFS |
| 91 | struct kset *memcg_kset; |
| 92 | #endif |
Glauber Costa | ba6c496 | 2012-12-18 14:22:27 -0800 | [diff] [blame] | 93 | #endif |
Christoph Lameter | 81819f0 | 2007-05-06 14:49:36 -0700 | [diff] [blame] | 94 | |
| 95 | #ifdef CONFIG_NUMA |
Christoph Lameter | 9824601 | 2008-01-07 23:20:26 -0800 | [diff] [blame] | 96 | /* |
| 97 | * Defragmentation by allocating from a remote node. |
| 98 | */ |
| 99 | int remote_node_defrag_ratio; |
Christoph Lameter | 81819f0 | 2007-05-06 14:49:36 -0700 | [diff] [blame] | 100 | #endif |
Christoph Lameter | 7340cc8 | 2010-09-28 08:10:26 -0500 | [diff] [blame] | 101 | struct kmem_cache_node *node[MAX_NUMNODES]; |
Christoph Lameter | 81819f0 | 2007-05-06 14:49:36 -0700 | [diff] [blame] | 102 | }; |
| 103 | |
Christoph Lameter | 41a2128 | 2014-05-06 12:50:08 -0700 | [diff] [blame] | 104 | #ifdef CONFIG_SYSFS |
| 105 | #define SLAB_SUPPORTS_SYSFS |
| 106 | void sysfs_slab_remove(struct kmem_cache *); |
| 107 | #else |
| 108 | static inline void sysfs_slab_remove(struct kmem_cache *s) |
| 109 | { |
| 110 | } |
| 111 | #endif |
| 112 | |
Andrey Ryabinin | 912f5fb | 2015-02-13 14:39:31 -0800 | [diff] [blame] | 113 | |
| 114 | /** |
| 115 | * virt_to_obj - returns address of the beginning of object. |
| 116 | * @s: object's kmem_cache |
| 117 | * @slab_page: address of slab page |
| 118 | * @x: address within object memory range |
| 119 | * |
| 120 | * Returns address of the beginning of object |
| 121 | */ |
| 122 | static inline void *virt_to_obj(struct kmem_cache *s, |
| 123 | const void *slab_page, |
| 124 | const void *x) |
| 125 | { |
| 126 | return (void *)x - ((x - slab_page) % s->size); |
| 127 | } |
| 128 | |
Andrey Ryabinin | 75c66de | 2015-02-13 14:39:35 -0800 | [diff] [blame] | 129 | void object_err(struct kmem_cache *s, struct page *page, |
| 130 | u8 *object, char *reason); |
| 131 | |
Christoph Lameter | 81819f0 | 2007-05-06 14:49:36 -0700 | [diff] [blame] | 132 | #endif /* _LINUX_SLUB_DEF_H */ |