tail: avoid unnecessary pipe2 syscall for empty files#12465
Conversation
|
Does this require additional stat or other syscall? I'm not sure which syscall is cheap, but I thins this is not needed considering usage for 0-sized file is very rare. |
|
Compared full syscall counts with Empty file (
No new syscalls added. Non-empty file:
No overhead for the common case. |
|
GNU testsuite comparison: |
Are /dev/sd* and /dev/nvme* missing splice driver yet? I saw |
tested on /dev/nvme0n1, splice is called successfully, so block devices do support it |
| /// For regular files, checks position against file length. | ||
| /// For char/block devices, probes by reading one byte; if data exists, writes | ||
| /// it to `out` so it isn't lost (char devices don't support seeking back). | ||
| #[allow(unused_variables)] |
There was a problem hiding this comment.
please remove this allow
Fixes #12464
bounded_tailcallsprint_target_sectionunconditionally, which createsa broker pipe via
splice_unbounded_brokereven when the file is empty orexhausted, causing an unnecessary
pipe2syscall.Added
is_file_exhaustedto check before callingprint_target_section:it directly to stdout since char devices don't support seeking back
Before:
strace -c -e pipe,pipe2 tail -c +1 /dev/null → 1 pipe2 call
After:
strace -c -e pipe,pipe2 tail -c +1 /dev/null → 0 pipe2 calls