1
2#ifndef _LINUX_SLUB_DEF_H
3#define _LINUX_SLUB_DEF_H
4
5
6
7
8
9
10#include <linux/kobject.h>
11
12enum stat_item {
13 ALLOC_FASTPATH,
14 ALLOC_SLOWPATH,
15 FREE_FASTPATH,
16 FREE_SLOWPATH,
17 FREE_FROZEN,
18 FREE_ADD_PARTIAL,
19 FREE_REMOVE_PARTIAL,
20 ALLOC_FROM_PARTIAL,
21 ALLOC_SLAB,
22 ALLOC_REFILL,
23 ALLOC_NODE_MISMATCH,
24 FREE_SLAB,
25 CPUSLAB_FLUSH,
26 DEACTIVATE_FULL,
27 DEACTIVATE_EMPTY,
28 DEACTIVATE_TO_HEAD,
29 DEACTIVATE_TO_TAIL,
30 DEACTIVATE_REMOTE_FREES,
31 DEACTIVATE_BYPASS,
32 ORDER_FALLBACK,
33 CMPXCHG_DOUBLE_CPU_FAIL,
34 CMPXCHG_DOUBLE_FAIL,
35 CPU_PARTIAL_ALLOC,
36 CPU_PARTIAL_FREE,
37 CPU_PARTIAL_NODE,
38 CPU_PARTIAL_DRAIN,
39 NR_SLUB_STAT_ITEMS };
40
41struct kmem_cache_cpu {
42 void **freelist;
43 unsigned long tid;
44 struct page *page;
45#ifdef CONFIG_SLUB_CPU_PARTIAL
46 struct page *partial;
47#endif
48#ifdef CONFIG_SLUB_STATS
49 unsigned stat[NR_SLUB_STAT_ITEMS];
50#endif
51};
52
53#ifdef CONFIG_SLUB_CPU_PARTIAL
54#define slub_percpu_partial(c) ((c)->partial)
55
56#define slub_set_percpu_partial(c, p) \
57({ \
58 slub_percpu_partial(c) = (p)->next; \
59})
60
61#define slub_percpu_partial_read_once(c) READ_ONCE(slub_percpu_partial(c))
62#else
63#define slub_percpu_partial(c) NULL
64
65#define slub_set_percpu_partial(c, p)
66
67#define slub_percpu_partial_read_once(c) NULL
68#endif
69
70
71
72
73
74
75struct kmem_cache_order_objects {
76 unsigned int x;
77};
78
79
80
81
82struct kmem_cache {
83 struct kmem_cache_cpu __percpu *cpu_slab;
84
85 slab_flags_t flags;
86 unsigned long min_partial;
87 unsigned int size;
88 unsigned int object_size;
89 unsigned int offset;
90#ifdef CONFIG_SLUB_CPU_PARTIAL
91
92 unsigned int cpu_partial;
93#endif
94 struct kmem_cache_order_objects oo;
95
96
97 struct kmem_cache_order_objects max;
98 struct kmem_cache_order_objects min;
99 gfp_t allocflags;
100 int refcount;
101 void (*ctor)(void *);
102 unsigned int inuse;
103 unsigned int align;
104 unsigned int reserved;
105 unsigned int red_left_pad;
106 const char *name;
107 struct list_head list;
108#ifdef CONFIG_SYSFS
109 struct kobject kobj;
110 struct work_struct kobj_remove_work;
111#endif
112#ifdef CONFIG_MEMCG
113 struct memcg_cache_params memcg_params;
114
115 unsigned int max_attr_size;
116#ifdef CONFIG_SYSFS
117 struct kset *memcg_kset;
118#endif
119#endif
120
121#ifdef CONFIG_SLAB_FREELIST_HARDENED
122 unsigned long random;
123#endif
124
125#ifdef CONFIG_NUMA
126
127
128
129 unsigned int remote_node_defrag_ratio;
130#endif
131
132#ifdef CONFIG_SLAB_FREELIST_RANDOM
133 unsigned int *random_seq;
134#endif
135
136#ifdef CONFIG_KASAN
137 struct kasan_cache kasan_info;
138#endif
139
140 unsigned int useroffset;
141 unsigned int usersize;
142
143 struct kmem_cache_node *node[MAX_NUMNODES];
144};
145
146#ifdef CONFIG_SLUB_CPU_PARTIAL
147#define slub_cpu_partial(s) ((s)->cpu_partial)
148#define slub_set_cpu_partial(s, n) \
149({ \
150 slub_cpu_partial(s) = (n); \
151})
152#else
153#define slub_cpu_partial(s) (0)
154#define slub_set_cpu_partial(s, n)
155#endif
156
157#ifdef CONFIG_SYSFS
158#define SLAB_SUPPORTS_SYSFS
159void sysfs_slab_release(struct kmem_cache *);
160#else
161static inline void sysfs_slab_release(struct kmem_cache *s)
162{
163}
164#endif
165
166void object_err(struct kmem_cache *s, struct page *page,
167 u8 *object, char *reason);
168
169void *fixup_red_left(struct kmem_cache *s, void *p);
170
171static inline void *nearest_obj(struct kmem_cache *cache, struct page *page,
172 void *x) {
173 void *object = x - (x - page_address(page)) % cache->size;
174 void *last_object = page_address(page) +
175 (page->objects - 1) * cache->size;
176 void *result = (unlikely(object > last_object)) ? last_object : object;
177
178 result = fixup_red_left(cache, result);
179 return result;
180}
181
182#endif
183