Re: sizeof PIPE_BUF
Nikola Vladov <[email protected]>
| Newsgroups | gmane.linux.lib.dietlibc |
|---|---|
| Message-ID | <[email protected]> |
On Sun, Feb 28, 2010 at 07:54:31PM +0100, Laurent Bercot wrote: > > Note that the PIPE_BUF macro is not meant to indicate the size of the > > kernel's pipe buffer. Check the SUS description of write() for the > > details of what PIPE_BUF means. The buffer's size must be at least > > PIPE_BUF to satisfy those requirements, but it may be larger. > > Indeed. And as far as I know, there's no strictly user-space way of > knowing the size of the pipe buffer. When I needed to do this, I had > to look deep into the Linux kernel headers, and didn't find anything > either (even the kernel-space PIPE_SIZE macro is defined as PAGE_SIZE > which is 4096). The 65536 value is probably hardcoded somewhere, but > it's obviously not meant to be accessed by a userspace program. > > I guess it's one of the "the specific value is none of your business" > cases, and strictly Single Unix-speaking, it's true; but with the > introduction of the splice() family of system calls, it's still > interesting to know that value. If Felix agrees, maybe he could > suggest it on lkml. As I understand the situation is the follows. In 2.6 kernels the size of the pipe is 64K. This means if the pipe (named or unnamed) is open from two processes one can write max 64K and the other can sleep during this time (not reading). The program I attached last time here show this. This means that we could find the PIPE_SIZE with an user space program! The problem is what is atomic write? The manpage pipe(7) says that any write <= PIPE_BUF is atomic (the pipe could be even O_NONBLOCK). Then the question is: is atomic write(fd, buf, n) if PIPE_BUF < n <= 64K (for example n == 12000). If someone know anything about this let me know. The splice(2) says aslo nothing for PIPE_BUF. I agree with Laurent! /nv