This source file includes following definitions.
- nearest_obj
- obj_to_index
1
2 #ifndef _LINUX_SLAB_DEF_H
3 #define _LINUX_SLAB_DEF_H
4
5 #include <linux/reciprocal_div.h>
6
7
8
9
10
11 struct kmem_cache {
12 struct array_cache __percpu *cpu_cache;
13
14
15 unsigned int batchcount;
16 unsigned int limit;
17 unsigned int shared;
18
19 unsigned int size;
20 struct reciprocal_value reciprocal_buffer_size;
21
22
23 slab_flags_t flags;
24 unsigned int num;
25
26
27
28 unsigned int gfporder;
29
30
31 gfp_t allocflags;
32
33 size_t colour;
34 unsigned int colour_off;
35 struct kmem_cache *freelist_cache;
36 unsigned int freelist_size;
37
38
39 void (*ctor)(void *obj);
40
41
42 const char *name;
43 struct list_head list;
44 int refcount;
45 int object_size;
46 int align;
47
48
49 #ifdef CONFIG_DEBUG_SLAB
50 unsigned long num_active;
51 unsigned long num_allocations;
52 unsigned long high_mark;
53 unsigned long grown;
54 unsigned long reaped;
55 unsigned long errors;
56 unsigned long max_freeable;
57 unsigned long node_allocs;
58 unsigned long node_frees;
59 unsigned long node_overflow;
60 atomic_t allochit;
61 atomic_t allocmiss;
62 atomic_t freehit;
63 atomic_t freemiss;
64
65
66
67
68
69
70
71
72 int obj_offset;
73 #endif
74
75 #ifdef CONFIG_MEMCG
76 struct memcg_cache_params memcg_params;
77 #endif
78 #ifdef CONFIG_KASAN
79 struct kasan_cache kasan_info;
80 #endif
81
82 #ifdef CONFIG_SLAB_FREELIST_RANDOM
83 unsigned int *random_seq;
84 #endif
85
86 unsigned int useroffset;
87 unsigned int usersize;
88
89 struct kmem_cache_node *node[MAX_NUMNODES];
90 };
91
92 static inline void *nearest_obj(struct kmem_cache *cache, struct page *page,
93 void *x)
94 {
95 void *object = x - (x - page->s_mem) % cache->size;
96 void *last_object = page->s_mem + (cache->num - 1) * cache->size;
97
98 if (unlikely(object > last_object))
99 return last_object;
100 else
101 return object;
102 }
103
104
105
106
107
108
109
110 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
111 const struct page *page, void *obj)
112 {
113 u32 offset = (obj - page->s_mem);
114 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
115 }
116
117 #endif