aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs/linux-2.6/kmem.h
diff options
context:
space:
mode:
authorNathan Scott <nathans@sgi.com>2006-03-13 21:18:19 -0500
committerNathan Scott <nathans@sgi.com>2006-03-13 21:18:19 -0500
commit8758280fcc6129be89503efe93bb59eaf2f85d28 (patch)
tree395246120b571385c1f3efad773b83a932d008da /fs/xfs/linux-2.6/kmem.h
parent8d280b98cfe3c0b69c37d355218975c1c0279bb0 (diff)
[XFS] Cleanup the use of zones/slabs, more consistent and allows flags to
be passed. SGI-PV: 949073 SGI-Modid: xfs-linux-melb:xfs-kern:25122a Signed-off-by: Nathan Scott <nathans@sgi.com>
Diffstat (limited to 'fs/xfs/linux-2.6/kmem.h')
-rw-r--r--fs/xfs/linux-2.6/kmem.h91
1 files changed, 55 insertions, 36 deletions
diff --git a/fs/xfs/linux-2.6/kmem.h b/fs/xfs/linux-2.6/kmem.h
index c64a29cdfff3..f0268a84e6fd 100644
--- a/fs/xfs/linux-2.6/kmem.h
+++ b/fs/xfs/linux-2.6/kmem.h
@@ -23,17 +23,8 @@
23#include <linux/mm.h> 23#include <linux/mm.h>
24 24
25/* 25/*
26 * memory management routines 26 * Process flags handling
27 */ 27 */
28#define KM_SLEEP 0x0001u
29#define KM_NOSLEEP 0x0002u
30#define KM_NOFS 0x0004u
31#define KM_MAYFAIL 0x0008u
32
33#define kmem_zone kmem_cache
34#define kmem_zone_t struct kmem_cache
35
36typedef unsigned long xfs_pflags_t;
37 28
38#define PFLAGS_TEST_NOIO() (current->flags & PF_NOIO) 29#define PFLAGS_TEST_NOIO() (current->flags & PF_NOIO)
39#define PFLAGS_TEST_FSTRANS() (current->flags & PF_FSTRANS) 30#define PFLAGS_TEST_FSTRANS() (current->flags & PF_FSTRANS)
@@ -67,74 +58,102 @@ typedef unsigned long xfs_pflags_t;
67 *(NSTATEP) = *(OSTATEP); \ 58 *(NSTATEP) = *(OSTATEP); \
68} while (0) 59} while (0)
69 60
70static __inline gfp_t kmem_flags_convert(unsigned int __nocast flags) 61/*
62 * General memory allocation interfaces
63 */
64
65#define KM_SLEEP 0x0001u
66#define KM_NOSLEEP 0x0002u
67#define KM_NOFS 0x0004u
68#define KM_MAYFAIL 0x0008u
69
70/*
71 * We use a special process flag to avoid recursive callbacks into
72 * the filesystem during transactions. We will also issue our own
73 * warnings, so we explicitly skip any generic ones (silly of us).
74 */
75static inline gfp_t
76kmem_flags_convert(unsigned int __nocast flags)
71{ 77{
72 gfp_t lflags = __GFP_NOWARN; /* we'll report problems, if need be */ 78 gfp_t lflags;
73 79
74#ifdef DEBUG 80 BUG_ON(flags & ~(KM_SLEEP|KM_NOSLEEP|KM_NOFS|KM_MAYFAIL));
75 if (unlikely(flags & ~(KM_SLEEP|KM_NOSLEEP|KM_NOFS|KM_MAYFAIL))) {
76 printk(KERN_WARNING
77 "XFS: memory allocation with wrong flags (%x)\n", flags);
78 BUG();
79 }
80#endif
81 81
82 if (flags & KM_NOSLEEP) { 82 if (flags & KM_NOSLEEP) {
83 lflags |= GFP_ATOMIC; 83 lflags = GFP_ATOMIC | __GFP_NOWARN;
84 } else { 84 } else {
85 lflags |= GFP_KERNEL; 85 lflags = GFP_KERNEL | __GFP_NOWARN;
86
87 /* avoid recusive callbacks to filesystem during transactions */
88 if (PFLAGS_TEST_FSTRANS() || (flags & KM_NOFS)) 86 if (PFLAGS_TEST_FSTRANS() || (flags & KM_NOFS))
89 lflags &= ~__GFP_FS; 87 lflags &= ~__GFP_FS;
90 } 88 }
91 89 return lflags;
92 return lflags;
93} 90}
94 91
95static __inline kmem_zone_t * 92extern void *kmem_alloc(size_t, unsigned int __nocast);
93extern void *kmem_realloc(void *, size_t, size_t, unsigned int __nocast);
94extern void *kmem_zalloc(size_t, unsigned int __nocast);
95extern void kmem_free(void *, size_t);
96
97/*
98 * Zone interfaces
99 */
100
101#define KM_ZONE_HWALIGN SLAB_HWCACHE_ALIGN
102#define KM_ZONE_RECLAIM SLAB_RECLAIM_ACCOUNT
103#define KM_ZONE_SPREAD 0
104
105#define kmem_zone kmem_cache
106#define kmem_zone_t struct kmem_cache
107
108static inline kmem_zone_t *
96kmem_zone_init(int size, char *zone_name) 109kmem_zone_init(int size, char *zone_name)
97{ 110{
98 return kmem_cache_create(zone_name, size, 0, 0, NULL, NULL); 111 return kmem_cache_create(zone_name, size, 0, 0, NULL, NULL);
99} 112}
100 113
101static __inline void 114static inline kmem_zone_t *
115kmem_zone_init_flags(int size, char *zone_name, unsigned long flags,
116 void (*construct)(void *, kmem_zone_t *, unsigned long))
117{
118 return kmem_cache_create(zone_name, size, 0, flags, construct, NULL);
119}
120
121static inline void
102kmem_zone_free(kmem_zone_t *zone, void *ptr) 122kmem_zone_free(kmem_zone_t *zone, void *ptr)
103{ 123{
104 kmem_cache_free(zone, ptr); 124 kmem_cache_free(zone, ptr);
105} 125}
106 126
107static __inline void 127static inline void
108kmem_zone_destroy(kmem_zone_t *zone) 128kmem_zone_destroy(kmem_zone_t *zone)
109{ 129{
110 if (zone && kmem_cache_destroy(zone)) 130 if (zone && kmem_cache_destroy(zone))
111 BUG(); 131 BUG();
112} 132}
113 133
114extern void *kmem_zone_zalloc(kmem_zone_t *, unsigned int __nocast);
115extern void *kmem_zone_alloc(kmem_zone_t *, unsigned int __nocast); 134extern void *kmem_zone_alloc(kmem_zone_t *, unsigned int __nocast);
135extern void *kmem_zone_zalloc(kmem_zone_t *, unsigned int __nocast);
116 136
117extern void *kmem_alloc(size_t, unsigned int __nocast); 137/*
118extern void *kmem_realloc(void *, size_t, size_t, unsigned int __nocast); 138 * Low memory cache shrinkers
119extern void *kmem_zalloc(size_t, unsigned int __nocast); 139 */
120extern void kmem_free(void *, size_t);
121 140
122typedef struct shrinker *kmem_shaker_t; 141typedef struct shrinker *kmem_shaker_t;
123typedef int (*kmem_shake_func_t)(int, gfp_t); 142typedef int (*kmem_shake_func_t)(int, gfp_t);
124 143
125static __inline kmem_shaker_t 144static inline kmem_shaker_t
126kmem_shake_register(kmem_shake_func_t sfunc) 145kmem_shake_register(kmem_shake_func_t sfunc)
127{ 146{
128 return set_shrinker(DEFAULT_SEEKS, sfunc); 147 return set_shrinker(DEFAULT_SEEKS, sfunc);
129} 148}
130 149
131static __inline void 150static inline void
132kmem_shake_deregister(kmem_shaker_t shrinker) 151kmem_shake_deregister(kmem_shaker_t shrinker)
133{ 152{
134 remove_shrinker(shrinker); 153 remove_shrinker(shrinker);
135} 154}
136 155
137static __inline int 156static inline int
138kmem_shake_allow(gfp_t gfp_mask) 157kmem_shake_allow(gfp_t gfp_mask)
139{ 158{
140 return (gfp_mask & __GFP_WAIT); 159 return (gfp_mask & __GFP_WAIT);