From owner-svn-src-head@freebsd.org Fri Jan 24 07:46:00 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 8EBAF230EF0; Fri, 24 Jan 2020 07:46:00 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 483rmS314Vz4dVh; Fri, 24 Jan 2020 07:46:00 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 6271024100; Fri, 24 Jan 2020 07:46:00 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 00O7k0U1021211; Fri, 24 Jan 2020 07:46:00 GMT (envelope-from mjg@FreeBSD.org) Received: (from mjg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 00O7k0ZY021210; Fri, 24 Jan 2020 07:46:00 GMT (envelope-from mjg@FreeBSD.org) Message-Id: <202001240746.00O7k0ZY021210@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mjg set sender to mjg@FreeBSD.org using -f From: Mateusz Guzik Date: Fri, 24 Jan 2020 07:46:00 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r357071 - in head/sys: kern ufs/ffs X-SVN-Group: head X-SVN-Commit-Author: mjg X-SVN-Commit-Paths: in head/sys: kern ufs/ffs X-SVN-Commit-Revision: 357071 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Jan 2020 07:46:00 -0000 Author: mjg Date: Fri Jan 24 07:45:59 2020 New Revision: 357071 URL: https://svnweb.freebsd.org/changeset/base/357071 Log: vfs: stop handling VI_OWEINACT in vget vget is almost always called with LK_SHARED, meaning the flag (if present) is almost guaranteed to get cleared. Stop handling it in the first place and instead let the thread which wanted to do inactive handle the bumepd usecount. Reviewed by: jeff Tested by: pho Differential Revision: https://reviews.freebsd.org/D23184 Modified: head/sys/kern/vfs_subr.c head/sys/ufs/ffs/ffs_snapshot.c Modified: head/sys/kern/vfs_subr.c ============================================================================== --- head/sys/kern/vfs_subr.c Fri Jan 24 07:44:25 2020 (r357070) +++ head/sys/kern/vfs_subr.c Fri Jan 24 07:45:59 2020 (r357071) @@ -2860,7 +2860,7 @@ vget(struct vnode *vp, int flags, struct thread *td) int vget_finish(struct vnode *vp, int flags, enum vgetstate vs) { - int error, oweinact; + int error; VNASSERT((flags & LK_TYPE_MASK) != 0, vp, ("%s: invalid lock operation", __func__)); @@ -2887,8 +2887,6 @@ vget_finish(struct vnode *vp, int flags, enum vgetstat } if (vs == VGET_USECOUNT) { - VNASSERT((vp->v_iflag & VI_OWEINACT) == 0, vp, - ("%s: vnode with usecount and VI_OWEINACT set", __func__)); return (0); } @@ -2904,9 +2902,6 @@ vget_finish(struct vnode *vp, int flags, enum vgetstat #else refcount_release(&vp->v_holdcnt); #endif - VNODE_REFCOUNT_FENCE_ACQ(); - VNASSERT((vp->v_iflag & VI_OWEINACT) == 0, vp, - ("%s: vnode with usecount and VI_OWEINACT set", __func__)); return (0); } @@ -2930,25 +2925,11 @@ vget_finish(struct vnode *vp, int flags, enum vgetstat #else refcount_release(&vp->v_holdcnt); #endif - VNODE_REFCOUNT_FENCE_ACQ(); - VNASSERT((vp->v_iflag & VI_OWEINACT) == 0, vp, - ("%s: vnode with usecount and VI_OWEINACT set", - __func__)); VI_UNLOCK(vp); return (0); } - if ((vp->v_iflag & VI_OWEINACT) == 0) { - oweinact = 0; - } else { - oweinact = 1; - vp->v_iflag &= ~VI_OWEINACT; - VNODE_REFCOUNT_FENCE_REL(); - } v_incr_devcount(vp); refcount_acquire(&vp->v_usecount); - if (oweinact && VOP_ISLOCKED(vp) == LK_EXCLUSIVE && - (flags & LK_NOWAIT) == 0) - vinactive(vp); VI_UNLOCK(vp); return (0); } @@ -2967,8 +2948,6 @@ vref(struct vnode *vp) VNODE_REFCOUNT_FENCE_ACQ(); VNASSERT(vp->v_holdcnt > 0, vp, ("%s: active vnode not held", __func__)); - VNASSERT((vp->v_iflag & VI_OWEINACT) == 0, vp, - ("%s: vnode with usecount and VI_OWEINACT set", __func__)); return; } VI_LOCK(vp); @@ -2986,15 +2965,9 @@ vrefl(struct vnode *vp) VNODE_REFCOUNT_FENCE_ACQ(); VNASSERT(vp->v_holdcnt > 0, vp, ("%s: active vnode not held", __func__)); - VNASSERT((vp->v_iflag & VI_OWEINACT) == 0, vp, - ("%s: vnode with usecount and VI_OWEINACT set", __func__)); return; } vholdl(vp); - if ((vp->v_iflag & VI_OWEINACT) != 0) { - vp->v_iflag &= ~VI_OWEINACT; - VNODE_REFCOUNT_FENCE_REL(); - } v_incr_devcount(vp); refcount_acquire(&vp->v_usecount); } @@ -3052,8 +3025,8 @@ vdefer_inactive(struct vnode *vp) { ASSERT_VI_LOCKED(vp, __func__); - VNASSERT(vp->v_iflag & VI_OWEINACT, vp, - ("%s: vnode without VI_OWEINACT", __func__)); + VNASSERT(vp->v_holdcnt > 0, vp, + ("%s: vnode without hold count", __func__)); if (VN_IS_DOOMED(vp)) { vdropl(vp); return; @@ -3063,6 +3036,11 @@ vdefer_inactive(struct vnode *vp) vdropl(vp); return; } + if (vp->v_usecount > 0) { + vp->v_iflag &= ~VI_OWEINACT; + vdropl(vp); + return; + } vlazy(vp); vp->v_iflag |= VI_DEFINACT; VI_UNLOCK(vp); @@ -3070,11 +3048,10 @@ vdefer_inactive(struct vnode *vp) } static void -vdefer_inactive_cond(struct vnode *vp) +vdefer_inactive_unlocked(struct vnode *vp) { VI_LOCK(vp); - VNASSERT(vp->v_holdcnt > 0, vp, ("vnode without hold count")); if ((vp->v_iflag & VI_OWEINACT) == 0) { vdropl(vp); return; @@ -3173,15 +3150,12 @@ vputx(struct vnode *vp, enum vputx_op func) VNASSERT(vp->v_usecount == 0 || (vp->v_iflag & VI_OWEINACT) == 0, vp, ("vnode with usecount and VI_OWEINACT set")); if (error == 0) { - if (vp->v_iflag & VI_OWEINACT) - vinactive(vp); + vinactive(vp); if (func != VPUTX_VUNREF) VOP_UNLOCK(vp); vdropl(vp); - } else if (vp->v_iflag & VI_OWEINACT) { - vdefer_inactive(vp); } else { - vdropl(vp); + vdefer_inactive(vp); } return; out: @@ -3442,11 +3416,9 @@ vdropl(struct vnode *vp) /* * Call VOP_INACTIVE on the vnode and manage the DOINGINACT and OWEINACT * flags. DOINGINACT prevents us from recursing in calls to vinactive. - * OWEINACT tracks whether a vnode missed a call to inactive due to a - * failed lock upgrade. */ -void -vinactive(struct vnode *vp) +static void +vinactivef(struct vnode *vp) { struct vm_object *obj; @@ -3481,6 +3453,25 @@ vinactive(struct vnode *vp) vp->v_iflag &= ~VI_DOINGINACT; } +void +vinactive(struct vnode *vp) +{ + + ASSERT_VOP_ELOCKED(vp, "vinactive"); + ASSERT_VI_LOCKED(vp, "vinactive"); + CTR2(KTR_VFS, "%s: vp %p", __func__, vp); + + if ((vp->v_iflag & VI_OWEINACT) == 0) + return; + if (vp->v_iflag & VI_DOINGINACT) + return; + if (vp->v_usecount > 0) { + vp->v_iflag &= ~VI_OWEINACT; + return; + } + vinactivef(vp); +} + /* * Remove any vnodes in the vnode table belonging to mount point mp. * @@ -3779,8 +3770,7 @@ vgonel(struct vnode *vp) VOP_CLOSE(vp, FNONBLOCK, NOCRED, td); if (oweinact || active) { VI_LOCK(vp); - if ((vp->v_iflag & VI_DOINGINACT) == 0) - vinactive(vp); + vinactivef(vp); VI_UNLOCK(vp); } if (vp->v_type == VSOCK) @@ -4530,13 +4520,12 @@ vfs_deferred_inactive(struct vnode *vp, int lkflags) } if (vn_lock(vp, lkflags) == 0) { VI_LOCK(vp); - if ((vp->v_iflag & (VI_OWEINACT | VI_DOINGINACT)) == VI_OWEINACT) - vinactive(vp); + vinactive(vp); VOP_UNLOCK(vp); vdropl(vp); return; } - vdefer_inactive_cond(vp); + vdefer_inactive_unlocked(vp); } static int @@ -4636,7 +4625,7 @@ vfs_periodic_msync_inactive(struct mount *mp, int flag vdrop(vp); } else { if (seen_defer) - vdefer_inactive_cond(vp); + vdefer_inactive_unlocked(vp); } } } Modified: head/sys/ufs/ffs/ffs_snapshot.c ============================================================================== --- head/sys/ufs/ffs/ffs_snapshot.c Fri Jan 24 07:44:25 2020 (r357070) +++ head/sys/ufs/ffs/ffs_snapshot.c Fri Jan 24 07:45:59 2020 (r357071) @@ -2583,15 +2583,7 @@ process_deferred_inactive(struct mount *mp) UFS_INODE_SET_FLAG(ip, IN_MODIFIED); } VI_LOCK(vp); - if ((vp->v_iflag & VI_OWEINACT) == 0 || vp->v_usecount > 0) { - VI_UNLOCK(vp); - VOP_UNLOCK(vp); - vdrop(vp); - continue; - } vinactive(vp); - VNASSERT((vp->v_iflag & VI_OWEINACT) == 0, vp, - ("process_deferred_inactive: got VI_OWEINACT")); VI_UNLOCK(vp); VOP_UNLOCK(vp); vdrop(vp);