xref: /freebsd/sys/contrib/openzfs/config/kernel-shrink.m4 (revision b197d4b893974c9eb4d7b38704c6d5c486235d6f)
1dnl #
2dnl # 3.1 API change
3dnl # The super_block structure now stores a per-filesystem shrinker.
4dnl # This interface is preferable because it can be used to specifically
5dnl # target only the zfs filesystem for pruning.
6dnl #
7AC_DEFUN([ZFS_AC_KERNEL_SRC_SUPER_BLOCK_S_SHRINK], [
8	ZFS_LINUX_TEST_SRC([super_block_s_shrink], [
9		#include <linux/fs.h>
10
11		int shrink(struct shrinker *s, struct shrink_control *sc)
12		    { return 0; }
13
14		static const struct super_block
15		    sb __attribute__ ((unused)) = {
16			.s_shrink.seeks = DEFAULT_SEEKS,
17			.s_shrink.batch = 0,
18		};
19	],[])
20])
21
22AC_DEFUN([ZFS_AC_KERNEL_SUPER_BLOCK_S_SHRINK], [
23	AC_MSG_CHECKING([whether super_block has s_shrink])
24	ZFS_LINUX_TEST_RESULT([super_block_s_shrink], [
25		AC_MSG_RESULT(yes)
26	],[
27		ZFS_LINUX_TEST_ERROR([sb->s_shrink()])
28	])
29])
30
31dnl #
32dnl # 3.12 API change
33dnl # The nid member was added to struct shrink_control to support
34dnl # NUMA-aware shrinkers.
35dnl #
36AC_DEFUN([ZFS_AC_KERNEL_SRC_SHRINK_CONTROL_HAS_NID], [
37	ZFS_LINUX_TEST_SRC([shrink_control_nid], [
38		#include <linux/fs.h>
39	],[
40		struct shrink_control sc __attribute__ ((unused));
41		unsigned long scnidsize __attribute__ ((unused)) =
42		    sizeof(sc.nid);
43	])
44])
45
46AC_DEFUN([ZFS_AC_KERNEL_SHRINK_CONTROL_HAS_NID], [
47	AC_MSG_CHECKING([whether shrink_control has nid])
48	ZFS_LINUX_TEST_RESULT([shrink_control_nid], [
49		AC_MSG_RESULT(yes)
50		AC_DEFINE(SHRINK_CONTROL_HAS_NID, 1,
51		    [struct shrink_control has nid])
52	],[
53		AC_MSG_RESULT(no)
54	])
55])
56
57AC_DEFUN([ZFS_AC_KERNEL_SRC_REGISTER_SHRINKER_VARARG], [
58	ZFS_LINUX_TEST_SRC([register_shrinker_vararg], [
59		#include <linux/mm.h>
60		unsigned long shrinker_cb(struct shrinker *shrink,
61		    struct shrink_control *sc) { return 0; }
62	],[
63		struct shrinker cache_shrinker = {
64			.count_objects = shrinker_cb,
65			.scan_objects = shrinker_cb,
66			.seeks = DEFAULT_SEEKS,
67		};
68		register_shrinker(&cache_shrinker, "vararg-reg-shrink-test");
69	])
70])
71
72AC_DEFUN([ZFS_AC_KERNEL_SRC_SHRINKER_CALLBACK], [
73	ZFS_LINUX_TEST_SRC([shrinker_cb_shrink_control], [
74		#include <linux/mm.h>
75		int shrinker_cb(struct shrinker *shrink,
76		    struct shrink_control *sc) { return 0; }
77	],[
78		struct shrinker cache_shrinker = {
79			.shrink = shrinker_cb,
80			.seeks = DEFAULT_SEEKS,
81		};
82		register_shrinker(&cache_shrinker);
83	])
84
85	ZFS_LINUX_TEST_SRC([shrinker_cb_shrink_control_split], [
86		#include <linux/mm.h>
87		unsigned long shrinker_cb(struct shrinker *shrink,
88		    struct shrink_control *sc) { return 0; }
89	],[
90		struct shrinker cache_shrinker = {
91			.count_objects = shrinker_cb,
92			.scan_objects = shrinker_cb,
93			.seeks = DEFAULT_SEEKS,
94		};
95		register_shrinker(&cache_shrinker);
96	])
97])
98
99AC_DEFUN([ZFS_AC_KERNEL_SHRINKER_CALLBACK],[
100	dnl #
101	dnl # 6.0 API change
102	dnl # register_shrinker() becomes a var-arg function that takes
103	dnl # a printf-style format string as args > 0
104	dnl #
105	AC_MSG_CHECKING([whether new var-arg register_shrinker() exists])
106	ZFS_LINUX_TEST_RESULT([register_shrinker_vararg], [
107		AC_MSG_RESULT(yes)
108		AC_DEFINE(HAVE_REGISTER_SHRINKER_VARARG, 1,
109		    [register_shrinker is vararg])
110
111		dnl # We assume that the split shrinker callback exists if the
112		dnl # vararg register_shrinker() exists, because the latter is
113		dnl # a much more recent addition, and the macro test for the
114		dnl # var-arg version only works if the callback is split
115		AC_DEFINE(HAVE_SPLIT_SHRINKER_CALLBACK, 1,
116			[cs->count_objects exists])
117	],[
118		AC_MSG_RESULT(no)
119		dnl #
120		dnl # 3.0 - 3.11 API change
121		dnl # cs->shrink(struct shrinker *, struct shrink_control *sc)
122		dnl #
123		AC_MSG_CHECKING([whether new 2-argument shrinker exists])
124		ZFS_LINUX_TEST_RESULT([shrinker_cb_shrink_control], [
125			AC_MSG_RESULT(yes)
126			AC_DEFINE(HAVE_SINGLE_SHRINKER_CALLBACK, 1,
127				[new shrinker callback wants 2 args])
128		],[
129			AC_MSG_RESULT(no)
130
131			dnl #
132			dnl # 3.12 API change,
133			dnl # cs->shrink() is logically split in to
134			dnl # cs->count_objects() and cs->scan_objects()
135			dnl #
136			AC_MSG_CHECKING([if cs->count_objects callback exists])
137			ZFS_LINUX_TEST_RESULT(
138				[shrinker_cb_shrink_control_split],[
139					AC_MSG_RESULT(yes)
140					AC_DEFINE(HAVE_SPLIT_SHRINKER_CALLBACK, 1,
141						[cs->count_objects exists])
142			],[
143					ZFS_LINUX_TEST_ERROR([shrinker])
144			])
145		])
146	])
147])
148
149dnl #
150dnl # 2.6.39 API change,
151dnl # Shrinker adjust to use common shrink_control structure.
152dnl #
153AC_DEFUN([ZFS_AC_KERNEL_SRC_SHRINK_CONTROL_STRUCT], [
154	ZFS_LINUX_TEST_SRC([shrink_control_struct], [
155		#include <linux/mm.h>
156	],[
157		struct shrink_control sc __attribute__ ((unused));
158
159		sc.nr_to_scan = 0;
160		sc.gfp_mask = GFP_KERNEL;
161	])
162])
163
164AC_DEFUN([ZFS_AC_KERNEL_SHRINK_CONTROL_STRUCT], [
165	AC_MSG_CHECKING([whether struct shrink_control exists])
166	ZFS_LINUX_TEST_RESULT([shrink_control_struct], [
167		AC_MSG_RESULT(yes)
168		AC_DEFINE(HAVE_SHRINK_CONTROL_STRUCT, 1,
169		    [struct shrink_control exists])
170	],[
171		ZFS_LINUX_TEST_ERROR([shrink_control])
172	])
173])
174
175AC_DEFUN([ZFS_AC_KERNEL_SRC_SHRINKER], [
176	ZFS_AC_KERNEL_SRC_SUPER_BLOCK_S_SHRINK
177	ZFS_AC_KERNEL_SRC_SHRINK_CONTROL_HAS_NID
178	ZFS_AC_KERNEL_SRC_SHRINKER_CALLBACK
179	ZFS_AC_KERNEL_SRC_SHRINK_CONTROL_STRUCT
180	ZFS_AC_KERNEL_SRC_REGISTER_SHRINKER_VARARG
181])
182
183AC_DEFUN([ZFS_AC_KERNEL_SHRINKER], [
184	ZFS_AC_KERNEL_SUPER_BLOCK_S_SHRINK
185	ZFS_AC_KERNEL_SHRINK_CONTROL_HAS_NID
186	ZFS_AC_KERNEL_SHRINKER_CALLBACK
187	ZFS_AC_KERNEL_SHRINK_CONTROL_STRUCT
188])
189