From owner-dev-commits-src-all@freebsd.org Sat May 22 18:23:56 2021 Return-Path: Delivered-To: dev-commits-src-all@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 F02C7634246; Sat, 22 May 2021 18:23:56 +0000 (UTC) (envelope-from git@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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4FnX183pcBz4V0x; Sat, 22 May 2021 18:23:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 219CEF69; Sat, 22 May 2021 18:23:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 14MINuql005860; Sat, 22 May 2021 18:23:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 14MINuPv005859; Sat, 22 May 2021 18:23:56 GMT (envelope-from git) Date: Sat, 22 May 2021 18:23:56 GMT Message-Id: <202105221823.14MINuPv005859@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mateusz Guzik Subject: git: 4869c1571f34 - stable/13 - vfs: lockless writecount adjustment in set/unset text MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mjg X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 4869c1571f34b603279a9addd18181aefc4f17e9 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 22 May 2021 18:23:57 -0000 The branch stable/13 has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=4869c1571f34b603279a9addd18181aefc4f17e9 commit 4869c1571f34b603279a9addd18181aefc4f17e9 Author: Mateusz Guzik AuthorDate: 2021-05-07 14:04:27 +0000 Commit: Mateusz Guzik CommitDate: 2021-05-22 18:22:03 +0000 vfs: lockless writecount adjustment in set/unset text ... for cases where this is not the first/last exec. (cherry picked from commit b5fb9ae6872c499f1a02bec41f48b163a73a2aaa) --- sys/kern/vfs_default.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/sys/kern/vfs_default.c b/sys/kern/vfs_default.c index 4b9b1b43f1ce..eb584feb6c41 100644 --- a/sys/kern/vfs_default.c +++ b/sys/kern/vfs_default.c @@ -1177,9 +1177,23 @@ vop_stdset_text(struct vop_set_text_args *ap) { struct vnode *vp; struct mount *mp; - int error; + int error, n; vp = ap->a_vp; + + /* + * Avoid the interlock if execs are already present. + */ + n = atomic_load_int(&vp->v_writecount); + for (;;) { + if (n > -1) { + break; + } + if (atomic_fcmpset_int(&vp->v_writecount, &n, n - 1)) { + return (0); + } + } + VI_LOCK(vp); if (vp->v_writecount > 0) { error = ETXTBSY; @@ -1207,10 +1221,24 @@ static int vop_stdunset_text(struct vop_unset_text_args *ap) { struct vnode *vp; - int error; + int error, n; bool last; vp = ap->a_vp; + + /* + * Avoid the interlock if this is not the last exec. + */ + n = atomic_load_int(&vp->v_writecount); + for (;;) { + if (n >= -1) { + break; + } + if (atomic_fcmpset_int(&vp->v_writecount, &n, n + 1)) { + return (0); + } + } + last = false; VI_LOCK(vp); if (vp->v_writecount < 0) {