From nobody Sun Nov 19 22:25:51 2023 X-Original-To: dev-commits-src-all@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 4SYQFr0Fflz51RBh; Sun, 19 Nov 2023 22:25:52 +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 4SYQFq6rMfz3Tjm; Sun, 19 Nov 2023 22:25:51 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1700432752; 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=m5OQvLSa2VJjiac7R/DY7/8vkQiDerQAlv7ZupT79f8=; b=um/cZ42zN5waot7SH/sWWo4yxP/Uzeuszeaoalt27JJqx+uUO7AkXlg7jnRtvVYhiusVnS CjGFIgN6SU14CqvzuA5Cb98+h6xxe8gi1ATE9wD7Oim15N4pCzcZ2gZFEAAWoTaTVXzqvQ a/8YogN7z5i1TU795NGLx1Of23Tp/mggHBVZHqlMv7IwHqfvJD7LVqW+SKTw2j4GXpYCkR MKuoSc7Pbq7L05oNvfjBJifoIMcWpBCwvYLvaXVkfOlJQA8fFX0mNFYB+KCcQ4nR+H9JFq EwdEtS3PrTxjtsM4KlnmtQQdSoeTQKwAwFWjdfTg4cdWqNlBZkc9+O20oM2Arg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1700432752; 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=m5OQvLSa2VJjiac7R/DY7/8vkQiDerQAlv7ZupT79f8=; b=k8tRl6Yoyh4ltCL/lH/Yy14x6Ey7Ko8wfkMpLxzonAD3DuupBTmVXv5/zmjC82LUKQVP8p hO2/3gtWqfjvpLguzrd43rJWJIwaLklwmKB9H3C66VpGGM+Jp5D+cnVu3DKlxdrDIU3Fv7 jKgAvf41tIeLfvky/It6fRPX0iShEnpP0n0UE8q9QQOkl3+o5lx0t/GtT39T62NuDnggnh dtSicHV7Unj5Mn4m0GOG1RxwgMXV/YgmxAHWWQjw95c6KpygC1rnRIotfP206ZituM7uvQ qMn3SGI5AT5hKSHMZZ1+qvOFK3dv6nv9g/0i81seD46orYAvgUTos8YqeBsBzQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1700432752; a=rsa-sha256; cv=none; b=pc2b/cnRaC/TBUmeN9Nx1o8bFTMNN/m+q1lN4XzQ3DgYZOD2CzndJaUunbr7VuW8sueM4/ y3zgZcc6EWDihRaL96CWA+ZKjVfoCRLjq0jc22jcm3KxuplMjkqUEz5nA+X71TzsVXFqrS oV8tX59Lw0jjfRo4q0QhM9mK38W/j2xq701msONXB8cksx9wRa7I4KW9SJAJzYzD6UUkxV sylSfU6g2HA0JNzyf6Q1mV49m3A6xmYJmCGpVxwFe+Z2Ah6zx4Vc4W3OsPuT6xZekCRLeO CqB6Rw3VGT8OXer8j19b+D8BjNbys35TOmrz//4V/DKBze/icthTkkJMA/T0eA== 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 4SYQFq5vn4zCBt; Sun, 19 Nov 2023 22:25:51 +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 3AJMPpeB019362; Sun, 19 Nov 2023 22:25:51 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3AJMPprx019359; Sun, 19 Nov 2023 22:25:51 GMT (envelope-from git) Date: Sun, 19 Nov 2023 22:25:51 GMT Message-Id: <202311192225.3AJMPprx019359@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: 305a2676ae93 - main - vfs: dodge locking for lseek(fd, 0, SEEK_CUR) List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org 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: 305a2676ae93fb50a623024d51039415521cb2da Auto-Submitted: auto-generated The branch main has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=305a2676ae93fb50a623024d51039415521cb2da commit 305a2676ae93fb50a623024d51039415521cb2da Author: Mateusz Guzik AuthorDate: 2023-11-19 22:23:20 +0000 Commit: Mateusz Guzik CommitDate: 2023-11-19 22:25:45 +0000 vfs: dodge locking for lseek(fd, 0, SEEK_CUR) It is very common and according to dtrace while running poudriere almost all calls with SEEK_CUR pass 0. --- sys/kern/vfs_vnops.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c index f81516608eeb..4669296750e4 100644 --- a/sys/kern/vfs_vnops.c +++ b/sys/kern/vfs_vnops.c @@ -828,6 +828,13 @@ foffset_unlock(struct file *fp, off_t val, int flags) sleepq_broadcast(&fp->f_vnread_flags, SLEEPQ_SLEEP, 0, 0); sleepq_release(&fp->f_vnread_flags); } + +static off_t +foffset_read(struct file *fp) +{ + + return (atomic_load_long(&fp->f_offset)); +} #else off_t foffset_lock(struct file *fp, int flags) @@ -876,6 +883,13 @@ foffset_unlock(struct file *fp, off_t val, int flags) } mtx_unlock(mtxp); } + +static off_t +foffset_read(struct file *fp) +{ + + return (foffset_lock(fp, FOF_NOLOCK)); +} #endif void @@ -2647,8 +2661,19 @@ vn_seek(struct file *fp, off_t offset, int whence, struct thread *td) cred = td->td_ucred; vp = fp->f_vnode; - foffset = foffset_lock(fp, 0); noneg = (vp->v_type != VCHR); + /* + * Try to dodge locking for common case of querying the offset. + */ + if (whence == L_INCR && offset == 0) { + foffset = foffset_read(fp); + if (__predict_false(foffset < 0 && noneg)) { + return (EOVERFLOW); + } + td->td_uretoff.tdu_off = foffset; + return (0); + } + foffset = foffset_lock(fp, 0); error = 0; switch (whence) { case L_INCR: