diff options
author | H. Peter Anvin <hpa@zytor.com> | 2016-02-01 02:39:07 -0800 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2016-02-01 02:41:00 -0800 |
commit | cf9c7d2382eadc5699d3e4032b3e1774eccc36da (patch) | |
tree | 5ffd6e3c9e8f0995c09adcdc74e8a936508fad07 | |
parent | 17fabd540aeb5019909a024243c6d26610cab307 (diff) | |
download | klibc-cf9c7d2382eadc5699d3e4032b3e1774eccc36da.tar.gz |
[klibc] fwrite: flush before a large write to allow better bypass
If we are doing a large write, flush the buffer preemptively, so we
don't end up double-buffering a sequence of BUFSIZ writes simply
because we started out with something in the buffer.
This doesn't increase the number of system calls, since we will always
need to do two system calls in this case.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
-rw-r--r-- | usr/klibc/stdio/fwrite.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/usr/klibc/stdio/fwrite.c b/usr/klibc/stdio/fwrite.c index 71ee75cc95892e..feb48efbafa79b 100644 --- a/usr/klibc/stdio/fwrite.c +++ b/usr/klibc/stdio/fwrite.c @@ -14,14 +14,15 @@ static size_t fwrite_noflush(const void *buf, size_t count, ssize_t rv; while (count) { - if (f->ibytes || f->obytes >= f->bufsiz) + if (f->ibytes || f->obytes >= f->bufsiz || + (f->obytes && count >= f->bufsiz)) if (__fflush(f)) break; - if (f->obytes == 0 && count >= f->bufsiz) { + if (count >= f->bufsiz) { /* - * The buffer is empty and the write is large, - * so bypass the buffering entirely. + * The the write is large, so bypass + * buffering entirely. */ rv = write(f->pub._IO_fileno, p, count); if (rv == -1) { |