commit 46707728c44fc9119dd56b66e42abbe397699faf Author: Mateusz Guzik Date: Wed Mar 17 22:33:47 2021 +0100 vfs: vnlru fix diff --git a/sys/contrib/openzfs/module/os/freebsd/zfs/arc_os.c b/sys/contrib/openzfs/module/os/freebsd/zfs/arc_os.c index 4fc7468bfa47..5ed33b5161fc 100644 --- a/sys/contrib/openzfs/module/os/freebsd/zfs/arc_os.c +++ b/sys/contrib/openzfs/module/os/freebsd/zfs/arc_os.c @@ -51,6 +51,8 @@ #include #include +static struct vnode *arc_vnlru_marker; + extern struct vfsops zfs_vfsops; uint_t zfs_arc_free_target = 0; @@ -157,7 +159,7 @@ arc_prune_task(void *arg) arc_reduce_target_size(ptob(nr_scan)); free(arg, M_TEMP); - vnlru_free(nr_scan, &zfs_vfsops); + vnlru_free_vfsops(nr_scan, &zfs_vfsops, arc_vnlru_marker); } /* @@ -234,7 +236,7 @@ arc_lowmem_init(void) { arc_event_lowmem = EVENTHANDLER_REGISTER(vm_lowmem, arc_lowmem, NULL, EVENTHANDLER_PRI_FIRST); - + arc_vnlru_marker = vnlru_alloc_marker(); } void @@ -242,6 +244,8 @@ arc_lowmem_fini(void) { if (arc_event_lowmem != NULL) EVENTHANDLER_DEREGISTER(vm_lowmem, arc_event_lowmem); + if (arc_vnlru_marker != NULL) + vnlru_free_marker(arc_vnlru_marker); } void diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c index 37e713ee48ea..59c716149216 100644 --- a/sys/kern/vfs_subr.c +++ b/sys/kern/vfs_subr.c @@ -1216,9 +1216,9 @@ SYSCTL_INT(_debug, OID_AUTO, max_vnlru_free, CTLFLAG_RW, &max_vnlru_free, * Attempt to reduce the free list by the requested amount. */ static int -vnlru_free_locked(int count, struct vfsops *mnt_op) +vnlru_free_impl(int count, struct vfsops *mnt_op, struct vnode *mvp) { - struct vnode *vp, *mvp; + struct vnode *vp; struct mount *mp; int ocount; @@ -1226,7 +1226,6 @@ vnlru_free_locked(int count, struct vfsops *mnt_op) if (count > max_vnlru_free) count = max_vnlru_free; ocount = count; - mvp = vnode_list_free_marker; vp = mvp; for (;;) { if (count == 0) { @@ -1268,15 +1267,51 @@ vnlru_free_locked(int count, struct vfsops *mnt_op) return (ocount - count); } +static int +vnlru_free_locked(int count) +{ + + mtx_assert(&vnode_list_mtx, MA_OWNED); + return (vnlru_free_impl(count, NULL, vnode_list_free_marker)); +} + void -vnlru_free(int count, struct vfsops *mnt_op) +vnlru_free(int count) { mtx_lock(&vnode_list_mtx); - vnlru_free_locked(count, mnt_op); + vnlru_free_locked(count); mtx_unlock(&vnode_list_mtx); } +void +vnlru_free_vfsops(int count, struct vfsops *mnt_op, struct vnode *mvp) +{ + + MPASS(mnt_op != NULL); + MPASS(mvp != NULL); + VNPASS(mvp->v_type == VMARKER, mvp); + mtx_lock(&vnode_list_mtx); + TAILQ_INSERT_BEFORE(vnode_list_free_marker, mvp, v_vnodelist); + vnlru_free_impl(count, mnt_op, mvp); + TAILQ_REMOVE(&vnode_list, mvp, v_vnodelist); + mtx_unlock(&vnode_list_mtx); +} + +struct vnode * +vnlru_alloc_marker(void) +{ + + return (vn_alloc_marker(NULL)); +} + +void +vnlru_free_marker(struct vnode *vp) +{ + + return (vn_free_marker(vp)); +} + static void vnlru_recalc(void) { @@ -1423,7 +1458,7 @@ vnlru_proc(void) * try to reduce it by discarding from the free list. */ if (rnumvnodes > desiredvnodes) { - vnlru_free_locked(rnumvnodes - desiredvnodes, NULL); + vnlru_free_locked(rnumvnodes - desiredvnodes); rnumvnodes = atomic_load_long(&numvnodes); } /* @@ -1615,7 +1650,7 @@ vn_alloc_hard(struct mount *mp) * should be chosen so that we never wait or even reclaim from * the free list to below its target minimum. */ - if (vnlru_free_locked(1, NULL) > 0) + if (vnlru_free_locked(1) > 0) goto alloc; if (mp == NULL || (mp->mnt_kern_flag & MNTK_SUSPEND) == 0) { /* @@ -1625,7 +1660,7 @@ vn_alloc_hard(struct mount *mp) msleep(&vnlruproc_sig, &vnode_list_mtx, PVFS, "vlruwk", hz); if (atomic_load_long(&numvnodes) + 1 > desiredvnodes && vnlru_read_freevnodes() > 1) - vnlru_free_locked(1, NULL); + vnlru_free_locked(1); } alloc: rnumvnodes = atomic_fetchadd_long(&numvnodes, 1) + 1; diff --git a/sys/sys/vnode.h b/sys/sys/vnode.h index 0e46bea14b64..fa1188fe7538 100644 --- a/sys/sys/vnode.h +++ b/sys/sys/vnode.h @@ -826,7 +826,10 @@ void vfs_timestamp(struct timespec *); void vfs_write_resume(struct mount *mp, int flags); int vfs_write_suspend(struct mount *mp, int flags); int vfs_write_suspend_umnt(struct mount *mp); -void vnlru_free(int, struct vfsops *); +struct vnode *vnlru_alloc_marker(void); +void vnlru_free_marker(struct vnode *); +void vnlru_free(int); +void vnlru_free_vfsops(int, struct vfsops *, struct vnode *); int vop_stdbmap(struct vop_bmap_args *); int vop_stdfdatasync_buf(struct vop_fdatasync_args *); int vop_stdfsync(struct vop_fsync_args *);