From nobody Wed Aug 17 14:23:51 2022 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 4M79HX2cggz4ZZG8; Wed, 17 Aug 2022 14:23: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 4M79HX16PLz3PF6; Wed, 17 Aug 2022 14:23:52 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660746232; 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=FEqa0fK5efZhH/YGAL3IP8zymtx3AHE5EEtIri8EPCE=; b=ZTSeOfNymnG0kotJUsoJ02Iz0RczUhVW7iwYYSgoT4sW0+cGM2hB6KwgRv2wnBprlHQFyS bLhXJbjBzX97ssLgttK6QEGXfbVHZffVg0K8IrSbDNEsfTtvirQHDGV3QdBllPtxxd9NMI IJei1DxS3IYbpsQ8MaWMwq+Mbzt0PeroMJMCmHsVURsYTUJS7nDbPIpY9Gq/mg340JxIL5 Kl1N2lIwNAjKysZgYiUJ838U5PoXHbdTyb44U1rPi1iaqcxfz9dI+pLgYEJCrjwUFEGF1c RXntyD6Vaj2i4Uh25rst7oyPHIYIxQLgLniaF6yHnoUdtlOy2hITX3+595y69w== 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 4M79HX0CbPzsQC; Wed, 17 Aug 2022 14:23:52 +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 27HENpP7024624; Wed, 17 Aug 2022 14:23:51 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 27HENpvp024623; Wed, 17 Aug 2022 14:23:51 GMT (envelope-from git) Date: Wed, 17 Aug 2022 14:23:51 GMT Message-Id: <202208171423.27HENpvp024623@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: 9ac6eda6c6a3 - main - pipe: try to skip locking the pipe if a non-blocking fd is used 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: 9ac6eda6c6a36db6bffa01be7faea24f8bb92a0f Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660746232; 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=FEqa0fK5efZhH/YGAL3IP8zymtx3AHE5EEtIri8EPCE=; b=yHDCDFanT79I3jQ4xaK60Pbs0zrRAOrkp69kn/7v4zFPCU2d4ja6+x3fTVfcn91cJDEH15 zkqZIRUu1c1zpMtvfeTMafOXQfjv7TzMBRx80HgHn3hjxmZESVjYQ5RqXPWN3D1yoNOB0P l+YPHHr8fPg69TipFM0xStGiOmrxZciCimrZ3zRqxufACYzOYAdS5mMoejRkYjMG3wredh WF3H8hc+ocEFwPZROqslng6p5Rrw/87fsxj+1wAKutagPQyb4HUp2v4moAZ+SKWeLwhXvU /DnoAiqpES/yKKoYjvVrEQajkacjwbJZm4VZ637Oo/655QmAYbhQVzQe1iSubA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1660746232; a=rsa-sha256; cv=none; b=o2C+t08dh3exgbgS5/+6sqAYqO28Uy/4EVQkLrKycCnWTTp7Vdcipkz4aRrtjT3TN283M4 AnIqEeLrPArUiAbysag3vU+XWcB4TBOEnG01ujFP9B0L1exB67+36BoX1MXN8+zRxvCPEs oBcaXdkLIGsVGCq7EUBto11uP6VN+0FNPTvLVncj0oEeMDYvtKsjY8VZVbKkUMf04VFmQJ +x9hrFh9GYwbIfXD6/XSHnTMuywplTN/EINorH689mxwGLgY9qJ38u84YeyZcQIaJgtxgu sAYpqZDqfKtI6X3arwZjfHT3p3m69sbIgEedCOzIgucuQNsunML0Yk59y80PfA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=9ac6eda6c6a36db6bffa01be7faea24f8bb92a0f commit 9ac6eda6c6a36db6bffa01be7faea24f8bb92a0f Author: Mateusz Guzik AuthorDate: 2022-08-08 18:02:15 +0000 Commit: Mateusz Guzik CommitDate: 2022-08-17 14:23:34 +0000 pipe: try to skip locking the pipe if a non-blocking fd is used Reviewed by: markj (previous version) Differential Revision: https://reviews.freebsd.org/D36082 --- sys/kern/sys_pipe.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/sys/kern/sys_pipe.c b/sys/kern/sys_pipe.c index d9e7d97d01e1..f9060ba2c8a6 100644 --- a/sys/kern/sys_pipe.c +++ b/sys/kern/sys_pipe.c @@ -721,6 +721,26 @@ pipe_read(struct file *fp, struct uio *uio, struct ucred *active_cred, int size; rpipe = fp->f_data; + + /* + * Try to avoid locking the pipe if we have nothing to do. + * + * There are programs which share one pipe amongst multiple processes + * and perform non-blocking reads in parallel, even if the pipe is + * empty. This in particular is the case with BSD make, which when + * spawned with a high -j number can find itself with over half of the + * calls failing to find anything. + */ + if ((fp->f_flag & FNONBLOCK) != 0 && !mac_pipe_check_read_enabled()) { + if (__predict_false(uio->uio_resid == 0)) + return (0); + if ((atomic_load_short(&rpipe->pipe_state) & PIPE_EOF) != 0) + return (0); + if (atomic_load_int(&rpipe->pipe_buffer.cnt) == 0 && + atomic_load_int(&rpipe->pipe_pages.cnt) == 0) + return (EAGAIN); + } + PIPE_LOCK(rpipe); ++rpipe->pipe_busy; error = pipelock(rpipe, 1);