2 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 #ifndef __XFS_SUPPORT_KMEM_H__
19 #define __XFS_SUPPORT_KMEM_H__
21 #include <linux/slab.h>
22 #include <linux/sched.h>
26 * memory management routines
28 #define KM_SLEEP 0x0001u
29 #define KM_NOSLEEP 0x0002u
30 #define KM_NOFS 0x0004u
31 #define KM_MAYFAIL 0x0008u
33 #define kmem_zone kmem_cache
34 #define kmem_zone_t struct kmem_cache
36 typedef unsigned long xfs_pflags_t
;
38 #define PFLAGS_TEST_NOIO() (current->flags & PF_NOIO)
39 #define PFLAGS_TEST_FSTRANS() (current->flags & PF_FSTRANS)
41 #define PFLAGS_SET_NOIO() do { \
42 current->flags |= PF_NOIO; \
45 #define PFLAGS_CLEAR_NOIO() do { \
46 current->flags &= ~PF_NOIO; \
49 /* these could be nested, so we save state */
50 #define PFLAGS_SET_FSTRANS(STATEP) do { \
51 *(STATEP) = current->flags; \
52 current->flags |= PF_FSTRANS; \
55 #define PFLAGS_CLEAR_FSTRANS(STATEP) do { \
56 *(STATEP) = current->flags; \
57 current->flags &= ~PF_FSTRANS; \
60 /* Restore the PF_FSTRANS state to what was saved in STATEP */
61 #define PFLAGS_RESTORE_FSTRANS(STATEP) do { \
62 current->flags = ((current->flags & ~PF_FSTRANS) | \
63 (*(STATEP) & PF_FSTRANS)); \
66 #define PFLAGS_DUP(OSTATEP, NSTATEP) do { \
67 *(NSTATEP) = *(OSTATEP); \
70 static __inline gfp_t
kmem_flags_convert(unsigned int __nocast flags
)
72 gfp_t lflags
= __GFP_NOWARN
; /* we'll report problems, if need be */
75 if (unlikely(flags
& ~(KM_SLEEP
|KM_NOSLEEP
|KM_NOFS
|KM_MAYFAIL
))) {
77 "XFS: memory allocation with wrong flags (%x)\n", flags
);
82 if (flags
& KM_NOSLEEP
) {
87 /* avoid recusive callbacks to filesystem during transactions */
88 if (PFLAGS_TEST_FSTRANS() || (flags
& KM_NOFS
))
95 static __inline kmem_zone_t
*
96 kmem_zone_init(int size
, char *zone_name
)
98 return kmem_cache_create(zone_name
, size
, 0, 0, NULL
, NULL
);
102 kmem_zone_free(kmem_zone_t
*zone
, void *ptr
)
104 kmem_cache_free(zone
, ptr
);
108 kmem_zone_destroy(kmem_zone_t
*zone
)
110 if (zone
&& kmem_cache_destroy(zone
))
114 extern void *kmem_zone_zalloc(kmem_zone_t
*, unsigned int __nocast
);
115 extern void *kmem_zone_alloc(kmem_zone_t
*, unsigned int __nocast
);
117 extern void *kmem_alloc(size_t, unsigned int __nocast
);
118 extern void *kmem_realloc(void *, size_t, size_t, unsigned int __nocast
);
119 extern void *kmem_zalloc(size_t, unsigned int __nocast
);
120 extern void kmem_free(void *, size_t);
122 typedef struct shrinker
*kmem_shaker_t
;
123 typedef int (*kmem_shake_func_t
)(int, gfp_t
);
125 static __inline kmem_shaker_t
126 kmem_shake_register(kmem_shake_func_t sfunc
)
128 return set_shrinker(DEFAULT_SEEKS
, sfunc
);
132 kmem_shake_deregister(kmem_shaker_t shrinker
)
134 remove_shrinker(shrinker
);
138 kmem_shake_allow(gfp_t gfp_mask
)
140 return (gfp_mask
& __GFP_WAIT
);
143 #endif /* __XFS_SUPPORT_KMEM_H__ */