xref: /freebsd/sys/contrib/openzfs/config/kernel-shrink.m4 (revision fe75646a0234a261c0013bf1840fdac4acaf0cec)
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
22dnl #
23dnl # 6.7 API change
24dnl # s_shrink is now a pointer.
25dnl #
26AC_DEFUN([ZFS_AC_KERNEL_SRC_SUPER_BLOCK_S_SHRINK_PTR], [
27	ZFS_LINUX_TEST_SRC([super_block_s_shrink_ptr], [
28		#include <linux/fs.h>
29		unsigned long shrinker_cb(struct shrinker *shrink,
30		    struct shrink_control *sc) { return 0; }
31		static struct shrinker shrinker = {
32			.count_objects = shrinker_cb,
33			.scan_objects = shrinker_cb,
34			.seeks = DEFAULT_SEEKS,
35		};
36		static const struct super_block
37		    sb __attribute__ ((unused)) = {
38			.s_shrink = &shrinker,
39		};
40	],[])
41])
42
43AC_DEFUN([ZFS_AC_KERNEL_SUPER_BLOCK_S_SHRINK], [
44	AC_MSG_CHECKING([whether super_block has s_shrink])
45	ZFS_LINUX_TEST_RESULT([super_block_s_shrink], [
46		AC_MSG_RESULT(yes)
47		AC_DEFINE(HAVE_SUPER_BLOCK_S_SHRINK, 1,
48			[have super_block s_shrink])
49	],[
50		AC_MSG_RESULT(no)
51		AC_MSG_CHECKING([whether super_block has s_shrink pointer])
52		ZFS_LINUX_TEST_RESULT([super_block_s_shrink_ptr], [
53			AC_MSG_RESULT(yes)
54			AC_DEFINE(HAVE_SUPER_BLOCK_S_SHRINK_PTR, 1,
55				[have super_block s_shrink pointer])
56		],[
57			AC_MSG_RESULT(no)
58			ZFS_LINUX_TEST_ERROR([sb->s_shrink()])
59		])
60	])
61])
62
63dnl #
64dnl # 3.12 API change
65dnl # The nid member was added to struct shrink_control to support
66dnl # NUMA-aware shrinkers.
67dnl #
68AC_DEFUN([ZFS_AC_KERNEL_SRC_SHRINK_CONTROL_HAS_NID], [
69	ZFS_LINUX_TEST_SRC([shrink_control_nid], [
70		#include <linux/fs.h>
71	],[
72		struct shrink_control sc __attribute__ ((unused));
73		unsigned long scnidsize __attribute__ ((unused)) =
74		    sizeof(sc.nid);
75	])
76])
77
78AC_DEFUN([ZFS_AC_KERNEL_SHRINK_CONTROL_HAS_NID], [
79	AC_MSG_CHECKING([whether shrink_control has nid])
80	ZFS_LINUX_TEST_RESULT([shrink_control_nid], [
81		AC_MSG_RESULT(yes)
82		AC_DEFINE(SHRINK_CONTROL_HAS_NID, 1,
83		    [struct shrink_control has nid])
84	],[
85		AC_MSG_RESULT(no)
86	])
87])
88
89AC_DEFUN([ZFS_AC_KERNEL_SRC_REGISTER_SHRINKER_VARARG], [
90	ZFS_LINUX_TEST_SRC([register_shrinker_vararg], [
91		#include <linux/mm.h>
92		unsigned long shrinker_cb(struct shrinker *shrink,
93		    struct shrink_control *sc) { return 0; }
94	],[
95		struct shrinker cache_shrinker = {
96			.count_objects = shrinker_cb,
97			.scan_objects = shrinker_cb,
98			.seeks = DEFAULT_SEEKS,
99		};
100		register_shrinker(&cache_shrinker, "vararg-reg-shrink-test");
101	])
102])
103
104AC_DEFUN([ZFS_AC_KERNEL_SRC_SHRINKER_CALLBACK], [
105	ZFS_LINUX_TEST_SRC([shrinker_cb_shrink_control], [
106		#include <linux/mm.h>
107		int shrinker_cb(struct shrinker *shrink,
108		    struct shrink_control *sc) { return 0; }
109	],[
110		struct shrinker cache_shrinker = {
111			.shrink = shrinker_cb,
112			.seeks = DEFAULT_SEEKS,
113		};
114		register_shrinker(&cache_shrinker);
115	])
116
117	ZFS_LINUX_TEST_SRC([shrinker_cb_shrink_control_split], [
118		#include <linux/mm.h>
119		unsigned long shrinker_cb(struct shrinker *shrink,
120		    struct shrink_control *sc) { return 0; }
121	],[
122		struct shrinker cache_shrinker = {
123			.count_objects = shrinker_cb,
124			.scan_objects = shrinker_cb,
125			.seeks = DEFAULT_SEEKS,
126		};
127		register_shrinker(&cache_shrinker);
128	])
129])
130
131dnl #
132dnl # 6.7 API change
133dnl # register_shrinker has been replaced by shrinker_register.
134dnl #
135AC_DEFUN([ZFS_AC_KERNEL_SRC_SHRINKER_REGISTER], [
136	ZFS_LINUX_TEST_SRC([shrinker_register], [
137		#include <linux/shrinker.h>
138		unsigned long shrinker_cb(struct shrinker *shrink,
139		    struct shrink_control *sc) { return 0; }
140	],[
141		struct shrinker cache_shrinker = {
142			.count_objects = shrinker_cb,
143			.scan_objects = shrinker_cb,
144			.seeks = DEFAULT_SEEKS,
145		};
146		shrinker_register(&cache_shrinker);
147	])
148])
149
150AC_DEFUN([ZFS_AC_KERNEL_SHRINKER_CALLBACK],[
151	dnl #
152	dnl # 6.0 API change
153	dnl # register_shrinker() becomes a var-arg function that takes
154	dnl # a printf-style format string as args > 0
155	dnl #
156	AC_MSG_CHECKING([whether new var-arg register_shrinker() exists])
157	ZFS_LINUX_TEST_RESULT([register_shrinker_vararg], [
158		AC_MSG_RESULT(yes)
159		AC_DEFINE(HAVE_REGISTER_SHRINKER_VARARG, 1,
160		    [register_shrinker is vararg])
161
162		dnl # We assume that the split shrinker callback exists if the
163		dnl # vararg register_shrinker() exists, because the latter is
164		dnl # a much more recent addition, and the macro test for the
165		dnl # var-arg version only works if the callback is split
166		AC_DEFINE(HAVE_SPLIT_SHRINKER_CALLBACK, 1,
167			[cs->count_objects exists])
168	],[
169		AC_MSG_RESULT(no)
170		dnl #
171		dnl # 3.0 - 3.11 API change
172		dnl # cs->shrink(struct shrinker *, struct shrink_control *sc)
173		dnl #
174		AC_MSG_CHECKING([whether new 2-argument shrinker exists])
175		ZFS_LINUX_TEST_RESULT([shrinker_cb_shrink_control], [
176			AC_MSG_RESULT(yes)
177			AC_DEFINE(HAVE_SINGLE_SHRINKER_CALLBACK, 1,
178				[new shrinker callback wants 2 args])
179		],[
180			AC_MSG_RESULT(no)
181
182			dnl #
183			dnl # 3.12 API change,
184			dnl # cs->shrink() is logically split in to
185			dnl # cs->count_objects() and cs->scan_objects()
186			dnl #
187			AC_MSG_CHECKING(
188			    [whether cs->count_objects callback exists])
189			ZFS_LINUX_TEST_RESULT(
190			    [shrinker_cb_shrink_control_split],[
191				AC_MSG_RESULT(yes)
192				AC_DEFINE(HAVE_SPLIT_SHRINKER_CALLBACK, 1,
193				    [cs->count_objects exists])
194			],[
195				AC_MSG_RESULT(no)
196
197				AC_MSG_CHECKING(
198				    [whether shrinker_register exists])
199				ZFS_LINUX_TEST_RESULT([shrinker_register], [
200					AC_MSG_RESULT(yes)
201					AC_DEFINE(HAVE_SHRINKER_REGISTER, 1,
202					    [shrinker_register exists])
203
204					dnl # We assume that the split shrinker
205					dnl # callback exists if
206					dnl # shrinker_register() exists,
207					dnl # because the latter is a much more
208					dnl # recent addition, and the macro
209					dnl # test for shrinker_register() only
210					dnl # works if the callback is split
211					AC_DEFINE(HAVE_SPLIT_SHRINKER_CALLBACK,
212					    1, [cs->count_objects exists])
213				],[
214					AC_MSG_RESULT(no)
215					ZFS_LINUX_TEST_ERROR([shrinker])
216				])
217			])
218		])
219	])
220])
221
222dnl #
223dnl # 2.6.39 API change,
224dnl # Shrinker adjust to use common shrink_control structure.
225dnl #
226AC_DEFUN([ZFS_AC_KERNEL_SRC_SHRINK_CONTROL_STRUCT], [
227	ZFS_LINUX_TEST_SRC([shrink_control_struct], [
228		#include <linux/mm.h>
229	],[
230		struct shrink_control sc __attribute__ ((unused));
231
232		sc.nr_to_scan = 0;
233		sc.gfp_mask = GFP_KERNEL;
234	])
235])
236
237AC_DEFUN([ZFS_AC_KERNEL_SHRINK_CONTROL_STRUCT], [
238	AC_MSG_CHECKING([whether struct shrink_control exists])
239	ZFS_LINUX_TEST_RESULT([shrink_control_struct], [
240		AC_MSG_RESULT(yes)
241		AC_DEFINE(HAVE_SHRINK_CONTROL_STRUCT, 1,
242		    [struct shrink_control exists])
243	],[
244		ZFS_LINUX_TEST_ERROR([shrink_control])
245	])
246])
247
248AC_DEFUN([ZFS_AC_KERNEL_SRC_SHRINKER], [
249	ZFS_AC_KERNEL_SRC_SUPER_BLOCK_S_SHRINK
250	ZFS_AC_KERNEL_SRC_SUPER_BLOCK_S_SHRINK_PTR
251	ZFS_AC_KERNEL_SRC_SHRINK_CONTROL_HAS_NID
252	ZFS_AC_KERNEL_SRC_SHRINKER_CALLBACK
253	ZFS_AC_KERNEL_SRC_SHRINK_CONTROL_STRUCT
254	ZFS_AC_KERNEL_SRC_REGISTER_SHRINKER_VARARG
255	ZFS_AC_KERNEL_SRC_SHRINKER_REGISTER
256])
257
258AC_DEFUN([ZFS_AC_KERNEL_SHRINKER], [
259	ZFS_AC_KERNEL_SUPER_BLOCK_S_SHRINK
260	ZFS_AC_KERNEL_SHRINK_CONTROL_HAS_NID
261	ZFS_AC_KERNEL_SHRINKER_CALLBACK
262	ZFS_AC_KERNEL_SHRINK_CONTROL_STRUCT
263])
264