aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRob Norris <[email protected]>2024-08-04 10:11:03 +1000
committerBrian Behlendorf <[email protected]>2024-09-18 11:23:50 -0700
commitb545b07b2fa024744c59e89d7898fda66a9c6179 (patch)
treeabe0f00abce6e332eb638272467068bc5db5ea05
parentd60d4ad809eb1ccfd50991bf1a1060b5e14bd16d (diff)
config: remove HAVE_SPLIT_SHRINKER_CALLBACK and HAVE_SINGLE_SHRINKER_CALLBACK
Sponsored-by: https://despairlabs.com/sponsor/ Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Tony Hutter <[email protected]> Reviewed-by: Tino Reichardt <[email protected]> Signed-off-by: Rob Norris <[email protected]> Closes #16479
-rw-r--r--config/kernel-shrink.m4110
-rw-r--r--module/os/linux/spl/spl-shrinker.c46
-rw-r--r--module/os/linux/zfs/zfs_vfsops.c79
3 files changed, 24 insertions, 211 deletions
diff --git a/config/kernel-shrink.m4 b/config/kernel-shrink.m4
index 4879a129a..30ea1c269 100644
--- a/config/kernel-shrink.m4
+++ b/config/kernel-shrink.m4
@@ -83,6 +83,11 @@ AC_DEFUN([ZFS_AC_KERNEL_SHRINK_CONTROL_HAS_NID], [
])
])
+dnl #
+dnl # 6.0 API change
+dnl # register_shrinker() becomes a var-arg function that takes
+dnl # a printf-style format string as args > 0
+dnl #
AC_DEFUN([ZFS_AC_KERNEL_SRC_REGISTER_SHRINKER_VARARG], [
ZFS_LINUX_TEST_SRC([register_shrinker_vararg], [
#include <linux/mm.h>
@@ -98,30 +103,14 @@ AC_DEFUN([ZFS_AC_KERNEL_SRC_REGISTER_SHRINKER_VARARG], [
])
])
-AC_DEFUN([ZFS_AC_KERNEL_SRC_SHRINKER_CALLBACK], [
- ZFS_LINUX_TEST_SRC([shrinker_cb_shrink_control], [
- #include <linux/mm.h>
- static int shrinker_cb(struct shrinker *shrink,
- struct shrink_control *sc) { return 0; }
- ],[
- struct shrinker cache_shrinker = {
- .shrink = shrinker_cb,
- .seeks = DEFAULT_SEEKS,
- };
- register_shrinker(&cache_shrinker);
- ])
-
- ZFS_LINUX_TEST_SRC([shrinker_cb_shrink_control_split], [
- #include <linux/mm.h>
- static unsigned long shrinker_cb(struct shrinker *shrink,
- struct shrink_control *sc) { return 0; }
+AC_DEFUN([ZFS_AC_KERNEL_REGISTER_SHRINKER_VARARG],[
+ AC_MSG_CHECKING([whether new var-arg register_shrinker() exists])
+ ZFS_LINUX_TEST_RESULT([register_shrinker_vararg], [
+ AC_MSG_RESULT(yes)
+ AC_DEFINE(HAVE_REGISTER_SHRINKER_VARARG, 1,
+ [register_shrinker is vararg])
],[
- struct shrinker cache_shrinker = {
- .count_objects = shrinker_cb,
- .scan_objects = shrinker_cb,
- .seeks = DEFAULT_SEEKS,
- };
- register_shrinker(&cache_shrinker);
+ AC_MSG_RESULT(no)
])
])
@@ -144,75 +133,12 @@ AC_DEFUN([ZFS_AC_KERNEL_SRC_SHRINKER_REGISTER], [
])
])
-AC_DEFUN([ZFS_AC_KERNEL_SHRINKER_CALLBACK],[
- dnl #
- dnl # 6.0 API change
- dnl # register_shrinker() becomes a var-arg function that takes
- dnl # a printf-style format string as args > 0
- dnl #
- AC_MSG_CHECKING([whether new var-arg register_shrinker() exists])
- ZFS_LINUX_TEST_RESULT([register_shrinker_vararg], [
+AC_DEFUN([ZFS_AC_KERNEL_SHRINKER_REGISTER], [
+ ZFS_LINUX_TEST_RESULT([shrinker_register], [
AC_MSG_RESULT(yes)
- AC_DEFINE(HAVE_REGISTER_SHRINKER_VARARG, 1,
- [register_shrinker is vararg])
-
- dnl # We assume that the split shrinker callback exists if the
- dnl # vararg register_shrinker() exists, because the latter is
- dnl # a much more recent addition, and the macro test for the
- dnl # var-arg version only works if the callback is split
- AC_DEFINE(HAVE_SPLIT_SHRINKER_CALLBACK, 1,
- [cs->count_objects exists])
- ],[
+ AC_DEFINE(HAVE_SHRINKER_REGISTER, 1, [shrinker_register exists])
+ ], [
AC_MSG_RESULT(no)
- dnl #
- dnl # 3.0 - 3.11 API change
- dnl # cs->shrink(struct shrinker *, struct shrink_control *sc)
- dnl #
- AC_MSG_CHECKING([whether new 2-argument shrinker exists])
- ZFS_LINUX_TEST_RESULT([shrinker_cb_shrink_control], [
- AC_MSG_RESULT(yes)
- AC_DEFINE(HAVE_SINGLE_SHRINKER_CALLBACK, 1,
- [new shrinker callback wants 2 args])
- ],[
- AC_MSG_RESULT(no)
-
- dnl #
- dnl # 3.12 API change,
- dnl # cs->shrink() is logically split in to
- dnl # cs->count_objects() and cs->scan_objects()
- dnl #
- AC_MSG_CHECKING(
- [whether cs->count_objects callback exists])
- ZFS_LINUX_TEST_RESULT(
- [shrinker_cb_shrink_control_split],[
- AC_MSG_RESULT(yes)
- AC_DEFINE(HAVE_SPLIT_SHRINKER_CALLBACK, 1,
- [cs->count_objects exists])
- ],[
- AC_MSG_RESULT(no)
-
- AC_MSG_CHECKING(
- [whether shrinker_register exists])
- ZFS_LINUX_TEST_RESULT([shrinker_register], [
- AC_MSG_RESULT(yes)
- AC_DEFINE(HAVE_SHRINKER_REGISTER, 1,
- [shrinker_register exists])
-
- dnl # We assume that the split shrinker
- dnl # callback exists if
- dnl # shrinker_register() exists,
- dnl # because the latter is a much more
- dnl # recent addition, and the macro
- dnl # test for shrinker_register() only
- dnl # works if the callback is split
- AC_DEFINE(HAVE_SPLIT_SHRINKER_CALLBACK,
- 1, [cs->count_objects exists])
- ],[
- AC_MSG_RESULT(no)
- ZFS_LINUX_TEST_ERROR([shrinker])
- ])
- ])
- ])
])
])
@@ -220,7 +146,6 @@ AC_DEFUN([ZFS_AC_KERNEL_SRC_SHRINKER], [
ZFS_AC_KERNEL_SRC_SUPER_BLOCK_S_SHRINK
ZFS_AC_KERNEL_SRC_SUPER_BLOCK_S_SHRINK_PTR
ZFS_AC_KERNEL_SRC_SHRINK_CONTROL_HAS_NID
- ZFS_AC_KERNEL_SRC_SHRINKER_CALLBACK
ZFS_AC_KERNEL_SRC_REGISTER_SHRINKER_VARARG
ZFS_AC_KERNEL_SRC_SHRINKER_REGISTER
])
@@ -228,5 +153,6 @@ AC_DEFUN([ZFS_AC_KERNEL_SRC_SHRINKER], [
AC_DEFUN([ZFS_AC_KERNEL_SHRINKER], [
ZFS_AC_KERNEL_SUPER_BLOCK_S_SHRINK
ZFS_AC_KERNEL_SHRINK_CONTROL_HAS_NID
- ZFS_AC_KERNEL_SHRINKER_CALLBACK
+ ZFS_AC_KERNEL_REGISTER_SHRINKER_VARARG
+ ZFS_AC_KERNEL_SHRINKER_REGISTER
])
diff --git a/module/os/linux/spl/spl-shrinker.c b/module/os/linux/spl/spl-shrinker.c
index d5c8da471..ff1c196d0 100644
--- a/module/os/linux/spl/spl-shrinker.c
+++ b/module/os/linux/spl/spl-shrinker.c
@@ -26,25 +26,6 @@
#include <sys/kmem.h>
#include <sys/shrinker.h>
-#ifdef HAVE_SINGLE_SHRINKER_CALLBACK
-/* 3.0-3.11: single shrink() callback, which we wrap to carry both functions */
-struct spl_shrinker_wrap {
- struct shrinker shrinker;
- spl_shrinker_cb countfunc;
- spl_shrinker_cb scanfunc;
-};
-
-static int
-spl_shrinker_single_cb(struct shrinker *shrinker, struct shrink_control *sc)
-{
- struct spl_shrinker_wrap *sw = (struct spl_shrinker_wrap *)shrinker;
-
- if (sc->nr_to_scan != 0)
- (void) sw->scanfunc(&sw->shrinker, sc);
- return (sw->countfunc(&sw->shrinker, sc));
-}
-#endif
-
struct shrinker *
spl_register_shrinker(const char *name, spl_shrinker_cb countfunc,
spl_shrinker_cb scanfunc, int seek_cost)
@@ -52,34 +33,20 @@ spl_register_shrinker(const char *name, spl_shrinker_cb countfunc,
struct shrinker *shrinker;
/* allocate shrinker */
-#if defined(HAVE_SHRINKER_REGISTER)
+#ifdef HAVE_SHRINKER_REGISTER
/* 6.7: kernel will allocate the shrinker for us */
shrinker = shrinker_alloc(0, name);
-#elif defined(HAVE_SPLIT_SHRINKER_CALLBACK)
- /* 3.12-6.6: we allocate the shrinker */
- shrinker = kmem_zalloc(sizeof (struct shrinker), KM_SLEEP);
-#elif defined(HAVE_SINGLE_SHRINKER_CALLBACK)
- /* 3.0-3.11: allocate a wrapper */
- struct spl_shrinker_wrap *sw =
- kmem_zalloc(sizeof (struct spl_shrinker_wrap), KM_SLEEP);
- shrinker = &sw->shrinker;
#else
- /* 2.x-2.6.22, or a newer shrinker API has been introduced. */
-#error "Unknown shrinker API"
+ /* 4.4-6.6: we allocate the shrinker */
+ shrinker = kmem_zalloc(sizeof (struct shrinker), KM_SLEEP);
#endif
if (shrinker == NULL)
return (NULL);
/* set callbacks */
-#ifdef HAVE_SINGLE_SHRINKER_CALLBACK
- sw->countfunc = countfunc;
- sw->scanfunc = scanfunc;
- shrinker->shrink = spl_shrinker_single_cb;
-#else
shrinker->count_objects = countfunc;
shrinker->scan_objects = scanfunc;
-#endif
/* set params */
shrinker->seeks = seek_cost;
@@ -102,14 +69,9 @@ spl_unregister_shrinker(struct shrinker *shrinker)
{
#if defined(HAVE_SHRINKER_REGISTER)
shrinker_free(shrinker);
-#elif defined(HAVE_SPLIT_SHRINKER_CALLBACK)
+#else
unregister_shrinker(shrinker);
kmem_free(shrinker, sizeof (struct shrinker));
-#elif defined(HAVE_SINGLE_SHRINKER_CALLBACK)
- unregister_shrinker(shrinker);
- kmem_free(shrinker, sizeof (struct spl_shrinker_wrap));
-#else
-#error "Unknown shrinker API"
#endif
}
EXPORT_SYMBOL(spl_unregister_shrinker);
diff --git a/module/os/linux/zfs/zfs_vfsops.c b/module/os/linux/zfs/zfs_vfsops.c
index 98b820e74..37d784b9c 100644
--- a/module/os/linux/zfs/zfs_vfsops.c
+++ b/module/os/linux/zfs/zfs_vfsops.c
@@ -1179,64 +1179,6 @@ zfs_root(zfsvfs_t *zfsvfs, struct inode **ipp)
}
/*
- * Linux kernels older than 3.1 do not support a per-filesystem shrinker.
- * To accommodate this we must improvise and manually walk the list of znodes
- * attempting to prune dentries in order to be able to drop the inodes.
- *
- * To avoid scanning the same znodes multiple times they are always rotated
- * to the end of the z_all_znodes list. New znodes are inserted at the
- * end of the list so we're always scanning the oldest znodes first.
- */
-static int
-zfs_prune_aliases(zfsvfs_t *zfsvfs, unsigned long nr_to_scan)
-{
- znode_t **zp_array, *zp;
- int max_array = MIN(nr_to_scan, PAGE_SIZE * 8 / sizeof (znode_t *));
- int objects = 0;
- int i = 0, j = 0;
-
- zp_array = vmem_zalloc(max_array * sizeof (znode_t *), KM_SLEEP);
-
- mutex_enter(&zfsvfs->z_znodes_lock);
- while ((zp = list_head(&zfsvfs->z_all_znodes)) != NULL) {
-
- if ((i++ > nr_to_scan) || (j >= max_array))
- break;
-
- ASSERT(list_link_active(&zp->z_link_node));
- list_remove(&zfsvfs->z_all_znodes, zp);
- list_insert_tail(&zfsvfs->z_all_znodes, zp);
-
- /* Skip active znodes and .zfs entries */
- if (MUTEX_HELD(&zp->z_lock) || zp->z_is_ctldir)
- continue;
-
- if (igrab(ZTOI(zp)) == NULL)
- continue;
-
- zp_array[j] = zp;
- j++;
- }
- mutex_exit(&zfsvfs->z_znodes_lock);
-
- for (i = 0; i < j; i++) {
- zp = zp_array[i];
-
- ASSERT3P(zp, !=, NULL);
- d_prune_aliases(ZTOI(zp));
-
- if (atomic_read(&ZTOI(zp)->i_count) == 1)
- objects++;
-
- zrele(zp);
- }
-
- vmem_free(zp_array, max_array * sizeof (znode_t *));
-
- return (objects);
-}
-
-/*
* The ARC has requested that the filesystem drop entries from the dentry
* and inode caches. This can occur when the ARC needs to free meta data
* blocks but can't because they are all pinned by entries in these caches.
@@ -1261,8 +1203,7 @@ zfs_prune(struct super_block *sb, unsigned long nr_to_scan, int *objects)
if ((error = zfs_enter(zfsvfs, FTAG)) != 0)
return (error);
-#if defined(HAVE_SPLIT_SHRINKER_CALLBACK) && \
- defined(SHRINK_CONTROL_HAS_NID) && \
+#if defined(SHRINK_CONTROL_HAS_NID) && \
defined(SHRINKER_NUMA_AWARE)
if (shrinker->flags & SHRINKER_NUMA_AWARE) {
long tc = 1;
@@ -1285,24 +1226,8 @@ zfs_prune(struct super_block *sb, unsigned long nr_to_scan, int *objects)
} else {
*objects = (*shrinker->scan_objects)(shrinker, &sc);
}
-
-#elif defined(HAVE_SPLIT_SHRINKER_CALLBACK)
+#else
*objects = (*shrinker->scan_objects)(shrinker, &sc);
-#elif defined(HAVE_SINGLE_SHRINKER_CALLBACK)
- *objects = (*shrinker->shrink)(shrinker, &sc);
-#define D_PRUNE_ALIASES_IS_DEFAULT
- *objects = zfs_prune_aliases(zfsvfs, nr_to_scan);
-#endif
-
-#ifndef D_PRUNE_ALIASES_IS_DEFAULT
-#undef D_PRUNE_ALIASES_IS_DEFAULT
- /*
- * Fall back to zfs_prune_aliases if the kernel's per-superblock
- * shrinker couldn't free anything, possibly due to the inodes being
- * allocated in a different memcg.
- */
- if (*objects == 0)
- *objects = zfs_prune_aliases(zfsvfs, nr_to_scan);
#endif
zfs_exit(zfsvfs, FTAG);