slab_def.h 2.3 KB
Newer Older
1 2 3
#ifndef _LINUX_SLAB_DEF_H
#define	_LINUX_SLAB_DEF_H

4 5
#include <linux/reciprocal_div.h>

6 7
/*
 * Definitions unique to the original Linux SLAB allocator.
8 9 10
 */

struct kmem_cache {
11 12
	struct array_cache __percpu *cpu_cache;

13
/* 1) Cache tunables. Protected by slab_mutex */
14 15 16 17
	unsigned int batchcount;
	unsigned int limit;
	unsigned int shared;

18
	unsigned int size;
19
	struct reciprocal_value reciprocal_buffer_size;
20
/* 2) touched by every alloc & free from the backend */
21 22 23 24

	unsigned int flags;		/* constant flags */
	unsigned int num;		/* # of objs per slab */

25
/* 3) cache_grow/shrink */
26 27 28 29
	/* order of pgs per slab (2^n) */
	unsigned int gfporder;

	/* force GFP flags, e.g. GFP_DMA */
30
	gfp_t allocflags;
31 32 33

	size_t colour;			/* cache colouring range */
	unsigned int colour_off;	/* colour offset */
34 35
	struct kmem_cache *freelist_cache;
	unsigned int freelist_size;
36 37 38 39

	/* constructor func */
	void (*ctor)(void *obj);

40
/* 4) cache creation/removal */
41
	const char *name;
42 43 44 45
	struct list_head list;
	int refcount;
	int object_size;
	int align;
46

47
/* 5) statistics */
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
#ifdef CONFIG_DEBUG_SLAB
	unsigned long num_active;
	unsigned long num_allocations;
	unsigned long high_mark;
	unsigned long grown;
	unsigned long reaped;
	unsigned long errors;
	unsigned long max_freeable;
	unsigned long node_allocs;
	unsigned long node_frees;
	unsigned long node_overflow;
	atomic_t allochit;
	atomic_t allocmiss;
	atomic_t freehit;
	atomic_t freemiss;
63 64 65
#ifdef CONFIG_DEBUG_SLAB_LEAK
	atomic_t store_user_clean;
#endif
66 67 68

	/*
	 * If debugging is enabled, then the allocator can add additional
69
	 * fields and/or padding to every object. size contains the total
70 71 72 73 74
	 * object size including these internal fields, the following two
	 * variables contain the offset to the user object and its size.
	 */
	int obj_offset;
#endif /* CONFIG_DEBUG_SLAB */
75 76

#ifdef CONFIG_MEMCG
77
	struct memcg_cache_params memcg_params;
G
Glauber Costa 已提交
78
#endif
A
Alexander Potapenko 已提交
79 80 81
#ifdef CONFIG_KASAN
	struct kasan_cache kasan_info;
#endif
82

83
	struct kmem_cache_node *node[MAX_NUMNODES];
84 85
};

A
Alexander Potapenko 已提交
86 87 88 89 90 91 92 93 94 95 96
static inline void *nearest_obj(struct kmem_cache *cache, struct page *page,
				void *x) {
	void *object = x - (x - page->s_mem) % cache->size;
	void *last_object = page->s_mem + (cache->num - 1) * cache->size;

	if (unlikely(object > last_object))
		return last_object;
	else
		return object;
}

97
#endif	/* _LINUX_SLAB_DEF_H */