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>.
8 * This file is part of the SPL, Solaris Porting Layer.
9 * For details, see <http://github.com/behlendorf/spl/>.
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.
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
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 \*****************************************************************************/
25 #ifndef _SPL_MM_COMPAT_H
26 #define _SPL_MM_COMPAT_H
32 * Linux 2.6.31 API Change.
33 * Individual pages_{min,low,high} moved in to watermark array.
35 #ifndef min_wmark_pages
36 #define min_wmark_pages(z) (z->pages_min)
39 #ifndef low_wmark_pages
40 #define low_wmark_pages(z) (z->pages_low)
43 #ifndef high_wmark_pages
44 #define high_wmark_pages(z) (z->pages_high)
47 #if !defined(HAVE_SHRINK_CONTROL_STRUCT)
48 struct shrink_control
{
50 unsigned long nr_to_scan
;
52 #endif /* HAVE_SHRINK_CONTROL_STRUCT */
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.
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) \
67 struct shrink_control sc = { .nr_to_scan = nr, .gfp_mask = gfp }; \
70 if (shrink_dcache_memory_fn) \
71 __ret__ = shrink_dcache_memory_fn(NULL, &sc); \
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) \
82 if (shrink_dcache_memory_fn) \
83 __ret__ = shrink_dcache_memory_fn(NULL, nr, gfp); \
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) \
94 if (shrink_dcache_memory_fn) \
95 __ret__ = shrink_dcache_memory_fn(nr, gfp); \
99 # endif /* HAVE_3ARGS_SHRINKER_CALLBACK */
100 #endif /* HAVE_SHRINK_DCACHE_MEMORY */
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.
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) \
115 struct shrink_control sc = { .nr_to_scan = nr, .gfp_mask = gfp }; \
118 if (shrink_icache_memory_fn) \
119 __ret__ = shrink_icache_memory_fn(NULL, &sc); \
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) \
130 if (shrink_icache_memory_fn) \
131 __ret__ = shrink_icache_memory_fn(NULL, nr, gfp); \
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) \
142 if (shrink_icache_memory_fn) \
143 __ret__ = shrink_icache_memory_fn(nr, gfp); \
147 # endif /* HAVE_3ARGS_SHRINKER_CALLBACK */
148 #endif /* HAVE_SHRINK_ICACHE_MEMORY */
151 * Linux 2.6. - 2.6. Shrinker API Compatibility.
153 #ifdef HAVE_SET_SHRINKER
154 typedef struct spl_shrinker
{
155 struct shrinker
*shrinker
;
161 spl_register_shrinker(spl_shrinker_t
*ss
)
163 ss
->shrinker
= set_shrinker(ss
->seeks
, ss
->fn
);
167 spl_unregister_shrinker(spl_shrinker_t
*ss
)
169 remove_shrinker(ss
->shrinker
);
172 # define SPL_SHRINKER_DECLARE(s, x, y) \
173 static spl_shrinker_t s = { \
179 # define SPL_SHRINKER_CALLBACK_FWD_DECLARE(fn) \
180 static int fn(int, unsigned int)
181 # define SPL_SHRINKER_CALLBACK_WRAPPER(fn) \
183 fn(int nr_to_scan, unsigned int gfp_mask) \
185 struct shrink_control sc; \
187 sc.nr_to_scan = nr_to_scan; \
188 sc.gfp_mask = gfp_mask; \
190 return __ ## fn(NULL, &sc); \
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 = { \
204 * Linux 2.6. - 2.6. Shrinker API Compatibility.
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) \
211 fn(struct shrinker *shrink, struct shrink_control *sc) { \
212 return __ ## fn(shrink, sc); \
216 * Linux 2.6. - 2.6. Shrinker API Compatibility.
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) \
223 fn(struct shrinker *shrink, int nr_to_scan, unsigned int gfp_mask) \
225 struct shrink_control sc; \
227 sc.nr_to_scan = nr_to_scan; \
228 sc.gfp_mask = gfp_mask; \
230 return __ ## fn(shrink, &sc); \
234 * Linux 2.6. - 2.6. Shrinker API Compatibility.
237 # define SPL_SHRINKER_CALLBACK_FWD_DECLARE(fn) \
238 static int fn(int, unsigned int)
239 # define SPL_SHRINKER_CALLBACK_WRAPPER(fn) \
241 fn(int nr_to_scan, unsigned int gfp_mask) \
243 struct shrink_control sc; \
245 sc.nr_to_scan = nr_to_scan; \
246 sc.gfp_mask = gfp_mask; \
248 return __ ## fn(NULL, &sc); \
252 #endif /* HAVE_SET_SHRINKER */
254 #endif /* SPL_MM_COMPAT_H */