limits / PIPE_BUF?
Hi,
I was reading through the include/linux/limits.h file in order to generate a cleanup patch for it -- a large number of #defines within that file are no longer being used, as I surmise that they are simply remnants of earlier implementations.
A snippet from include/linux/limits.h:
#define PIPE_BUF 4096 /* # bytes in atomic write to a pipe */
PIPE_BUF is a bit of an oddity. It is defined there, then redefined in the arm header files, even though those header files are never included anywhere. Also, PIPE_BUF is never referenced by name in any of the Linux code. And yet, it is still being mentioned in some Big And Scary Warnings (tm): fs/autofs4/waitq.c or include/linux/pipe_fs_i.h, for example.
What's the deal with PIPE_BUF? Is its value used in the code indirectly, so that more comments would help make this fact obvious? Or is it now deprecated, and therefore a viable target for include/linux/limits.h cleanups?
- Vadim Lobanov
Quoted 10 lines · Vadim Lobanov
Hi,
I was reading through the
include/linux/limits.hfile in order to generate a cleanup patch for it -- a large number of #defines within that file are no longer being used, as I surmise that they are simply remnants of earlier implementations.A snippet from
include/linux/limits.h:
#definePIPE_BUF4096 /* # bytes in atomic write to a pipe */
Quoted 6 lines
PIPE_BUFis a bit of an oddity. It is defined there, then redefined in the arm header files, even though those header files are never included anywhere. Also,PIPE_BUFis never referenced by name in any of the Linux code. And yet, it is still being mentioned in some Big And Scary Warnings (tm):fs/autofs4/waitq.corinclude/linux/pipe_fs_i.h, for example.
it's for userland to tell it what the size of the atomic pipe operations we can do is.
Quoted 11 lines · Arjan van de Ven
Quoted 9 lines · Vadim Lobanov
A snippet from
include/linux/limits.h:
#definePIPE_BUF4096 /* # bytes in atomic write to a pipe */
PIPE_BUFis a bit of an oddity. It is defined there, then redefined in the arm header files, even though those header files are never included anywhere. Also,PIPE_BUFis never referenced by name in any of the Linux code. And yet, it is still being mentioned in some Big And Scary Warnings (tm):fs/autofs4/waitq.corinclude/linux/pipe_fs_i.h, for example.
Quoted 3 lines
it's for userland to tell it what the size of the atomic pipe operations we can do is.
How does userland get this value from the kernel? How does the kernel code ensure that this value is honored, considering that PIPE_BUF is not referenced in any of the pipe code?
- Vadim Lobanov
Quoted 4 lines · Vadim Lobanov
How does the kernel
code ensure that this value is honored, considering thatPIPE_BUFis not
referenced in any of the pipe code?
the kernel implementation guarantees one page basically, and on all architectures that I know of that's at least 4096 bytes
Quoted 10 lines · Arjan van de Ven
Quoted 4 lines · Vadim Lobanov
How does the kernel
code ensure that this value is honored, considering thatPIPE_BUFis not
referenced in any of the pipe code?the kernel implementation guarantees one page basically, and on all architectures that I know of that's at least 4096 bytes
Alright, so sounds like this constant should remain inside the include/linux/limits.h file. What about #defining it to be equal to PAGE_SIZE, like ARM (include/linux-arm/limits.h, for example) does?
- Vadim Lobanov
Quoted 9 lines · Vadim Lobanov
Quoted 7 lines · Arjan van de Ven
Quoted 4 lines · Vadim Lobanov
How does the kernel
code ensure that this value is honored, considering thatPIPE_BUFis not
referenced in any of the pipe code?
Quoted 7 lines
Quoted 3 lines
the kernel implementation guarantees one page basically, and on all architectures that I know of that's at least 4096 bytes
Alright, so sounds like this constant should remain inside the
include/linux/limits.hfile. What about #defining it to be equal toPAGE_SIZE, like ARM (include/linux-arm/limits.h, for example) does?
there is a certain elegance in providing the same value on all architectures; it means apps don't suddenly break if you port it to a "lesser" one. Also there is a problem with PAGE_SIZE itself, that's a config option on several architectures, so it'd have to be a define for get_page_size() or something, at which point you change semantics since apps can't do
char foo[PIPE_BUF];
anymore
Quoted 25 lines · Arjan van de Ven
Quoted 9 lines · Vadim Lobanov
Quoted 7 lines · Arjan van de Ven
Quoted 4 lines · Vadim Lobanov
How does the kernel
code ensure that this value is honored, considering thatPIPE_BUFis not
referenced in any of the pipe code?Quoted 7 lines
Quoted 3 lines
the kernel implementation guarantees one page basically, and on all architectures that I know of that's at least 4096 bytes
Alright, so sounds like this constant should remain inside the
include/linux/limits.hfile. What about #defining it to be equal toPAGE_SIZE, like ARM (include/linux-arm/limits.h, for example) does?there is a certain elegance in providing the same value on all architectures; it means apps don't suddenly break if you port it to a "lesser" one. Also there is a problem with
PAGE_SIZEitself, that's a config option on several architectures, so it'd have to be a define forget_page_size()or something, at which point you change semantics since apps can't do
Quoted 4 lines
char foo[PIPE_BUF];
anymore
Good point.
I suppose this means that the limits.h header file is used, either directly or indirectly, by both us (the kernel) and by user-space? If so, blech! What's the policy on keeping around config values that don't do anything inside the kernel anymore? The short list is:
NR_OPEN
ARG_MAX
CHILD_MAX
OPEN_MAX
LINK_MAX
MAX_CANON
MAX_INPUT
RTSIG_MAX
- Vadim Lobanov
Quoted 1 line · Vadim Lobanov wrote/
Hi,
Hi!
:
Quoted 7 lines
A snippet from
include/linux/limits.h:
#definePIPE_BUF4096 /* # bytes in atomic write to a pipe */
PIPE_BUFis a bit of an oddity. It is defined there, then redefined in the arm header files, even though those header files are never included anywhere.
Actually, here, on a 2.6.16 source code, PIPE_BUF is used in arch/sparc/kernel/sys_sunos.c, arch/sparc64/kernel/sys_sunos32.c, and arch/sparc64/solaris/fs.c . It seems it's some kind of compatibility value with Sun's OS...
Quoted 4 lines
Also,
PIPE_BUFis never referenced by name in any of the Linux code. And yet, it is still being mentioned in some Big And Scary Warnings (tm):fs/autofs4/waitq.corinclude/linux/pipe_fs_i.h, for example.
Maybe they wanted to say PIPE_BUFFERS ? (just wild guess)
c u,
Eric
Quoted 7 lines · Eric Piel
Quoted 1 line · Vadim Lobanov wrote/
Hi,
Hi!
Quoted 3 lines
A snippet from
include/linux/limits.h:
#definePIPE_BUF4096 /* # bytes in atomic write to a pipe */
Quoted 7 lines
Quoted 3 lines
PIPE_BUFis a bit of an oddity. It is defined there, then redefined in the arm header files, even though those header files are never included anywhere.Actually, here, on a 2.6.16 source code,
PIPE_BUFis used inarch/sparc/kernel/sys_sunos.c,arch/sparc64/kernel/sys_sunos32.c, andarch/sparc64/solaris/fs.c. It seems it's some kind of compatibility value with Sun's OS...
Yes, I saw those. But they're really just "magic numbers" that userland expects to see. In my opinion, the constant values should be inlined into that compat code. Or, at best, moved into the sparc compat header files.
Quoted 5 lines
Quoted 4 lines
Also,
PIPE_BUFis never referenced by name in any of the Linux code. And yet, it is still being mentioned in some Big And Scary Warnings (tm):fs/autofs4/waitq.corinclude/linux/pipe_fs_i.h, for example.Maybe they wanted to say
PIPE_BUFFERS? (just wild guess)
Doesn't look like it to me. PIPE_BUFFERS stands for something else entirely, if my understanding is correct. PIPE_BUF is the one that "guarantees" atomicity.
Quoted 3 lines
c u,
Eric
- Vadim Lobanov