2 * Copyright (c) 2000-2004 Silicon Graphics, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
32 #ifndef __XFS_SUPPORT_KMEM_H__
33 #define __XFS_SUPPORT_KMEM_H__
35 #include <linux/slab.h>
36 #include <linux/sched.h>
40 * memory management routines
42 #define KM_SLEEP 0x0001
43 #define KM_NOSLEEP 0x0002
44 #define KM_NOFS 0x0004
45 #define KM_MAYFAIL 0x0008
47 #define kmem_zone kmem_cache_s
48 #define kmem_zone_t kmem_cache_t
50 typedef unsigned long xfs_pflags_t
;
52 #define PFLAGS_TEST_NOIO() (current->flags & PF_NOIO)
53 #define PFLAGS_TEST_FSTRANS() (current->flags & PF_FSTRANS)
55 #define PFLAGS_SET_NOIO() do { \
56 current->flags |= PF_NOIO; \
59 #define PFLAGS_CLEAR_NOIO() do { \
60 current->flags &= ~PF_NOIO; \
63 /* these could be nested, so we save state */
64 #define PFLAGS_SET_FSTRANS(STATEP) do { \
65 *(STATEP) = current->flags; \
66 current->flags |= PF_FSTRANS; \
69 #define PFLAGS_CLEAR_FSTRANS(STATEP) do { \
70 *(STATEP) = current->flags; \
71 current->flags &= ~PF_FSTRANS; \
74 /* Restore the PF_FSTRANS state to what was saved in STATEP */
75 #define PFLAGS_RESTORE_FSTRANS(STATEP) do { \
76 current->flags = ((current->flags & ~PF_FSTRANS) | \
77 (*(STATEP) & PF_FSTRANS)); \
80 #define PFLAGS_DUP(OSTATEP, NSTATEP) do { \
81 *(NSTATEP) = *(OSTATEP); \
84 static __inline
unsigned int kmem_flags_convert(int flags
)
86 int lflags
= __GFP_NOWARN
; /* we'll report problems, if need be */
89 if (unlikely(flags
& ~(KM_SLEEP
|KM_NOSLEEP
|KM_NOFS
|KM_MAYFAIL
))) {
91 "XFS: memory allocation with wrong flags (%x)\n", flags
);
96 if (flags
& KM_NOSLEEP
) {
101 /* avoid recusive callbacks to filesystem during transactions */
102 if (PFLAGS_TEST_FSTRANS() || (flags
& KM_NOFS
))
109 static __inline kmem_zone_t
*
110 kmem_zone_init(int size
, char *zone_name
)
112 return kmem_cache_create(zone_name
, size
, 0, 0, NULL
, NULL
);
116 kmem_zone_free(kmem_zone_t
*zone
, void *ptr
)
118 kmem_cache_free(zone
, ptr
);
122 kmem_zone_destroy(kmem_zone_t
*zone
)
124 if (zone
&& kmem_cache_destroy(zone
))
128 extern void *kmem_zone_zalloc(kmem_zone_t
*, int);
129 extern void *kmem_zone_alloc(kmem_zone_t
*, int);
131 extern void *kmem_alloc(size_t, int);
132 extern void *kmem_realloc(void *, size_t, size_t, int);
133 extern void *kmem_zalloc(size_t, int);
134 extern void kmem_free(void *, size_t);
136 typedef struct shrinker
*kmem_shaker_t
;
137 typedef int (*kmem_shake_func_t
)(int, unsigned int);
139 static __inline kmem_shaker_t
140 kmem_shake_register(kmem_shake_func_t sfunc
)
142 return set_shrinker(DEFAULT_SEEKS
, sfunc
);
146 kmem_shake_deregister(kmem_shaker_t shrinker
)
148 remove_shrinker(shrinker
);
152 kmem_shake_allow(unsigned int gfp_mask
)
154 return (gfp_mask
& __GFP_WAIT
);
157 #endif /* __XFS_SUPPORT_KMEM_H__ */