[PATCH] manual: Drop incorrect statement on PIPE_BUF and blocking writes

Štěpán Němec stepnem@smrk.net
Mon Mar 25 08:59:27 GMT 2024


Typical Linux defaults are 4096 bytes of PIPE_BUF and 65536 bytes of
kernel pipe buffer; the latter, not the former, limits the amount
of data writable without blocking.  E.g., observe the different
behavior of the following two command lines (assuming the above
defaults):

{ dd if=/dev/zero bs=65536 count=1 2>/dev/null;
  echo 'all written' >&2; } |
    { sleep 1; wc -c; }

{ dd if=/dev/zero bs=65537 count=1 2>/dev/null;
  echo 'all written' >&2; } |
    { sleep 1; wc -c; }

Only the latter waits 1s before printing 'all written', due to the
number of bytes being written exceeding the kernel pipe buffer.
PIPE_BUF (still only 4096 bytes) is irrelevant here.

>From pipe(7):

  Before  Linux 2.6.11, the capacity of a pipe was the same as the system
  page size (e.g., 4096 bytes on i386).  Since Linux 2.6.11, the pipe ca‐
  pacity  is 16 pages (i.e., 65,536 bytes in a system with a page size of
  4096 bytes).  Since Linux 2.6.35,  the  default  pipe  capacity  is  16
  pages,  but  the  capacity  can  be  queried and set using the fcntl(2)
  F_GETPIPE_SZ and F_SETPIPE_SZ operations.  See fcntl(2) for more infor‐
  mation.
---
 manual/pipe.texi | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/manual/pipe.texi b/manual/pipe.texi
index 483c40c5c3dd..8a9a275cafe7 100644
--- a/manual/pipe.texi
+++ b/manual/pipe.texi
@@ -312,8 +312,7 @@
 
 Reading or writing a larger amount of data may not be atomic; for
 example, output data from other processes sharing the descriptor may be
-interspersed.  Also, once @code{PIPE_BUF} characters have been written,
-further writes will block until some characters are read.
+interspersed.
 
 @xref{Limits for Files}, for information about the @code{PIPE_BUF}
 parameter.

base-commit: dc1a77269c971652a8a5167ec366792eae052e65
-- 
2.44.0



More information about the Libc-alpha mailing list