Is BUFSIZ too small ?

Matthew Dillon dillon at apollo.backplane.com
Mon Jan 19 13:11:39 PST 2004


:I noticed that we still have BUFSIZ in stdio.h defined to only 1024,
:and wonder if that should be increased these days.
:
:Is there anybody who could devise and run some benchmarks to find
:out what effect it would have to increase it to for instance 4096 ?
:
:-- 
:Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
:phk at FreeBSD.ORG         | TCP/IP since RFC 956

    STDIO uses st.st_blksize sized I/O buffers by default, which will be
    either 8K or 16K on most machines.

    Very few programs use BUFSIZ for the actual I/O ops but libc seems
    to use it for stack-declared buffers (e.g. like in 
    /usr/src/lib/libc/net/getservent.c, net/name6.c, net/gethostnamadr.c,
    etc).  vprintf uses it but I doubt that would impact performance.l
    Unbuffered FILE I/O (setvbuf SNBF) will cause writes to be broken 
    down into BUFSIZ chunks... but who uses unbuffered I/O in that manner?
    Not very many programs I would wager.

    So, just at a guess, raising BUFSIZ could lead to unnecessary dirty
    page bloat in most programs and would otherwise not improve performance.

    It might be worth seeing what stdout's behavior is when the program 
    output runs through a pipe.  If it is dropping down to BUFSIZ for pipes 
    it might be worth fixing __swhatbuf() in stdio/makebuf.c, but I still 
    wouldn't bother with BUFSIZ.

					-Matt
					Matthew Dillon 
					<dillon at backplane.com>


More information about the freebsd-current mailing list