]> git.proxmox.com Git - mirror_spl.git/blame - include/linux/mm_compat.h
Remove spl_invalidate_inodes()
[mirror_spl.git] / include / linux / mm_compat.h
CommitLineData
716154c5
BB
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://github.com/behlendorf/spl/>.
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
baf2979e
BB
25#ifndef _SPL_MM_COMPAT_H
26#define _SPL_MM_COMPAT_H
27
28#include <linux/mm.h>
914b0631 29#include <linux/fs.h>
baf2979e
BB
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
a55bcaad
BB
47#if !defined(HAVE_SHRINK_CONTROL_STRUCT)
48struct shrink_control {
49 gfp_t gfp_mask;
50 unsigned long nr_to_scan;
51};
52#endif /* HAVE_SHRINK_CONTROL_STRUCT */
53
e76f4bf1
BB
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
a55bcaad
BB
61# if defined(HAVE_SHRINK_CONTROL_STRUCT)
62typedef int (*shrink_dcache_memory_t)(struct shrinker *,
63 struct shrink_control *);
64extern 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 }; \
fe71c0e5
BB
68 int __ret__ = 0; \
69 \
70 if (shrink_dcache_memory_fn) \
71 __ret__ = shrink_dcache_memory_fn(NULL, &sc); \
72 \
73 __ret__; \
a55bcaad
BB
74})
75# elif defined(HAVE_3ARGS_SHRINKER_CALLBACK)
e76f4bf1
BB
76typedef int (*shrink_dcache_memory_t)(struct shrinker *, int, gfp_t);
77extern shrink_dcache_memory_t shrink_dcache_memory_fn;
fe71c0e5
BB
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})
e76f4bf1
BB
87# else
88typedef int (*shrink_dcache_memory_t)(int, gfp_t);
89extern shrink_dcache_memory_t shrink_dcache_memory_fn;
fe71c0e5
BB
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})
e76f4bf1
BB
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
a55bcaad
BB
109# if defined(HAVE_SHRINK_CONTROL_STRUCT)
110typedef int (*shrink_icache_memory_t)(struct shrinker *,
111 struct shrink_control *);
112extern 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 }; \
fe71c0e5
BB
116 int __ret__ = 0; \
117 \
118 if (shrink_icache_memory_fn) \
119 __ret__ = shrink_icache_memory_fn(NULL, &sc); \
120 \
121 __ret__; \
a55bcaad
BB
122})
123# elif defined(HAVE_3ARGS_SHRINKER_CALLBACK)
e76f4bf1
BB
124typedef int (*shrink_icache_memory_t)(struct shrinker *, int, gfp_t);
125extern shrink_icache_memory_t shrink_icache_memory_fn;
fe71c0e5
BB
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})
e76f4bf1
BB
135# else
136typedef int (*shrink_icache_memory_t)(int, gfp_t);
137extern shrink_icache_memory_t shrink_icache_memory_fn;
fe71c0e5
BB
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})
e76f4bf1
BB
147# endif /* HAVE_3ARGS_SHRINKER_CALLBACK */
148#endif /* HAVE_SHRINK_ICACHE_MEMORY */
149
a55bcaad
BB
150/*
151 * Linux 2.6. - 2.6. Shrinker API Compatibility.
152 */
495bd532
BB
153#ifdef HAVE_SET_SHRINKER
154typedef struct spl_shrinker {
155 struct shrinker *shrinker;
156 shrinker_t fn;
157 int seeks;
158} spl_shrinker_t;
159
160static inline void
161spl_register_shrinker(spl_shrinker_t *ss)
162{
163 ss->shrinker = set_shrinker(ss->seeks, ss->fn);
164}
165
166static inline void
167spl_unregister_shrinker(spl_shrinker_t *ss)
168{
169 remove_shrinker(ss->shrinker);
170}
171
a55bcaad
BB
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) \
182static int \
183fn(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}
495bd532 192
a55bcaad 193#else
495bd532
BB
194
195# define spl_register_shrinker(x) register_shrinker(x)
196# define spl_unregister_shrinker(x) unregister_shrinker(x)
a55bcaad
BB
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) \
210static int \
211fn(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) \
222static int \
223fn(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) \
240static int \
241fn(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
495bd532
BB
252#endif /* HAVE_SET_SHRINKER */
253
baf2979e 254#endif /* SPL_MM_COMPAT_H */