]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * Copyright (c) 2000-2004 Silicon Graphics, Inc. All Rights Reserved. | |
3 | * | |
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. | |
7 | * | |
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. | |
11 | * | |
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. | |
18 | * | |
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. | |
22 | * | |
23 | * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, | |
24 | * Mountain View, CA 94043, or: | |
25 | * | |
26 | * http://www.sgi.com | |
27 | * | |
28 | * For further information regarding this notice, see: | |
29 | * | |
30 | * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/ | |
31 | */ | |
32 | #ifndef __XFS_SUPPORT_KMEM_H__ | |
33 | #define __XFS_SUPPORT_KMEM_H__ | |
34 | ||
35 | #include <linux/slab.h> | |
36 | #include <linux/sched.h> | |
37 | #include <linux/mm.h> | |
38 | ||
39 | /* | |
40 | * memory management routines | |
41 | */ | |
42 | #define KM_SLEEP 0x0001 | |
43 | #define KM_NOSLEEP 0x0002 | |
44 | #define KM_NOFS 0x0004 | |
45 | #define KM_MAYFAIL 0x0008 | |
46 | ||
47 | #define kmem_zone kmem_cache_s | |
48 | #define kmem_zone_t kmem_cache_t | |
49 | ||
50 | typedef unsigned long xfs_pflags_t; | |
51 | ||
52 | #define PFLAGS_TEST_NOIO() (current->flags & PF_NOIO) | |
53 | #define PFLAGS_TEST_FSTRANS() (current->flags & PF_FSTRANS) | |
54 | ||
55 | #define PFLAGS_SET_NOIO() do { \ | |
56 | current->flags |= PF_NOIO; \ | |
57 | } while (0) | |
58 | ||
59 | #define PFLAGS_CLEAR_NOIO() do { \ | |
60 | current->flags &= ~PF_NOIO; \ | |
61 | } while (0) | |
62 | ||
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; \ | |
67 | } while (0) | |
68 | ||
69 | #define PFLAGS_CLEAR_FSTRANS(STATEP) do { \ | |
70 | *(STATEP) = current->flags; \ | |
71 | current->flags &= ~PF_FSTRANS; \ | |
72 | } while (0) | |
73 | ||
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)); \ | |
78 | } while (0) | |
79 | ||
80 | #define PFLAGS_DUP(OSTATEP, NSTATEP) do { \ | |
81 | *(NSTATEP) = *(OSTATEP); \ | |
82 | } while (0) | |
83 | ||
84 | static __inline unsigned int kmem_flags_convert(int flags) | |
85 | { | |
86 | int lflags = __GFP_NOWARN; /* we'll report problems, if need be */ | |
87 | ||
88 | #ifdef DEBUG | |
89 | if (unlikely(flags & ~(KM_SLEEP|KM_NOSLEEP|KM_NOFS|KM_MAYFAIL))) { | |
90 | printk(KERN_WARNING | |
91 | "XFS: memory allocation with wrong flags (%x)\n", flags); | |
92 | BUG(); | |
93 | } | |
94 | #endif | |
95 | ||
96 | if (flags & KM_NOSLEEP) { | |
97 | lflags |= GFP_ATOMIC; | |
98 | } else { | |
99 | lflags |= GFP_KERNEL; | |
100 | ||
101 | /* avoid recusive callbacks to filesystem during transactions */ | |
102 | if (PFLAGS_TEST_FSTRANS() || (flags & KM_NOFS)) | |
103 | lflags &= ~__GFP_FS; | |
104 | } | |
105 | ||
106 | return lflags; | |
107 | } | |
108 | ||
109 | static __inline kmem_zone_t * | |
110 | kmem_zone_init(int size, char *zone_name) | |
111 | { | |
112 | return kmem_cache_create(zone_name, size, 0, 0, NULL, NULL); | |
113 | } | |
114 | ||
115 | static __inline void | |
116 | kmem_zone_free(kmem_zone_t *zone, void *ptr) | |
117 | { | |
118 | kmem_cache_free(zone, ptr); | |
119 | } | |
120 | ||
121 | static __inline void | |
122 | kmem_zone_destroy(kmem_zone_t *zone) | |
123 | { | |
124 | if (zone && kmem_cache_destroy(zone)) | |
125 | BUG(); | |
126 | } | |
127 | ||
128 | extern void *kmem_zone_zalloc(kmem_zone_t *, int); | |
129 | extern void *kmem_zone_alloc(kmem_zone_t *, int); | |
130 | ||
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); | |
135 | ||
136 | typedef struct shrinker *kmem_shaker_t; | |
137 | typedef int (*kmem_shake_func_t)(int, unsigned int); | |
138 | ||
139 | static __inline kmem_shaker_t | |
140 | kmem_shake_register(kmem_shake_func_t sfunc) | |
141 | { | |
142 | return set_shrinker(DEFAULT_SEEKS, sfunc); | |
143 | } | |
144 | ||
145 | static __inline void | |
146 | kmem_shake_deregister(kmem_shaker_t shrinker) | |
147 | { | |
148 | remove_shrinker(shrinker); | |
149 | } | |
150 | ||
151 | static __inline int | |
152 | kmem_shake_allow(unsigned int gfp_mask) | |
153 | { | |
154 | return (gfp_mask & __GFP_WAIT); | |
155 | } | |
156 | ||
157 | #endif /* __XFS_SUPPORT_KMEM_H__ */ |