Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp249967pxt; Wed, 4 Aug 2021 21:44:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJylNpB53EVIIwpNZmvxuzXOFmTAiQ4IWeJcEIqbHeFimmiFE96DGeXtTLxjxA+UTISzgqgE X-Received: by 2002:a17:907:3d8f:: with SMTP id he15mr533149ejc.256.1628138689295; Wed, 04 Aug 2021 21:44:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628138689; cv=none; d=google.com; s=arc-20160816; b=FF1YpfTYhrVQYFVXKpaoreDdnmOQuhJsZe0J0cLX/sbA2Iuq20/PrqloWpNz3qS90r cRwUrEGm+gSA2m8OqTvESLqjwDSfJAluEKarlT+FW7dsODv+5rE/e3GfvlT4zVjEgj85 FkPSG4qAongAm6mdrs1cAD2kM+gJT/3UPytg8yB0gi69OVUWZnBEt2cPjxQ0+i9Ffroq 3wcsMAlae1ag/dP3Xwau3SLF6T7o7tLeuy9dhaR2NX+bOtGyUL1jfkohGL9EpoCwyPoG tccOtTEt/+9Xl5dhOf+KHG69Fp6C+78Bp4GK6uKK+n2HX5PHYgzjXGH4BkZ4wuS9FiAL N7kg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:message-id :mime-version:in-reply-to:references:to:subject:from:date :dkim-signature; bh=1xrWKh5TgmovRoSe4Y8HZf+3WeuagNCGYghLM3FUw6c=; b=cyAqpvO9ffuCxaeTBE4cnbBz8yAd+h0Wl7vtR/YCce/aCIxVwpvnREpeZxqpPaxkRl do3ZXDIvWoB71EUwFpl9kD/lFvwd00yWKS9b/2q+zmXCBlvJiEwjb6b/Ty1LJ3nBSKYQ MP+RyZy63yKFpfGD16AXtdJ46WxYHKg4lKKqn5ou4RVLpBpAslU4QKXbFUPka/lp+t+W 7MX46SCdvC0Ususf9EoHwVOBIq134204D3mPPCgLpNUFcUF9/opwWzY4F3GBa4P/iFFw Ex0QNybiAz5fenb7jpZYYKqrQR/GcWKorC2DfrbtwmR5Qva8mnvEV6frvREGqyWlxQ1I 7+Ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yahoo.ca header.s=s2048 header.b=OA9XeJt5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=yahoo.ca Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id rn6si4426103ejb.16.2021.08.04.21.44.25; Wed, 04 Aug 2021 21:44:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@yahoo.ca header.s=s2048 header.b=OA9XeJt5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=yahoo.ca Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237465AbhHEBdn (ORCPT + 99 others); Wed, 4 Aug 2021 21:33:43 -0400 Received: from sonic304-25.consmr.mail.gq1.yahoo.com ([98.137.68.206]:43231 "EHLO sonic304-25.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231964AbhHEBdl (ORCPT ); Wed, 4 Aug 2021 21:33:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.ca; s=s2048; t=1628127208; bh=1xrWKh5TgmovRoSe4Y8HZf+3WeuagNCGYghLM3FUw6c=; h=Date:From:Subject:To:References:In-Reply-To:From:Subject:Reply-To; b=OA9XeJt53xahUIh0EznnTR/n8hqoa+pyWqkIV1JrPl1A+YK1TxAUYRhDD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qEuTMrz7OuNA43cUgwTnt.MxFmqvd.RnbxUfbWL0KDS_B6p.sKqNBDLGc3w1i5 iVAmANcVinFoUwR_tKwDHoQoJDYIHRjnh0nU- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic304.consmr.mail.gq1.yahoo.com with HTTP; Thu, 5 Aug 2021 01:33:28 +0000 Received: by kubenode544.mail-prod1.omega.ne1.yahoo.com (VZM Hermes SMTP Server) with ESMTPA ID 0fb3b7ac0e701e905232dbd565dfae20; Thu, 05 Aug 2021 01:33:26 +0000 (UTC) Date: Wed, 04 Aug 2021 21:33:22 -0400 From: "Alex Xu (Hello71)" Subject: [PATCH] pipe: increase minimum default pipe size to 2 pages To: linux-kernel@vger.kernel.org References: <20210805000435.10833-1-alex_y_xu.ref@yahoo.ca> <20210805000435.10833-1-alex_y_xu@yahoo.ca> In-Reply-To: <20210805000435.10833-1-alex_y_xu@yahoo.ca> MIME-Version: 1.0 Message-Id: <1628127094.lxxn016tj7.none@localhost> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Mailer: WebService/1.1.18749 mail.backend.jedi.jws.acl:role.jedi.acl.token.atz.jws.hermes.yahoo Content-Length: 2488 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Before this patch, the following program prints 4096 and hangs. Afterwards, it prints 8192 and exits successfully. Note that you may need to increase your RLIMIT_NOFILE before running the program. int main() { int pipefd[2]; for (int i =3D 0; i < 1025; i++) if (pipe(pipefd) =3D=3D -1) return 1; size_t bufsz =3D fcntl(pipefd[1], F_GETPIPE_SZ); printf("%zd\n", bufsz); char *buf =3D calloc(bufsz, 1); write(pipefd[1], buf, bufsz); read(pipefd[0], buf, bufsz-1); write(pipefd[1], buf, 1); } Signed-off-by: Alex Xu (Hello71) --- See discussion at https://lore.kernel.org/lkml/1628086770.5rn8p04n6j.none@l= ocalhost/. Patch resend to linux-kernel@vger.kernel.org (typoed email last time).=20 Sorry if this messes up your mail clients. fs/pipe.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/fs/pipe.c b/fs/pipe.c index 9ef4231cce61..8e6ef62aeb1c 100644 --- a/fs/pipe.c +++ b/fs/pipe.c @@ -31,6 +31,21 @@ =20 #include "internal.h" =20 +/* + * New pipe buffers will be restricted to this size while the user is exce= eding + * their pipe buffer quota. The general pipe use case needs at least two + * buffers: one for data yet to be read, and one for new data. If this is = less + * than two, then a write to a non-empty pipe may block even if the pipe i= s not + * full. This can occur with GNU make jobserver or similar uses of pipes a= s + * semaphores: multiple processes may be waiting to write tokens back to t= he + * pipe before reading tokens: https://lore.kernel.org/lkml/1628086770.5rn= 8p04n6j.none@localhost/. + * + * Users can reduce their pipe buffers with F_SETPIPE_SZ below this at the= ir + * own risk, namely: pipe writes to non-full pipes may block until the pip= e is + * emptied. + */ +#define PIPE_MIN_DEF_BUFFERS 2 + /* * The max size that a non-root user is allowed to grow the pipe. Can * be set by root in /proc/sys/fs/pipe-max-size @@ -781,8 +796,8 @@ struct pipe_inode_info *alloc_pipe_info(void) user_bufs =3D account_pipe_buffers(user, 0, pipe_bufs); =20 if (too_many_pipe_buffers_soft(user_bufs) && pipe_is_unprivileged_user())= { - user_bufs =3D account_pipe_buffers(user, pipe_bufs, 1); - pipe_bufs =3D 1; + user_bufs =3D account_pipe_buffers(user, pipe_bufs, PIPE_MIN_DEF_BUFFERS= ); + pipe_bufs =3D PIPE_MIN_DEF_BUFFERS; } =20 if (too_many_pipe_buffers_hard(user_bufs) && pipe_is_unprivileged_user()) --=20 2.32.0