Merge branch 'work.aio' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
[linux-block.git] / include / linux / slab_def.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
2e892f43
CL
2#ifndef _LINUX_SLAB_DEF_H
3#define _LINUX_SLAB_DEF_H
4
809fa972
HFS
5#include <linux/reciprocal_div.h>
6
2e892f43
CL
7/*
8 * Definitions unique to the original Linux SLAB allocator.
8eae985f
PE
9 */
10
11struct kmem_cache {
bf0dea23
JK
12 struct array_cache __percpu *cpu_cache;
13
24755e2e 14/* 1) Cache tunables. Protected by slab_mutex */
8eae985f
PE
15 unsigned int batchcount;
16 unsigned int limit;
17 unsigned int shared;
18
3b0efdfa 19 unsigned int size;
809fa972 20 struct reciprocal_value reciprocal_buffer_size;
b56efcf0 21/* 2) touched by every alloc & free from the backend */
8eae985f 22
d50112ed 23 slab_flags_t flags; /* constant flags */
8eae985f
PE
24 unsigned int num; /* # of objs per slab */
25
b56efcf0 26/* 3) cache_grow/shrink */
8eae985f
PE
27 /* order of pgs per slab (2^n) */
28 unsigned int gfporder;
29
30 /* force GFP flags, e.g. GFP_DMA */
a618e89f 31 gfp_t allocflags;
8eae985f
PE
32
33 size_t colour; /* cache colouring range */
34 unsigned int colour_off; /* colour offset */
8456a648
JK
35 struct kmem_cache *freelist_cache;
36 unsigned int freelist_size;
8eae985f
PE
37
38 /* constructor func */
39 void (*ctor)(void *obj);
40
b56efcf0 41/* 4) cache creation/removal */
8eae985f 42 const char *name;
3b0efdfa
CL
43 struct list_head list;
44 int refcount;
45 int object_size;
46 int align;
8eae985f 47
b56efcf0 48/* 5) statistics */
8eae985f
PE
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;
d31676df
JK
64#ifdef CONFIG_DEBUG_SLAB_LEAK
65 atomic_t store_user_clean;
66#endif
8eae985f
PE
67
68 /*
69 * If debugging is enabled, then the allocator can add additional
05fec35e
BH
70 * fields and/or padding to every object. 'size' contains the total
71 * object size including these internal fields, while 'obj_offset'
72 * and 'object_size' contain the offset to the user object and its
73 * size.
8eae985f
PE
74 */
75 int obj_offset;
8eae985f 76#endif /* CONFIG_DEBUG_SLAB */
127424c8
JW
77
78#ifdef CONFIG_MEMCG
f7ce3190 79 struct memcg_cache_params memcg_params;
ba6c496e 80#endif
7ed2f9e6
AP
81#ifdef CONFIG_KASAN
82 struct kasan_cache kasan_info;
83#endif
8eae985f 84
c7ce4f60 85#ifdef CONFIG_SLAB_FREELIST_RANDOM
7c00fce9 86 unsigned int *random_seq;
c7ce4f60
TG
87#endif
88
7bbdb81e
AD
89 unsigned int useroffset; /* Usercopy region offset */
90 unsigned int usersize; /* Usercopy region size */
8eb8284b 91
bf0dea23 92 struct kmem_cache_node *node[MAX_NUMNODES];
8eae985f
PE
93};
94
7ed2f9e6 95static inline void *nearest_obj(struct kmem_cache *cache, struct page *page,
80a9201a
AP
96 void *x)
97{
7ed2f9e6
AP
98 void *object = x - (x - page->s_mem) % cache->size;
99 void *last_object = page->s_mem + (cache->num - 1) * cache->size;
100
101 if (unlikely(object > last_object))
102 return last_object;
103 else
104 return object;
105}
106
2e892f43 107#endif /* _LINUX_SLAB_DEF_H */