mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 02:27:36 +03:00
Unify arc_prune_async() code
There is no sense to have separate implementations for FreeBSD and Linux. Make Linux code shared as more functional and just register FreeBSD-specific prune callback with arc_add_prune_callback() API. Aside of code cleanup this should fix excessive pruning on FreeBSD: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=274698 Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Mark Johnston <markj@FreeBSD.org> Signed-off-by: Alexander Motin <mav@FreeBSD.org> Sponsored by: iXsystems, Inc. Closes #15456
This commit is contained in:
committed by
Tony Hutter
parent
bd7a02c251
commit
3ec4ea68d4
@@ -52,11 +52,6 @@
|
||||
#include <sys/vm.h>
|
||||
#include <sys/vmmeter.h>
|
||||
|
||||
#if __FreeBSD_version >= 1300139
|
||||
static struct sx arc_vnlru_lock;
|
||||
static struct vnode *arc_vnlru_marker;
|
||||
#endif
|
||||
|
||||
extern struct vfsops zfs_vfsops;
|
||||
|
||||
uint_t zfs_arc_free_target = 0;
|
||||
@@ -131,53 +126,6 @@ arc_default_max(uint64_t min, uint64_t allmem)
|
||||
return (MAX(allmem * 5 / 8, size));
|
||||
}
|
||||
|
||||
/*
|
||||
* Helper function for arc_prune_async() it is responsible for safely
|
||||
* handling the execution of a registered arc_prune_func_t.
|
||||
*/
|
||||
static void
|
||||
arc_prune_task(void *arg)
|
||||
{
|
||||
uint64_t nr_scan = (uintptr_t)arg;
|
||||
|
||||
#ifndef __ILP32__
|
||||
if (nr_scan > INT_MAX)
|
||||
nr_scan = INT_MAX;
|
||||
#endif
|
||||
|
||||
#if __FreeBSD_version >= 1300139
|
||||
sx_xlock(&arc_vnlru_lock);
|
||||
vnlru_free_vfsops(nr_scan, &zfs_vfsops, arc_vnlru_marker);
|
||||
sx_xunlock(&arc_vnlru_lock);
|
||||
#else
|
||||
vnlru_free(nr_scan, &zfs_vfsops);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Notify registered consumers they must drop holds on a portion of the ARC
|
||||
* buffered they reference. This provides a mechanism to ensure the ARC can
|
||||
* honor the metadata limit and reclaim otherwise pinned ARC buffers. This
|
||||
* is analogous to dnlc_reduce_cache() but more generic.
|
||||
*
|
||||
* This operation is performed asynchronously so it may be safely called
|
||||
* in the context of the arc_reclaim_thread(). A reference is taken here
|
||||
* for each registered arc_prune_t and the arc_prune_task() is responsible
|
||||
* for releasing it once the registered arc_prune_func_t has completed.
|
||||
*/
|
||||
void
|
||||
arc_prune_async(uint64_t adjust)
|
||||
{
|
||||
|
||||
#ifndef __LP64__
|
||||
if (adjust > UINTPTR_MAX)
|
||||
adjust = UINTPTR_MAX;
|
||||
#endif
|
||||
taskq_dispatch(arc_prune_taskq, arc_prune_task,
|
||||
(void *)(intptr_t)adjust, TQ_SLEEP);
|
||||
ARCSTAT_BUMP(arcstat_prune);
|
||||
}
|
||||
|
||||
uint64_t
|
||||
arc_all_memory(void)
|
||||
{
|
||||
@@ -228,10 +176,6 @@ arc_lowmem_init(void)
|
||||
{
|
||||
arc_event_lowmem = EVENTHANDLER_REGISTER(vm_lowmem, arc_lowmem, NULL,
|
||||
EVENTHANDLER_PRI_FIRST);
|
||||
#if __FreeBSD_version >= 1300139
|
||||
arc_vnlru_marker = vnlru_alloc_marker();
|
||||
sx_init(&arc_vnlru_lock, "arc vnlru lock");
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
@@ -239,12 +183,6 @@ arc_lowmem_fini(void)
|
||||
{
|
||||
if (arc_event_lowmem != NULL)
|
||||
EVENTHANDLER_DEREGISTER(vm_lowmem, arc_event_lowmem);
|
||||
#if __FreeBSD_version >= 1300139
|
||||
if (arc_vnlru_marker != NULL) {
|
||||
vnlru_free_marker(arc_vnlru_marker);
|
||||
sx_destroy(&arc_vnlru_lock);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -2070,6 +2070,26 @@ zfs_vnodes_adjust_back(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
#if __FreeBSD_version >= 1300139
|
||||
static struct sx zfs_vnlru_lock;
|
||||
static struct vnode *zfs_vnlru_marker;
|
||||
#endif
|
||||
static arc_prune_t *zfs_prune;
|
||||
|
||||
static void
|
||||
zfs_prune_task(uint64_t nr_to_scan, void *arg __unused)
|
||||
{
|
||||
if (nr_to_scan > INT_MAX)
|
||||
nr_to_scan = INT_MAX;
|
||||
#if __FreeBSD_version >= 1300139
|
||||
sx_xlock(&zfs_vnlru_lock);
|
||||
vnlru_free_vfsops(nr_to_scan, &zfs_vfsops, zfs_vnlru_marker);
|
||||
sx_xunlock(&zfs_vnlru_lock);
|
||||
#else
|
||||
vnlru_free(nr_to_scan, &zfs_vfsops);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
zfs_init(void)
|
||||
{
|
||||
@@ -2096,11 +2116,23 @@ zfs_init(void)
|
||||
dmu_objset_register_type(DMU_OST_ZFS, zpl_get_file_info);
|
||||
|
||||
zfsvfs_taskq = taskq_create("zfsvfs", 1, minclsyspri, 0, 0, 0);
|
||||
|
||||
#if __FreeBSD_version >= 1300139
|
||||
zfs_vnlru_marker = vnlru_alloc_marker();
|
||||
sx_init(&zfs_vnlru_lock, "zfs vnlru lock");
|
||||
#endif
|
||||
zfs_prune = arc_add_prune_callback(zfs_prune_task, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
zfs_fini(void)
|
||||
{
|
||||
arc_remove_prune_callback(zfs_prune);
|
||||
#if __FreeBSD_version >= 1300139
|
||||
vnlru_free_marker(zfs_vnlru_marker);
|
||||
sx_destroy(&zfs_vnlru_lock);
|
||||
#endif
|
||||
|
||||
taskq_destroy(zfsvfs_taskq);
|
||||
zfsctl_fini();
|
||||
zfs_znode_fini();
|
||||
|
||||
Reference in New Issue
Block a user