Pipe buffer size is 4k or 64k?

后端 未结 5 1844
轻奢々
轻奢々 2020-11-28 04:46

I read in multiple places that the default buffer size for a pipe is 4kB (for instance, here), and my ulimit -a tends to confirm that statement:



        
相关标签:
5条回答
  • 2020-11-28 04:53

    That's right. Since the 2.6.11 kernel, the pipe size in Linux is 64kB. Why ulimit reports it as 4Kb, I'm not sure, but that's wrong.

    0 讨论(0)
  • 2020-11-28 05:04

    In my experience, the single write test produced a total size of 65536, yet when I wrote 2700 at a time, I could only write 16 times, and then the next attempt stalls. I figure that the 'atomic' write needs to be within one 4K block, and that for each of my writes, it goes to the next full block to satisfy the request. So, in effect, the useable pipe size depends on the size of your writes.

    0 讨论(0)
  • 2020-11-28 05:04

    Looks like the kernel use up to 16 buffers which adds up to 64k. See this link for an explanation of the ulimit output vs actual buffer size

    0 讨论(0)
  • 2020-11-28 05:07

    The other answers tell you that the pipe size is 64 KB. The reason why PIPE_BUF is 4KB is that PIPE_BUF is the largest size for which writes are guaranteed to be atomic. See http://pubs.opengroup.org/onlinepubs/9699919799/functions/write.html

    0 讨论(0)
  • 2020-11-28 05:12

    It's programmable now


    As of Linux 2.6.35 you can use fcntl(2) with the F_SETPIPE_SZ operation to set the pipe buffer up to /proc/sys/fs/pipe-max-size. This is by default 1 MB; see proc(5).

    0 讨论(0)
提交回复
热议问题