3 dnl # The super_block structure now stores a per-filesystem shrinker.
4 dnl # This interface is preferable because it can be used to specifically
5 dnl # target only the zfs filesystem for pruning.
7 AC_DEFUN([ZFS_AC_KERNEL_SHRINK], [
8 AC_MSG_CHECKING([whether super_block has s_shrink])
9 ZFS_LINUX_TRY_COMPILE([
12 int shrink(struct shrinker *s, struct shrink_control *sc)
15 static const struct super_block
16 sb __attribute__ ((unused)) = {
17 .s_shrink.shrink = shrink,
18 .s_shrink.seeks = DEFAULT_SEEKS,
24 AC_DEFINE(HAVE_SHRINK, 1, [struct super_block has s_shrink])
33 dnl # The super_block structure was changed to use an hlist_node instead
34 dnl # of a list_head for the .s_instance linkage.
36 dnl # This was done in part to resolve a race in the iterate_supers_type()
37 dnl # function which was introduced in Linux 3.0 kernel. The iterator
38 dnl # was supposed to provide a safe way to call an arbitrary function on
39 dnl # all super blocks of a specific type. Unfortunately, because a
40 dnl # list_head was used it was possible for iterate_supers_type() to
41 dnl # get stuck spinning a super block which was just deactivated.
43 dnl # This can occur because when the list head is removed from the
44 dnl # fs_supers list it is reinitialized to point to itself. If the
45 dnl # iterate_supers_type() function happened to be processing the
46 dnl # removed list_head it will get stuck spinning on that list_head.
48 dnl # To resolve the issue for existing 3.0 - 3.2 kernels we detect when
49 dnl # a list_head is used. Then to prevent the spinning from occurring
50 dnl # the .next pointer is set to the fs_supers list_head which ensures
51 dnl # the iterate_supers_type() function will always terminate.
53 AC_DEFUN([ZFS_AC_KERNEL_S_INSTANCES_LIST_HEAD], [
54 AC_MSG_CHECKING([whether super_block has s_instances list_head])
55 ZFS_LINUX_TRY_COMPILE([
58 struct super_block sb __attribute__ ((unused));
60 INIT_LIST_HEAD(&sb.s_instances);
63 AC_DEFINE(HAVE_S_INSTANCES_LIST_HEAD, 1,
64 [struct super_block has s_instances list_head])
70 AC_DEFUN([ZFS_AC_KERNEL_NR_CACHED_OBJECTS], [
71 AC_MSG_CHECKING([whether sops->nr_cached_objects() exists])
72 ZFS_LINUX_TRY_COMPILE([
75 int nr_cached_objects(struct super_block *sb) { return 0; }
77 static const struct super_operations
78 sops __attribute__ ((unused)) = {
79 .nr_cached_objects = nr_cached_objects,
84 AC_DEFINE(HAVE_NR_CACHED_OBJECTS, 1,
85 [sops->nr_cached_objects() exists])
91 AC_DEFUN([ZFS_AC_KERNEL_FREE_CACHED_OBJECTS], [
92 AC_MSG_CHECKING([whether sops->free_cached_objects() exists])
93 ZFS_LINUX_TRY_COMPILE([
96 void free_cached_objects(struct super_block *sb, int x)
99 static const struct super_operations
100 sops __attribute__ ((unused)) = {
101 .free_cached_objects = free_cached_objects,
106 AC_DEFINE(HAVE_FREE_CACHED_OBJECTS, 1,
107 [sops->free_cached_objects() exists])
114 dnl # 3.12 API change
115 dnl # The nid member was added to struct shrink_control to support
116 dnl # NUMA-aware shrinkers.
118 AC_DEFUN([ZFS_AC_KERNEL_SHRINK_CONTROL_HAS_NID], [
119 AC_MSG_CHECKING([whether shrink_control has nid])
120 ZFS_LINUX_TRY_COMPILE([
121 #include <linux/fs.h>
123 struct shrink_control sc __attribute__ ((unused));
124 unsigned long scnidsize __attribute__ ((unused)) =
128 AC_DEFINE(SHRINK_CONTROL_HAS_NID, 1,
129 [struct shrink_control has nid])
136 AC_DEFUN([ZFS_AC_KERNEL_SHRINKER_CALLBACK],[
137 tmp_flags="$EXTRA_KCFLAGS"
138 EXTRA_KCFLAGS="-Werror"
140 dnl # 2.6.23 to 2.6.34 API change
141 dnl # ->shrink(int nr_to_scan, gfp_t gfp_mask)
143 AC_MSG_CHECKING([whether old 2-argument shrinker exists])
144 ZFS_LINUX_TRY_COMPILE([
145 #include <linux/mm.h>
147 int shrinker_cb(int nr_to_scan, gfp_t gfp_mask) {
151 struct shrinker cache_shrinker = {
152 .shrink = shrinker_cb,
153 .seeks = DEFAULT_SEEKS,
155 register_shrinker(&cache_shrinker);
158 AC_DEFINE(HAVE_2ARGS_OLD_SHRINKER_CALLBACK, 1,
159 [old shrinker callback wants 2 args])
163 dnl # 2.6.35 - 2.6.39 API change
164 dnl # ->shrink(struct shrinker *,
165 dnl # int nr_to_scan, gfp_t gfp_mask)
167 AC_MSG_CHECKING([whether old 3-argument shrinker exists])
168 ZFS_LINUX_TRY_COMPILE([
169 #include <linux/mm.h>
171 int shrinker_cb(struct shrinker *shrink, int nr_to_scan,
176 struct shrinker cache_shrinker = {
177 .shrink = shrinker_cb,
178 .seeks = DEFAULT_SEEKS,
180 register_shrinker(&cache_shrinker);
183 AC_DEFINE(HAVE_3ARGS_SHRINKER_CALLBACK, 1,
184 [old shrinker callback wants 3 args])
188 dnl # 3.0 - 3.11 API change
189 dnl # ->shrink(struct shrinker *,
190 dnl # struct shrink_control *sc)
193 [whether new 2-argument shrinker exists])
194 ZFS_LINUX_TRY_COMPILE([
195 #include <linux/mm.h>
197 int shrinker_cb(struct shrinker *shrink,
198 struct shrink_control *sc) {
202 struct shrinker cache_shrinker = {
203 .shrink = shrinker_cb,
204 .seeks = DEFAULT_SEEKS,
206 register_shrinker(&cache_shrinker);
209 AC_DEFINE(HAVE_2ARGS_NEW_SHRINKER_CALLBACK, 1,
210 [new shrinker callback wants 2 args])
214 dnl # 3.12 API change,
215 dnl # ->shrink() is logically split in to
216 dnl # ->count_objects() and ->scan_objects()
219 [whether ->count_objects callback exists])
220 ZFS_LINUX_TRY_COMPILE([
221 #include <linux/mm.h>
223 unsigned long shrinker_cb(
224 struct shrinker *shrink,
225 struct shrink_control *sc) {
229 struct shrinker cache_shrinker = {
230 .count_objects = shrinker_cb,
231 .scan_objects = shrinker_cb,
232 .seeks = DEFAULT_SEEKS,
234 register_shrinker(&cache_shrinker);
237 AC_DEFINE(HAVE_SPLIT_SHRINKER_CALLBACK,
238 1, [->count_objects exists])
245 EXTRA_KCFLAGS="$tmp_flags"
249 dnl # 2.6.39 API change,
250 dnl # Shrinker adjust to use common shrink_control structure.
252 AC_DEFUN([ZFS_AC_KERNEL_SHRINK_CONTROL_STRUCT], [
253 AC_MSG_CHECKING([whether struct shrink_control exists])
254 ZFS_LINUX_TRY_COMPILE([
255 #include <linux/mm.h>
257 struct shrink_control sc __attribute__ ((unused));
260 sc.gfp_mask = GFP_KERNEL;
263 AC_DEFINE(HAVE_SHRINK_CONTROL_STRUCT, 1,
264 [struct shrink_control exists])