From nobody Wed Jun 12 23:42:41 2024 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4W02CP6DF7z5L0Mw; Wed, 12 Jun 2024 23:42:41 +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 4W02CP5lnWz4fY4; Wed, 12 Jun 2024 23:42:41 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1718235761; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=I7YEmVkBbSUH633CwiItCt8TxIV+9Hsis/xlbz6f0Tw=; b=qoLBqpbqAriQXEDS3udLEIlbduofNNAmimVQdw9AL6eHsjDiStAC5ozGLNTUl+CqX6QtAV XM5BIf6ee2jO3ociYIYVKaFhcdzFQRRZxhlkDKByD9lBK6iW1gDBH8cySfvqJXxBh3QBKw AHfG5qxRG8pmdlOqZOX1FOT2LuH3Q76QQE3mfjWKOwfZPmd+b0frE0mS+7C4hAspeeWcTT 1xgRFOMpn38Hl7yoV/9Ucnuw3x+ET8+94kHUJZbxh2blFByZEb5OsUno53QsLMtp9rY6zM jdwrNx2o0Sp1tAYc+2Bdn7dVzWILKgf3hsVINdIYqxDvp9Id3NxN4OK4YUnmwA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1718235761; a=rsa-sha256; cv=none; b=Dwg8z+sWfyd4qVU2o4QtXK9BOPGtSIrn1z2ikYon1tiLuP8NRWeAy/qQrL6S6wIuFw5qsB WA60HIvEgQF+8zJIa2tZ3syf+tFYPfmKgulCcrSD+SD2uycr1Vn/q5oWP1ZDDQevBumGcm P/KC+MFGpSwjpEbEzHqYNW5WJkoMwaaEHYwTGcu5hRv1E4iJfDHE5pKNha9rHqo5xSWSTP uX6aUl9fRaZxJV8QvBJB0JZzF0AQPcNTcZfW+qsEY91LE2E1LgGFJ+7/AVlYyHfr09P0PS 2AxL2vPKWk4zVbQ2cTBKt6Lt4UG7TUnof6g0iswVok6KdSi2rFZ3KKbDEzsWuw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1718235761; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=I7YEmVkBbSUH633CwiItCt8TxIV+9Hsis/xlbz6f0Tw=; b=sOSFjxEI5vCSE7uw+dqIYdo2KcZm415e9nP6VAm4ZYNaHh/tOg1iHsX2w+dq4/pMJeBipZ vFGDwjhygt15ZEFCC0LcgzFE14eLdgvqewc0gdUeiSwGrV6IKN7sv5mb4L6S9kpW0zljq7 iHiDyUSNyJ9yA0Vq2bb6SfulmWk0Gf2XFblOCOiMMRD1cqpvSCBQAb1gA0+rjpByQE5PlH PXdPx+YfkxT9IrQ4XJ3rieiqJ4KH2JO8tyr7bC3zqFSUAT62dSZtZexzkfMckCnccX2vzb 05ZUNTbffSkk1BmJ7SXQ4PO8gDrAijvqLaKcUhFFxMTIAOZ6XUkdBh4eOB95EQ== 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 4W02CP4qgrz1Ckk; Wed, 12 Jun 2024 23:42:41 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 45CNgfSG061390; Wed, 12 Jun 2024 23:42:41 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 45CNgfXJ061387; Wed, 12 Jun 2024 23:42:41 GMT (envelope-from git) Date: Wed, 12 Jun 2024 23:42:41 GMT Message-Id: <202406122342.45CNgfXJ061387@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Rick Macklem Subject: git: bb53f071e85a - main - nfscl: Add support for read delegations and atomic upgrade List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: rmacklem X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: bb53f071e85a2ebb5b405e7fec4661a725b7caf5 Auto-Submitted: auto-generated The branch main has been updated by rmacklem: URL: https://cgit.FreeBSD.org/src/commit/?id=bb53f071e85a2ebb5b405e7fec4661a725b7caf5 commit bb53f071e85a2ebb5b405e7fec4661a725b7caf5 Author: Rick Macklem AuthorDate: 2024-06-12 23:41:12 +0000 Commit: Rick Macklem CommitDate: 2024-06-12 23:41:12 +0000 nfscl: Add support for read delegations and atomic upgrade For NFSv4.1/4.2, an atomic upgrade of a delegation from a read delegation to a write delegation is allowed and can result in significantly improved performance. This patch adds this upgrade to the NFSv4.1/4.2 client and enables use of read delegations. For a test case of building a FreeBSD kernel (sources and output objects) over a NFSv4.2 mount, these changes reduced the elapsed time by 30% and included a reduction of 80% for RPC counts when delegations were enabled. As such, with this patch there are at least certain cases where enabling delegations seems to be worth the increased complexity they bring. This patch should only affect the NFSv4.1/4.2 behaviour when delegations are enabled, which is not the default. MFC after: 1 month --- sys/fs/nfsclient/nfs_clstate.c | 38 ++++++++++++++++++++++---------------- sys/fs/nfsclient/nfs_clsubs.c | 6 +++--- sys/fs/nfsclient/nfs_clvnops.c | 2 +- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/sys/fs/nfsclient/nfs_clstate.c b/sys/fs/nfsclient/nfs_clstate.c index aef5d71592af..0a1eb51e279f 100644 --- a/sys/fs/nfsclient/nfs_clstate.c +++ b/sys/fs/nfsclient/nfs_clstate.c @@ -439,18 +439,6 @@ nfscl_deleg(mount_t mp, struct nfsclclient *clp, u_int8_t *nfhp, KASSERT(mp != NULL, ("nfscl_deleg: mp NULL")); nmp = VFSTONFS(mp); - /* - * First, if we have received a Read delegation for a file on a - * read/write file system, just return it, because they aren't - * useful, imho. - */ - if (dp != NULL && !NFSMNT_RDONLY(mp) && - (dp->nfsdl_flags & NFSCLDL_READ)) { - nfscl_trydelegreturn(dp, cred, nmp, p); - free(dp, M_NFSCLDELEG); - *dpp = NULL; - return (0); - } /* * Since a delegation might be added to the mount, @@ -478,17 +466,35 @@ nfscl_deleg(mount_t mp, struct nfsclclient *clp, u_int8_t *nfhp, nfscl_delegcnt++; } else { /* - * Delegation already exists, what do we do if a new one?? + * A delegation already exists. If the new one is a Write + * delegation and the old one a Read delegation, return the + * Read delegation. Otherwise, return the new delegation. */ if (dp != NULL) { - printf("Deleg already exists!\n"); - free(dp, M_NFSCLDELEG); - *dpp = NULL; + if ((dp->nfsdl_flags & NFSCLDL_WRITE) != 0 && + (tdp->nfsdl_flags & NFSCLDL_READ) != 0) { + TAILQ_REMOVE(&clp->nfsc_deleg, tdp, nfsdl_list); + LIST_REMOVE(tdp, nfsdl_hash); + *dpp = NULL; + TAILQ_INSERT_HEAD(&clp->nfsc_deleg, dp, + nfsdl_list); + LIST_INSERT_HEAD(NFSCLDELEGHASH(clp, nfhp, + fhlen), dp, nfsdl_hash); + dp->nfsdl_timestamp = NFSD_MONOSEC + 120; + } else { + *dpp = NULL; + tdp = dp; /* Return this one. */ + } } else { *dpp = tdp; + tdp = NULL; } } NFSUNLOCKCLSTATE(); + if (tdp != NULL) { + nfscl_trydelegreturn(tdp, cred, nmp, p); + free(tdp, M_NFSCLDELEG); + } return (0); } diff --git a/sys/fs/nfsclient/nfs_clsubs.c b/sys/fs/nfsclient/nfs_clsubs.c index 80ab979d22d7..8bb51e29e1d1 100644 --- a/sys/fs/nfsclient/nfs_clsubs.c +++ b/sys/fs/nfsclient/nfs_clsubs.c @@ -188,7 +188,7 @@ ncl_getattrcache(struct vnode *vp, struct vattr *vaper) np = VTONFS(vp); vap = &np->n_vattr.na_vattr; nmp = VFSTONFS(vp->v_mount); - mustflush = nfscl_mustflush(vp); /* must be before mtx_lock() */ + mustflush = nfscl_nodeleg(vp, 0); /* must be before mtx_lock() */ NFSLOCKNODE(np); /* XXX n_mtime doesn't seem to be updated on a miss-and-reload */ timeo = (time_second - np->n_mtime.tv_sec) / 10; @@ -221,8 +221,8 @@ ncl_getattrcache(struct vnode *vp, struct vattr *vaper) (time_second - np->n_attrstamp), timeo); #endif - if ((time_second - np->n_attrstamp) >= timeo && - (mustflush != 0 || np->n_attrstamp == 0)) { + if (mustflush != 0 && (np->n_attrstamp == 0 || + time_second - np->n_attrstamp >= timeo)) { nfsstatsv1.attrcache_misses++; NFSUNLOCKNODE(np); KDTRACE_NFS_ATTRCACHE_GET_MISS(vp); diff --git a/sys/fs/nfsclient/nfs_clvnops.c b/sys/fs/nfsclient/nfs_clvnops.c index 76a3cdf9281e..13341dfc26e0 100644 --- a/sys/fs/nfsclient/nfs_clvnops.c +++ b/sys/fs/nfsclient/nfs_clvnops.c @@ -940,7 +940,7 @@ nfs_close(struct vop_close_args *ap) /* * Get attributes so "change" is up to date. */ - if (error == 0 && nfscl_mustflush(vp) != 0 && + if (error == 0 && nfscl_nodeleg(vp, 0) != 0 && vp->v_type == VREG && (VFSTONFS(vp->v_mount)->nm_flag & NFSMNT_NOCTO) == 0) { ret = nfsrpc_getattr(vp, cred, ap->a_td, &nfsva);