[Toybox] [PATCH] More use of sendfile.

enh enh at google.com
Sat Mar 14 22:44:43 PDT 2020


This patch started by removing the CAT_V config option and using FLAG(),
and switching to xsendfile() for the no-options fast path.

This pointed out that the 'x' in the xsendfile family was significantly
weaker than the usual guarantee, silently ignoring a variety of errors.
It also made me realize that xsendfile() wasn't actually utilizing
sendfile(2).

This patch removes sendfile_len (without the 'x') which only had one
user that wasn't checking for failure and looks like it should have used
the 'x' form instead. It also changes xsendfile_len() to take a boolean
argument to specify whether you want exactly that number of bytes (in
tar, say) or up to that many bytes (as in head, which this patch also
switches over to xsendfile).

All the cat, head, and tar tests pass (the cat test needed a minor
modification now the error message is slightly different, but the new
version of the test also passes with coreutils cat where the old one
didn't).

cat and head -c are significantly faster than they were, and are now
faster than coreutils. (coreutils doesn't use sendfile(2), it seems,
but was faster by virtue of using a 128KiB buffer than the 4KiB
toybuf/libbuf).
---
 lib/lib.h         |  3 +-
 lib/portability.c | 19 +++++++++++++
 lib/portability.h |  2 ++
 lib/xwrap.c       | 71 +++++++++++++++++++++++++++++------------------
 tests/cat.test    |  4 +--
 toys/posix/cat.c  | 64 ++++++++++++++++++++----------------------
 toys/posix/head.c | 14 ++++++----
 toys/posix/tar.c  |  3 +-
 8 files changed, 108 insertions(+), 72 deletions(-)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-More-use-of-sendfile.patch
Type: text/x-patch
Size: 11356 bytes
Desc: not available
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20200314/cdeeb203/attachment.bin>


More information about the Toybox mailing list