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 long x;
77};
78
79
80
81
82struct kmem_cache {
83 struct kmem_cache_cpu __percpu *cpu_slab;
84
85 unsigned long flags;
86 unsigned long min_partial;
87 int size;
88 int object_size;
89 int offset;
90#ifdef CONFIG_SLUB_CPU_PARTIAL
91 int cpu_partial;
92#endif
93 struct kmem_cache_order_objects oo;
94
95
96 struct kmem_cache_order_objects max;
97 struct kmem_cache_order_objects min;
98 gfp_t allocflags;
99 int refcount;
100 void (*ctor)(void *);
101 int inuse;
102 int align;
103 int reserved;
104 int red_left_pad;
105 const char *name;
106 struct list_head list;
107#ifdef CONFIG_SYSFS
108 struct kobject kobj;
109 struct work_struct kobj_remove_work;
110#endif
111#ifdef CONFIG_MEMCG
112 struct memcg_cache_params memcg_params;
113 int max_attr_size;
114#ifdef CONFIG_SYSFS
115 struct kset *memcg_kset;
116#endif
117#endif
118
119#ifdef CONFIG_SLAB_FREELIST_HARDENED
120 unsigned long random;
121#endif
122
123#ifdef CONFIG_NUMA
124
125
126
127 int remote_node_defrag_ratio;
128#endif
129
130#ifdef CONFIG_SLAB_FREELIST_RANDOM
131 unsigned int *random_seq;
132#endif
133
134#ifdef CONFIG_KASAN
135 struct kasan_cache kasan_info;
136#endif
137
138 struct kmem_cache_node *node[MAX_NUMNODES];
139};
140
141#ifdef CONFIG_SLUB_CPU_PARTIAL
142#define slub_cpu_partial(s) ((s)->cpu_partial)
143#define slub_set_cpu_partial(s, n) \
144({ \
145 slub_cpu_partial(s) = (n); \
146})
147#else
148#define slub_cpu_partial(s) (0)
149#define slub_set_cpu_partial(s, n)
150#endif
151
152#ifdef CONFIG_SYSFS
153#define SLAB_SUPPORTS_SYSFS
154void sysfs_slab_release(struct kmem_cache *);
155#else
156static inline void sysfs_slab_release(struct kmem_cache *s)
157{
158}
159#endif
160
161void object_err(struct kmem_cache *s, struct page *page,
162 u8 *object, char *reason);
163
164void *fixup_red_left(struct kmem_cache *s, void *p);
165
166static inline void *nearest_obj(struct kmem_cache *cache, struct page *page,
167 void *x) {
168 void *object = x - (x - page_address(page)) % cache->size;
169 void *last_object = page_address(page) +
170 (page->objects - 1) * cache->size;
171 void *result = (unlikely(object > last_object)) ? last_object : object;
172
173 result = fixup_red_left(cache, result);
174 return result;
175}
176
177#endif
178