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>
38 * memory management routines
40 #define KM_SLEEP 0x0001
41 #define KM_NOSLEEP 0x0002
42 #define KM_NOFS 0x0004
43 #define KM_MAYFAIL 0x0008
45 #define kmem_zone kmem_cache_s
46 #define kmem_zone_t kmem_cache_t
48 typedef unsigned long xfs_pflags_t;
50 #define PFLAGS_TEST_NOIO() (current->flags & PF_NOIO)
51 #define PFLAGS_TEST_FSTRANS() (current->flags & PF_FSTRANS)
53 #define PFLAGS_SET_NOIO() do { \
54 current->flags |= PF_NOIO; \
57 #define PFLAGS_CLEAR_NOIO() do { \
58 current->flags &= ~PF_NOIO; \
61 /* these could be nested, so we save state */
62 #define PFLAGS_SET_FSTRANS(STATEP) do { \
63 *(STATEP) = current->flags; \
64 current->flags |= PF_FSTRANS; \
67 #define PFLAGS_CLEAR_FSTRANS(STATEP) do { \
68 *(STATEP) = current->flags; \
69 current->flags &= ~PF_FSTRANS; \
72 /* Restore the PF_FSTRANS state to what was saved in STATEP */
73 #define PFLAGS_RESTORE_FSTRANS(STATEP) do { \
74 current->flags = ((current->flags & ~PF_FSTRANS) | \
75 (*(STATEP) & PF_FSTRANS)); \
78 #define PFLAGS_DUP(OSTATEP, NSTATEP) do { \
79 *(NSTATEP) = *(OSTATEP); \
82 static __inline unsigned int kmem_flags_convert(int flags)
87 if (unlikely(flags & ~(KM_SLEEP|KM_NOSLEEP|KM_NOFS|KM_MAYFAIL))) {
89 "XFS: memory allocation with wrong flags (%x)\n", flags);
94 if (flags & KM_NOSLEEP) {
99 /* avoid recusive callbacks to filesystem during transactions */
100 if (PFLAGS_TEST_FSTRANS() || (flags & KM_NOFS))
107 static __inline kmem_zone_t *
108 kmem_zone_init(int size, char *zone_name)
110 return kmem_cache_create(zone_name, size, 0, 0, NULL, NULL);
114 kmem_zone_free(kmem_zone_t *zone, void *ptr)
116 kmem_cache_free(zone, ptr);
120 kmem_zone_destroy(kmem_zone_t *zone)
122 if (zone && kmem_cache_destroy(zone))
127 kmem_zone_shrink(kmem_zone_t *zone)
129 return kmem_cache_shrink(zone);
132 extern void *kmem_zone_zalloc(kmem_zone_t *, int);
133 extern void *kmem_zone_alloc(kmem_zone_t *, int);
135 extern void *kmem_alloc(size_t, int);
136 extern void *kmem_realloc(void *, size_t, size_t, int);
137 extern void *kmem_zalloc(size_t, int);
138 extern void kmem_free(void *, size_t);
140 typedef void *kmem_shaker_t;
141 typedef int (*kmem_shake_func_t)(int, unsigned int);
143 extern kmem_shaker_t kmem_shake_register(kmem_shake_func_t);
144 extern void kmem_shake_deregister(kmem_shaker_t);
147 kmem_shake_allow(unsigned int gfp_mask)
149 return (gfp_mask & __GFP_WAIT);
152 #endif /* __XFS_SUPPORT_KMEM_H__ */