OSDN Git Service

Merge 72078891843ce0d5b8e95040d09ba92913916af9 on remote branch
[sagit-ice-cold/kernel_xiaomi_msm8998.git] / include / linux / slub_def.h
1 #ifndef _LINUX_SLUB_DEF_H
2 #define _LINUX_SLUB_DEF_H
3
4 /*
5  * SLUB : A Slab allocator without object queues.
6  *
7  * (C) 2007 SGI, Christoph Lameter
8  */
9 #include <linux/kobject.h>
10
11 enum stat_item {
12         ALLOC_FASTPATH,         /* Allocation from cpu slab */
13         ALLOC_SLOWPATH,         /* Allocation by getting a new cpu slab */
14         FREE_FASTPATH,          /* Free to cpu slab */
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 */
19         ALLOC_FROM_PARTIAL,     /* Cpu slab acquired from node partial list */
20         ALLOC_SLAB,             /* Cpu slab acquired from page allocator */
21         ALLOC_REFILL,           /* Refill cpu slab from slab freelist */
22         ALLOC_NODE_MISMATCH,    /* Switching cpu slab */
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 */
30         DEACTIVATE_BYPASS,      /* Implicit deactivation */
31         ORDER_FALLBACK,         /* Number of times fallback was necessary */
32         CMPXCHG_DOUBLE_CPU_FAIL,/* Failure of this_cpu_cmpxchg_double */
33         CMPXCHG_DOUBLE_FAIL,    /* Number of times that cmpxchg double did not match */
34         CPU_PARTIAL_ALLOC,      /* Used cpu partial on alloc */
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 */
38         NR_SLUB_STAT_ITEMS };
39
40 struct kmem_cache_cpu {
41         void **freelist;        /* Pointer to next available object */
42         unsigned long tid;      /* Globally unique transaction id */
43         struct page *page;      /* The slab from which we are allocating */
44         struct page *partial;   /* Partially allocated frozen slabs */
45 #ifdef CONFIG_SLUB_STATS
46         unsigned stat[NR_SLUB_STAT_ITEMS];
47 #endif
48 };
49
50 /*
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 /*
60  * Slab cache management.
61  */
62 struct kmem_cache {
63         struct kmem_cache_cpu __percpu *cpu_slab;
64         /* Used for retriving partial slabs etc */
65         unsigned long flags;
66         unsigned long min_partial;
67         int size;               /* The size of an object including meta data */
68         int object_size;        /* The size of an object without meta data */
69         int offset;             /* Free pointer offset. */
70         /* Number of per cpu partial objects to keep around */
71         unsigned int cpu_partial;
72         struct kmem_cache_order_objects oo;
73
74         /* Allocation and freeing of slabs */
75         struct kmem_cache_order_objects max;
76         struct kmem_cache_order_objects min;
77         gfp_t allocflags;       /* gfp flags to use on each alloc */
78         int refcount;           /* Refcount for slab cache destroy */
79         void (*ctor)(void *);
80         int inuse;              /* Offset to metadata */
81         int align;              /* Alignment */
82         int reserved;           /* Reserved bytes at the end of slabs */
83         const char *name;       /* Name (only for display!) */
84         struct list_head list;  /* List of slab caches */
85         int red_left_pad;       /* Left redzone padding size */
86 #ifdef CONFIG_SYSFS
87         struct kobject kobj;    /* For sysfs */
88 #endif
89 #ifdef CONFIG_MEMCG_KMEM
90         struct memcg_cache_params memcg_params;
91         int max_attr_size; /* for propagation, maximum size of a stored attr */
92 #ifdef CONFIG_SYSFS
93         struct kset *memcg_kset;
94 #endif
95 #endif
96
97 #ifdef CONFIG_NUMA
98         /*
99          * Defragmentation by allocating from a remote node.
100          */
101         int remote_node_defrag_ratio;
102 #endif
103
104 #ifdef CONFIG_KASAN
105         struct kasan_cache kasan_info;
106 #endif
107
108         struct kmem_cache_node *node[MAX_NUMNODES];
109 };
110
111 #ifdef CONFIG_SYSFS
112 #define SLAB_SUPPORTS_SYSFS
113 void sysfs_slab_remove(struct kmem_cache *);
114 #else
115 static inline void sysfs_slab_remove(struct kmem_cache *s)
116 {
117 }
118 #endif
119
120
121 /**
122  * virt_to_obj - returns address of the beginning of object.
123  * @s: object's kmem_cache
124  * @slab_page: address of slab page
125  * @x: address within object memory range
126  *
127  * Returns address of the beginning of object
128  */
129 static inline void *virt_to_obj(struct kmem_cache *s,
130                                 const void *slab_page,
131                                 const void *x)
132 {
133         return (void *)x - ((x - slab_page) % s->size);
134 }
135
136 void object_err(struct kmem_cache *s, struct page *page,
137                 u8 *object, char *reason);
138
139 static inline void *nearest_obj(struct kmem_cache *cache, struct page *page,
140                                 void *x) {
141         void *object = x - (x - page_address(page)) % cache->size;
142         void *last_object = page_address(page) +
143                 (page->objects - 1) * cache->size;
144         if (unlikely(object > last_object))
145                 return last_object;
146         else
147                 return object;
148 }
149
150 #endif /* _LINUX_SLUB_DEF_H */