mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 10:37:35 +03:00
config: remove HAVE_SPLIT_SHRINKER_CALLBACK and HAVE_SINGLE_SHRINKER_CALLBACK
Sponsored-by: https://despairlabs.com/sponsor/ Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Tony Hutter <hutter2@llnl.gov> Reviewed-by: Tino Reichardt <milky-zfs@mcmilk.de> Signed-off-by: Rob Norris <robn@despairlabs.com> Closes #16479
This commit is contained in:
committed by
Brian Behlendorf
parent
d60d4ad809
commit
b545b07b2f
@@ -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);
|
||||
|
||||
@@ -1178,64 +1178,6 @@ zfs_root(zfsvfs_t *zfsvfs, struct inode **ipp)
|
||||
return (error);
|
||||
}
|
||||
|
||||
/*
|
||||
* 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
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user