klibc-bot for H. Peter Anvin
2016-Feb-01 10:42 UTC
[klibc] [klibc:master] fwrite: flush before a large write to allow better bypass
Commit-ID: cf9c7d2382eadc5699d3e4032b3e1774eccc36da Gitweb: http://git.kernel.org/?p=libs/klibc/klibc.git;a=commit;h=cf9c7d2382eadc5699d3e4032b3e1774eccc36da Author: H. Peter Anvin <hpa at zytor.com> AuthorDate: Mon, 1 Feb 2016 02:39:07 -0800 Committer: H. Peter Anvin <hpa at zytor.com> CommitDate: Mon, 1 Feb 2016 02:41:00 -0800 [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 at zytor.com> --- usr/klibc/stdio/fwrite.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/usr/klibc/stdio/fwrite.c b/usr/klibc/stdio/fwrite.c index 71ee75c..feb48ef 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) {