]> git.proxmox.com Git - mirror_spl.git/blob - include/linux/mm_compat.h
Merge branch 'build-system'
[mirror_spl.git] / include / linux / mm_compat.h
1 /*****************************************************************************\
2 * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
3 * Copyright (C) 2007 The Regents of the University of California.
4 * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
5 * Written by Brian Behlendorf <behlendorf1@llnl.gov>.
6 * UCRL-CODE-235197
7 *
8 * This file is part of the SPL, Solaris Porting Layer.
9 * For details, see <http://zfsonlinux.org/>.
10 *
11 * The SPL is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
15 *
16 * The SPL is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 * for more details.
20 *
21 * You should have received a copy of the GNU General Public License along
22 * with the SPL. If not, see <http://www.gnu.org/licenses/>.
23 \*****************************************************************************/
24
25 #ifndef _SPL_MM_COMPAT_H
26 #define _SPL_MM_COMPAT_H
27
28 #include <linux/mm.h>
29 #include <linux/fs.h>
30
31 /*
32 * Linux 2.6.31 API Change.
33 * Individual pages_{min,low,high} moved in to watermark array.
34 */
35 #ifndef min_wmark_pages
36 #define min_wmark_pages(z) (z->pages_min)
37 #endif
38
39 #ifndef low_wmark_pages
40 #define low_wmark_pages(z) (z->pages_low)
41 #endif
42
43 #ifndef high_wmark_pages
44 #define high_wmark_pages(z) (z->pages_high)
45 #endif
46
47 #if !defined(HAVE_SHRINK_CONTROL_STRUCT)
48 struct shrink_control {
49 gfp_t gfp_mask;
50 unsigned long nr_to_scan;
51 };
52 #endif /* HAVE_SHRINK_CONTROL_STRUCT */
53
54 /*
55 * 2.6.xx API compat,
56 * There currently exists no exposed API to partially shrink the dcache.
57 * The expected mechanism to shrink the cache is a registered shrinker
58 * which is called during memory pressure.
59 */
60 #ifndef HAVE_SHRINK_DCACHE_MEMORY
61 # if defined(HAVE_SHRINK_CONTROL_STRUCT)
62 typedef int (*shrink_dcache_memory_t)(struct shrinker *,
63 struct shrink_control *);
64 extern shrink_dcache_memory_t shrink_dcache_memory_fn;
65 # define shrink_dcache_memory(nr, gfp) \
66 ({ \
67 struct shrink_control sc = { .nr_to_scan = nr, .gfp_mask = gfp }; \
68 int __ret__ = 0; \
69 \
70 if (shrink_dcache_memory_fn) \
71 __ret__ = shrink_dcache_memory_fn(NULL, &sc); \
72 \
73 __ret__; \
74 })
75 # elif defined(HAVE_3ARGS_SHRINKER_CALLBACK)
76 typedef int (*shrink_dcache_memory_t)(struct shrinker *, int, gfp_t);
77 extern shrink_dcache_memory_t shrink_dcache_memory_fn;
78 # define shrink_dcache_memory(nr, gfp) \
79 ({ \
80 int __ret__ = 0; \
81 \
82 if (shrink_dcache_memory_fn) \
83 __ret__ = shrink_dcache_memory_fn(NULL, nr, gfp); \
84 \
85 __ret__; \
86 })
87 # else
88 typedef int (*shrink_dcache_memory_t)(int, gfp_t);
89 extern shrink_dcache_memory_t shrink_dcache_memory_fn;
90 # define shrink_dcache_memory(nr, gfp) \
91 ({ \
92 int __ret__ = 0; \
93 \
94 if (shrink_dcache_memory_fn) \
95 __ret__ = shrink_dcache_memory_fn(nr, gfp); \
96 \
97 __ret__; \
98 })
99 # endif /* HAVE_3ARGS_SHRINKER_CALLBACK */
100 #endif /* HAVE_SHRINK_DCACHE_MEMORY */
101
102 /*
103 * 2.6.xx API compat,
104 * There currently exists no exposed API to partially shrink the icache.
105 * The expected mechanism to shrink the cache is a registered shrinker
106 * which is called during memory pressure.
107 */
108 #ifndef HAVE_SHRINK_ICACHE_MEMORY
109 # if defined(HAVE_SHRINK_CONTROL_STRUCT)
110 typedef int (*shrink_icache_memory_t)(struct shrinker *,
111 struct shrink_control *);
112 extern shrink_icache_memory_t shrink_icache_memory_fn;
113 # define shrink_icache_memory(nr, gfp) \
114 ({ \
115 struct shrink_control sc = { .nr_to_scan = nr, .gfp_mask = gfp }; \
116 int __ret__ = 0; \
117 \
118 if (shrink_icache_memory_fn) \
119 __ret__ = shrink_icache_memory_fn(NULL, &sc); \
120 \
121 __ret__; \
122 })
123 # elif defined(HAVE_3ARGS_SHRINKER_CALLBACK)
124 typedef int (*shrink_icache_memory_t)(struct shrinker *, int, gfp_t);
125 extern shrink_icache_memory_t shrink_icache_memory_fn;
126 # define shrink_icache_memory(nr, gfp) \
127 ({ \
128 int __ret__ = 0; \
129 \
130 if (shrink_icache_memory_fn) \
131 __ret__ = shrink_icache_memory_fn(NULL, nr, gfp); \
132 \
133 __ret__; \
134 })
135 # else
136 typedef int (*shrink_icache_memory_t)(int, gfp_t);
137 extern shrink_icache_memory_t shrink_icache_memory_fn;
138 # define shrink_icache_memory(nr, gfp) \
139 ({ \
140 int __ret__ = 0; \
141 \
142 if (shrink_icache_memory_fn) \
143 __ret__ = shrink_icache_memory_fn(nr, gfp); \
144 \
145 __ret__; \
146 })
147 # endif /* HAVE_3ARGS_SHRINKER_CALLBACK */
148 #endif /* HAVE_SHRINK_ICACHE_MEMORY */
149
150 /*
151 * Linux 2.6. - 2.6. Shrinker API Compatibility.
152 */
153 #ifdef HAVE_SET_SHRINKER
154 typedef struct spl_shrinker {
155 struct shrinker *shrinker;
156 shrinker_t fn;
157 int seeks;
158 } spl_shrinker_t;
159
160 static inline void
161 spl_register_shrinker(spl_shrinker_t *ss)
162 {
163 ss->shrinker = set_shrinker(ss->seeks, ss->fn);
164 }
165
166 static inline void
167 spl_unregister_shrinker(spl_shrinker_t *ss)
168 {
169 remove_shrinker(ss->shrinker);
170 }
171
172 # define SPL_SHRINKER_DECLARE(s, x, y) \
173 static spl_shrinker_t s = { \
174 .shrinker = NULL, \
175 .fn = x, \
176 .seeks = y \
177 }
178
179 # define SPL_SHRINKER_CALLBACK_FWD_DECLARE(fn) \
180 static int fn(int, unsigned int)
181 # define SPL_SHRINKER_CALLBACK_WRAPPER(fn) \
182 static int \
183 fn(int nr_to_scan, unsigned int gfp_mask) \
184 { \
185 struct shrink_control sc; \
186 \
187 sc.nr_to_scan = nr_to_scan; \
188 sc.gfp_mask = gfp_mask; \
189 \
190 return __ ## fn(NULL, &sc); \
191 }
192
193 #else
194
195 # define spl_register_shrinker(x) register_shrinker(x)
196 # define spl_unregister_shrinker(x) unregister_shrinker(x)
197 # define SPL_SHRINKER_DECLARE(s, x, y) \
198 static struct shrinker s = { \
199 .shrink = x, \
200 .seeks = y \
201 }
202
203 /*
204 * Linux 2.6. - 2.6. Shrinker API Compatibility.
205 */
206 # if defined(HAVE_SHRINK_CONTROL_STRUCT)
207 # define SPL_SHRINKER_CALLBACK_FWD_DECLARE(fn) \
208 static int fn(struct shrinker *, struct shrink_control *)
209 # define SPL_SHRINKER_CALLBACK_WRAPPER(fn) \
210 static int \
211 fn(struct shrinker *shrink, struct shrink_control *sc) { \
212 return __ ## fn(shrink, sc); \
213 }
214
215 /*
216 * Linux 2.6. - 2.6. Shrinker API Compatibility.
217 */
218 # elif defined(HAVE_3ARGS_SHRINKER_CALLBACK)
219 # define SPL_SHRINKER_CALLBACK_FWD_DECLARE(fn) \
220 static int fn(struct shrinker *, int, unsigned int)
221 # define SPL_SHRINKER_CALLBACK_WRAPPER(fn) \
222 static int \
223 fn(struct shrinker *shrink, int nr_to_scan, unsigned int gfp_mask) \
224 { \
225 struct shrink_control sc; \
226 \
227 sc.nr_to_scan = nr_to_scan; \
228 sc.gfp_mask = gfp_mask; \
229 \
230 return __ ## fn(shrink, &sc); \
231 }
232
233 /*
234 * Linux 2.6. - 2.6. Shrinker API Compatibility.
235 */
236 # else
237 # define SPL_SHRINKER_CALLBACK_FWD_DECLARE(fn) \
238 static int fn(int, unsigned int)
239 # define SPL_SHRINKER_CALLBACK_WRAPPER(fn) \
240 static int \
241 fn(int nr_to_scan, unsigned int gfp_mask) \
242 { \
243 struct shrink_control sc; \
244 \
245 sc.nr_to_scan = nr_to_scan; \
246 sc.gfp_mask = gfp_mask; \
247 \
248 return __ ## fn(NULL, &sc); \
249 }
250
251 # endif
252 #endif /* HAVE_SET_SHRINKER */
253
254 #endif /* SPL_MM_COMPAT_H */