From owner-dev-commits-src-all@freebsd.org Fri Jan 1 00:11:53 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 894E04D5E57; Fri, 1 Jan 2021 00:11:53 +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 "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4D6QS929Qxz4bYL; Fri, 1 Jan 2021 00:11:53 +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 3BCEE193FA; Fri, 1 Jan 2021 00:11:53 +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 1010BrCO005858; Fri, 1 Jan 2021 00:11:53 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1010BrGn005857; Fri, 1 Jan 2021 00:11:53 GMT (envelope-from git) Date: Fri, 1 Jan 2021 00:11:53 GMT Message-Id: <202101010011.1010BrGn005857@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mateusz Guzik Subject: git: 1d6eb976774a - main - cache: save on branching when parsing the path by inserting a sentinel 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/main X-Git-Reftype: branch X-Git-Commit: 1d6eb976774af6a84414a6785217b305021ce841 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: Fri, 01 Jan 2021 00:11:53 -0000 The branch main has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=1d6eb976774af6a84414a6785217b305021ce841 commit 1d6eb976774af6a84414a6785217b305021ce841 Author: Mateusz Guzik AuthorDate: 2020-12-28 06:33:12 +0000 Commit: Mateusz Guzik CommitDate: 2021-01-01 00:10:42 +0000 cache: save on branching when parsing the path by inserting a sentinel Tested by: pho --- sys/kern/vfs_cache.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/sys/kern/vfs_cache.c b/sys/kern/vfs_cache.c index 7f9339d2ed56..c9b0010020f8 100644 --- a/sys/kern/vfs_cache.c +++ b/sys/kern/vfs_cache.c @@ -4741,15 +4741,24 @@ cache_fplookup_parse(struct cache_fpl *fpl) cnp = fpl->cnp; /* - * Search a new directory. + * Find the end of this path component, it is either / or nul. * - * The last component of the filename is left accessible via - * cnp->cn_nameptr for callers that need the name. Callers needing - * the name set the SAVENAME flag. When done, they assume - * responsibility for freeing the pathname buffer. + * Store / as a temporary sentinel so that we only have one character + * to test for. Pathnames tend to be short so this should not be + * resulting in cache misses. */ - for (cp = cnp->cn_nameptr; *cp != 0 && *cp != '/'; cp++) + KASSERT(cnp->cn_nameptr[ndp->ni_pathlen - 1] == '\0', + ("%s: expected nul at %p + %zu; string [%s]\n", __func__, + cnp->cn_nameptr, ndp->ni_pathlen - 1, cnp->cn_nameptr)); + cnp->cn_nameptr[ndp->ni_pathlen - 1] = '/'; + for (cp = cnp->cn_nameptr; *cp != '/'; cp++) { + KASSERT(*cp != '\0', + ("%s: encountered unexpected nul; string [%s]\n", __func__, + cnp->cn_nameptr)); continue; + } + cnp->cn_nameptr[ndp->ni_pathlen - 1] = '\0'; + cnp->cn_namelen = cp - cnp->cn_nameptr; if (__predict_false(cnp->cn_namelen > NAME_MAX)) { cache_fpl_smr_exit(fpl);