slub_def.h 4.21 KB
Newer Older
Christoph Lameter's avatar
Christoph Lameter committed
1 2 3 4 5 6
#ifndef _LINUX_SLUB_DEF_H
#define _LINUX_SLUB_DEF_H

/*
 * SLUB : A Slab allocator without object queues.
 *
Christoph Lameter's avatar
Christoph Lameter committed
7
 * (C) 2007 SGI, Christoph Lameter
Christoph Lameter's avatar
Christoph Lameter committed
8 9 10
 */
#include <linux/kobject.h>

11 12 13
enum stat_item {
	ALLOC_FASTPATH,		/* Allocation from cpu slab */
	ALLOC_SLOWPATH,		/* Allocation by getting a new cpu slab */
14
	FREE_FASTPATH,		/* Free to cpu slab */
15 16 17 18
	FREE_SLOWPATH,		/* Freeing not to cpu slab */
	FREE_FROZEN,		/* Freeing to frozen slab */
	FREE_ADD_PARTIAL,	/* Freeing moves slab to partial list */
	FREE_REMOVE_PARTIAL,	/* Freeing removes last object */
19
	ALLOC_FROM_PARTIAL,	/* Cpu slab acquired from node partial list */
20 21
	ALLOC_SLAB,		/* Cpu slab acquired from page allocator */
	ALLOC_REFILL,		/* Refill cpu slab from slab freelist */
22
	ALLOC_NODE_MISMATCH,	/* Switching cpu slab */
23 24 25 26 27 28 29
	FREE_SLAB,		/* Slab freed to the page allocator */
	CPUSLAB_FLUSH,		/* Abandoning of the cpu slab */
	DEACTIVATE_FULL,	/* Cpu slab was full when deactivated */
	DEACTIVATE_EMPTY,	/* Cpu slab was empty when deactivated */
	DEACTIVATE_TO_HEAD,	/* Cpu slab was moved to the head of partials */
	DEACTIVATE_TO_TAIL,	/* Cpu slab was moved to the tail of partials */
	DEACTIVATE_REMOTE_FREES,/* Slab contained remotely freed objects */
30
	DEACTIVATE_BYPASS,	/* Implicit deactivation */
31
	ORDER_FALLBACK,		/* Number of times fallback was necessary */
32
	CMPXCHG_DOUBLE_CPU_FAIL,/* Failure of this_cpu_cmpxchg_double */
33
	CMPXCHG_DOUBLE_FAIL,	/* Number of times that cmpxchg double did not match */
34
	CPU_PARTIAL_ALLOC,	/* Used cpu partial on alloc */
35 36 37
	CPU_PARTIAL_FREE,	/* Refill cpu partial on free */
	CPU_PARTIAL_NODE,	/* Refill cpu partial from node partial */
	CPU_PARTIAL_DRAIN,	/* Drain cpu partial to node partial */
38 39
	NR_SLUB_STAT_ITEMS };

40
struct kmem_cache_cpu {
41 42
	void **freelist;	/* Pointer to next available object */
	unsigned long tid;	/* Globally unique transaction id */
43
	struct page *page;	/* The slab from which we are allocating */
44
	struct page *partial;	/* Partially allocated frozen slabs */
45 46 47
#ifdef CONFIG_SLUB_STATS
	unsigned stat[NR_SLUB_STAT_ITEMS];
#endif
48
};
49

50 51 52 53 54 55 56 57 58
/*
 * Word size structure that can be atomically updated or read and that
 * contains both the order and the number of objects that a slab of the
 * given order would contain.
 */
struct kmem_cache_order_objects {
	unsigned long x;
};

Christoph Lameter's avatar
Christoph Lameter committed
59 60 61 62
/*
 * Slab cache management.
 */
struct kmem_cache {
63
	struct kmem_cache_cpu __percpu *cpu_slab;
Christoph Lameter's avatar
Christoph Lameter committed
64 65
	/* Used for retriving partial slabs etc */
	unsigned long flags;
66
	unsigned long min_partial;
Christoph Lameter's avatar
Christoph Lameter committed
67
	int size;		/* The size of an object including meta data */
68
	int object_size;	/* The size of an object without meta data */
Christoph Lameter's avatar
Christoph Lameter committed
69
	int offset;		/* Free pointer offset. */
70
	int cpu_partial;	/* Number of per cpu partial objects to keep around */
71
	struct kmem_cache_order_objects oo;
Christoph Lameter's avatar
Christoph Lameter committed
72 73

	/* Allocation and freeing of slabs */
74
	struct kmem_cache_order_objects max;
75
	struct kmem_cache_order_objects min;
76
	gfp_t allocflags;	/* gfp flags to use on each alloc */
Christoph Lameter's avatar
Christoph Lameter committed
77
	int refcount;		/* Refcount for slab cache destroy */
78
	void (*ctor)(void *);
Christoph Lameter's avatar
Christoph Lameter committed
79 80
	int inuse;		/* Offset to metadata */
	int align;		/* Alignment */
81
	int reserved;		/* Reserved bytes at the end of slabs */
Christoph Lameter's avatar
Christoph Lameter committed
82 83
	const char *name;	/* Name (only for display!) */
	struct list_head list;	/* List of slab caches */
84
	int red_left_pad;	/* Left redzone padding size */
85
#ifdef CONFIG_SYSFS
Christoph Lameter's avatar
Christoph Lameter committed
86
	struct kobject kobj;	/* For sysfs */
87
#endif
88
#ifdef CONFIG_MEMCG
89
	struct memcg_cache_params memcg_params;
90
	int max_attr_size; /* for propagation, maximum size of a stored attr */
91 92 93
#ifdef CONFIG_SYSFS
	struct kset *memcg_kset;
#endif
94
#endif
Christoph Lameter's avatar
Christoph Lameter committed
95 96

#ifdef CONFIG_NUMA
97 98 99 100
	/*
	 * Defragmentation by allocating from a remote node.
	 */
	int remote_node_defrag_ratio;
Christoph Lameter's avatar
Christoph Lameter committed
101
#endif
102
	struct kmem_cache_node *node[MAX_NUMNODES];
Christoph Lameter's avatar
Christoph Lameter committed
103 104
};

105 106 107 108 109 110 111 112 113
#ifdef CONFIG_SYSFS
#define SLAB_SUPPORTS_SYSFS
void sysfs_slab_remove(struct kmem_cache *);
#else
static inline void sysfs_slab_remove(struct kmem_cache *s)
{
}
#endif

114 115 116
void object_err(struct kmem_cache *s, struct page *page,
		u8 *object, char *reason);

117 118 119 120 121 122 123 124 125 126 127
static inline void *nearest_obj(struct kmem_cache *cache, struct page *page,
				void *x) {
	void *object = x - (x - page_address(page)) % cache->size;
	void *last_object = page_address(page) +
		(page->objects - 1) * cache->size;
	if (unlikely(object > last_object))
		return last_object;
	else
		return object;
}

Christoph Lameter's avatar
Christoph Lameter committed
128
#endif /* _LINUX_SLUB_DEF_H */