aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/slab_def.h
diff options
context:
space:
mode:
authorChristoph Lameter <clameter@sgi.com>2006-12-13 03:34:23 -0500
committerLinus Torvalds <torvalds@woody.osdl.org>2006-12-13 12:05:49 -0500
commit2e892f43ccb602e8ffad73396a1000f2040c9e0b (patch)
tree2f799810eccebeb5d432daed93ed9654238887b6 /include/linux/slab_def.h
parent872225ca77519a243d7e19270b062b0ac53418d8 (diff)
[PATCH] Cleanup slab headers / API to allow easy addition of new slab allocators
This is a response to an earlier discussion on linux-mm about splitting slab.h components per allocator. Patch is against 2.6.19-git11. See http://marc.theaimsgroup.com/?l=linux-mm&m=116469577431008&w=2 This patch cleans up the slab header definitions. We define the common functions of slob and slab in slab.h and put the extra definitions needed for slab's kmalloc implementations in <linux/slab_def.h>. In order to get a greater set of common functions we add several empty functions to slob.c and also rename slob's kmalloc to __kmalloc. Slob does not need any special definitions since we introduce a fallback case. If there is no need for a slab implementation to provide its own kmalloc mess^H^H^Hacros then we simply fall back to __kmalloc functions. That is sufficient for SLOB. Sort the function in slab.h according to their functionality. First the functions operating on struct kmem_cache * then the kmalloc related functions followed by special debug and fallback definitions. Also redo a lot of comments. Signed-off-by: Christoph Lameter <clameter@sgi.com>? Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'include/linux/slab_def.h')
-rw-r--r--include/linux/slab_def.h100
1 files changed, 100 insertions, 0 deletions
diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
new file mode 100644
index 000000000000..4b463e66ddea
--- /dev/null
+++ b/include/linux/slab_def.h
@@ -0,0 +1,100 @@
1#ifndef _LINUX_SLAB_DEF_H
2#define _LINUX_SLAB_DEF_H
3
4/*
5 * Definitions unique to the original Linux SLAB allocator.
6 *
7 * What we provide here is a way to optimize the frequent kmalloc
8 * calls in the kernel by selecting the appropriate general cache
9 * if kmalloc was called with a size that can be established at
10 * compile time.
11 */
12
13#include <linux/init.h>
14#include <asm/page.h> /* kmalloc_sizes.h needs PAGE_SIZE */
15#include <asm/cache.h> /* kmalloc_sizes.h needs L1_CACHE_BYTES */
16#include <linux/compiler.h>
17
18/* Size description struct for general caches. */
19struct cache_sizes {
20 size_t cs_size;
21 struct kmem_cache *cs_cachep;
22 struct kmem_cache *cs_dmacachep;
23};
24extern struct cache_sizes malloc_sizes[];
25
26static inline void *kmalloc(size_t size, gfp_t flags)
27{
28 if (__builtin_constant_p(size)) {
29 int i = 0;
30#define CACHE(x) \
31 if (size <= x) \
32 goto found; \
33 else \
34 i++;
35#include "kmalloc_sizes.h"
36#undef CACHE
37 {
38 extern void __you_cannot_kmalloc_that_much(void);
39 __you_cannot_kmalloc_that_much();
40 }
41found:
42 return kmem_cache_alloc((flags & GFP_DMA) ?
43 malloc_sizes[i].cs_dmacachep :
44 malloc_sizes[i].cs_cachep, flags);
45 }
46 return __kmalloc(size, flags);
47}
48
49static inline void *kzalloc(size_t size, gfp_t flags)
50{
51 if (__builtin_constant_p(size)) {
52 int i = 0;
53#define CACHE(x) \
54 if (size <= x) \
55 goto found; \
56 else \
57 i++;
58#include "kmalloc_sizes.h"
59#undef CACHE
60 {
61 extern void __you_cannot_kzalloc_that_much(void);
62 __you_cannot_kzalloc_that_much();
63 }
64found:
65 return kmem_cache_zalloc((flags & GFP_DMA) ?
66 malloc_sizes[i].cs_dmacachep :
67 malloc_sizes[i].cs_cachep, flags);
68 }
69 return __kzalloc(size, flags);
70}
71
72#ifdef CONFIG_NUMA
73extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
74
75static inline void *kmalloc_node(size_t size, gfp_t flags, int node)
76{
77 if (__builtin_constant_p(size)) {
78 int i = 0;
79#define CACHE(x) \
80 if (size <= x) \
81 goto found; \
82 else \
83 i++;
84#include "kmalloc_sizes.h"
85#undef CACHE
86 {
87 extern void __you_cannot_kmalloc_that_much(void);
88 __you_cannot_kmalloc_that_much();
89 }
90found:
91 return kmem_cache_alloc_node((flags & GFP_DMA) ?
92 malloc_sizes[i].cs_dmacachep :
93 malloc_sizes[i].cs_cachep, flags, node);
94 }
95 return __kmalloc_node(size, flags, node);
96}
97
98#endif /* CONFIG_NUMA */
99
100#endif /* _LINUX_SLAB_DEF_H */