NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

lib/55808: fread is inefficient in unbuffered mode

>Number:         55808
>Category:       lib
>Synopsis:       fread is inefficient in unbuffered mode
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Nov 16 20:30:00 +0000 2020
>Originator:     Roland Illig
>Release:        8.0
NetBSD 8.0 NetBSD 8.0 (GENERIC.PROF) #0: Sun May 17 14:12:24 UTC 2020 amd64
cat <<\EOF > fread-demo.c
#include <stdio.h>

int main(void)
        char buf[4096];

        setbuf(stdin, NULL);
        fread(buf, 1, 4096, stdin);
        return 0;

gcc --coverage fread-demo.c -o fread-demo

ktrace ./fread-demo < fread-demo

kdump | grep -w "RET.*read" | uniq -c

The output starts with 4096, which means that read(2) is called 4096 times to read a buffer of size 4096.  This is obviously inefficient.

I experienced this when running gcov in src/usr.bin/make.

cd src/usr.bin/make
USETOOLS=no make clean
time env USETOOLS=no USE_COVERAGE=yes make -s all test

This takes about 14 minutes.  Without the call to setbuf in gcov_open, it takes only 50 seconds.


The call to __srefill looks suspicious since that function does not get any information about how many bytes it should read.



Home | Main Index | Thread Index | Old Index