From: cheloha Date: Mon, 13 Dec 2021 18:33:23 +0000 (+0000) Subject: tee(1): increase I/O buffer size from 8KB to 64KB X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=e64ad945c73202db544260c894375b91756a7554;p=openbsd tee(1): increase I/O buffer size from 8KB to 64KB 64KB strikes a good balance between space and time on today's machines. Buffers smaller than 64KB waste more time in userspace traveling to and from the kernel. Buffers larger than 64KB do I/O a bit faster, but the performance improvements rapidly diminish at a steep memory cost. Discussed with millert@ and deraadt@. Positive feedback from Geoff Steckel. Thread: https://marc.info/?l=openbsd-tech&m=163737586414354&w=2 ok millert@ deraadt@ --- diff --git a/usr.bin/tee/tee.c b/usr.bin/tee/tee.c index 826aeaa9ca8..0ead1771d19 100644 --- a/usr.bin/tee/tee.c +++ b/usr.bin/tee/tee.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tee.c,v 1.13 2021/11/21 16:15:43 cheloha Exp $ */ +/* $OpenBSD: tee.c,v 1.14 2021/12/13 18:33:23 cheloha Exp $ */ /* $NetBSD: tee.c,v 1.5 1994/12/09 01:43:39 jtc Exp $ */ /* @@ -43,6 +43,8 @@ #include #include +#define BSIZE (64 * 1024) + struct list { SLIST_ENTRY(list) next; int fd; @@ -69,7 +71,7 @@ main(int argc, char *argv[]) int fd; ssize_t n, rval, wval; int append, ch, exitval; - char buf[8192]; + char *buf; if (pledge("stdio wpath cpath", NULL) == -1) err(1, "pledge"); @@ -109,7 +111,10 @@ main(int argc, char *argv[]) if (pledge("stdio", NULL) == -1) err(1, "pledge"); - while ((rval = read(STDIN_FILENO, buf, sizeof(buf))) > 0) { + buf = malloc(BSIZE); + if (buf == NULL) + err(1, NULL); + while ((rval = read(STDIN_FILENO, buf, BSIZE)) > 0) { SLIST_FOREACH(p, &head, next) { for (n = 0; n < rval; n += wval) { wval = write(p->fd, buf + n, rval - n); @@ -121,6 +126,7 @@ main(int argc, char *argv[]) } } } + free(buf); if (rval == -1) { warn("read"); exitval = 1;