summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorBrian Behlendorf <[email protected]>2011-03-23 15:45:55 -0700
committerBrian Behlendorf <[email protected]>2011-04-06 20:06:03 -0700
commit495bd532ab4aaef46b57094d59707bad91e6ec25 (patch)
tree16bd9d692bfe445673dd52c01c7b34ae665682cd /include
parent91cb1d91a4cf0dfa360f09747915699d0bef3d6f (diff)
Linux shrinker compat
The Linux shrinker has gone through three API changes since 2.6.22. Rather than force every caller to understand all three APIs this change consolidates the compatibility code in to the mm-compat.h header. The caller then can then use a single spl provided shrinker API which does the right thing for your kernel. SPL_SHRINKER_CALLBACK_PROTO(shrinker_callback, cb, nr_to_scan, gfp_mask); SPL_SHRINKER_DECLARE(shrinker_struct, shrinker_callback, seeks); spl_register_shrinker(&shrinker_struct); spl_unregister_shrinker(&&shrinker_struct); spl_exec_shrinker(&shrinker_struct, nr_to_scan, gfp_mask);
Diffstat (limited to 'include')
-rw-r--r--include/linux/mm_compat.h46
1 files changed, 46 insertions, 0 deletions
diff --git a/include/linux/mm_compat.h b/include/linux/mm_compat.h
index 5c5198b90..7e2f6b8a5 100644
--- a/include/linux/mm_compat.h
+++ b/include/linux/mm_compat.h
@@ -56,4 +56,50 @@ extern invalidate_inodes_t invalidate_inodes_fn;
#define invalidate_inodes(sb) invalidate_inodes_fn(sb)
#endif /* HAVE_INVALIDATE_INODES */
+#ifdef HAVE_SET_SHRINKER
+typedef struct spl_shrinker {
+ struct shrinker *shrinker;
+ shrinker_t fn;
+ int seeks;
+} spl_shrinker_t;
+
+static inline void
+spl_register_shrinker(spl_shrinker_t *ss)
+{
+ ss->shrinker = set_shrinker(ss->seeks, ss->fn);
+}
+
+static inline void
+spl_unregister_shrinker(spl_shrinker_t *ss)
+{
+ remove_shrinker(ss->shrinker);
+}
+
+# define SPL_SHRINKER_DECLARE(s, x, y) \
+ static spl_shrinker_t s = { .shrinker = NULL, .fn = x, .seeks = y }
+# define SPL_SHRINKER_CALLBACK_PROTO(fn, x, y, z) \
+ static int fn(int y, unsigned int z)
+# define spl_exec_shrinker(ss, nr, gfp) \
+ ((spl_shrinker_t *)ss)->fn(nr, gfp)
+
+#else /* HAVE_SET_SHRINKER */
+
+# define spl_register_shrinker(x) register_shrinker(x)
+# define spl_unregister_shrinker(x) unregister_shrinker(x)
+# define SPL_SHRINKER_DECLARE(s, x, y) \
+ static struct shrinker s = { .shrink = x, .seeks = y }
+
+# ifdef HAVE_3ARGS_SHRINKER_CALLBACK
+# define SPL_SHRINKER_CALLBACK_PROTO(fn, x, y, z) \
+ static int fn(struct shrinker *x, int y, unsigned int z)
+# define spl_exec_shrinker(ss, nr, gfp) \
+ ((struct shrinker *)ss)->shrink(NULL, nr, gfp)
+# else /* HAVE_3ARGS_SHRINKER_CALLBACK */
+# define SPL_SHRINKER_CALLBACK_PROTO(fn, x, y, z) \
+ static int fn(int y, unsigned int z)
+# define spl_exec_shrinker(ss, nr, gfp) \
+ ((struct shrinker *)ss)->shrink(nr, gfp)
+# endif /* HAVE_3ARGS_SHRINKER_CALLBACK */
+#endif /* HAVE_SET_SHRINKER */
+
#endif /* SPL_MM_COMPAT_H */