uucore: add common splice-write functionality#6964
Conversation
| /// The `bool` in the result value indicates if we need to fall back to normal | ||
| /// copying or not. False means we don't have to. | ||
| #[inline] | ||
| pub fn write_fast_using_splice<R: Read + AsFd + AsRawFd, S: AsRawFd + AsFd>( |
There was a problem hiding this comment.
would it be possible to add unit tests in this file ? thanks
| #[cfg(any(target_os = "linux", target_os = "android"))] | ||
| use crate::pipes::{pipe, splice, splice_exact}; | ||
|
|
||
| const SPLICE_SIZE: usize = 1024 * 128; |
There was a problem hiding this comment.
please document these "magic numbers"
There was a problem hiding this comment.
damn not the author of this 😄 hmm
There was a problem hiding this comment.
from here src/uu/cat/src/splice.rs ?
There was a problem hiding this comment.
yeah. it's taken from there
There was a problem hiding this comment.
ok, leave it like this then :)
I will have a look
|
|
||
| /// Move exactly `num_bytes` bytes from `read_fd` to `write_fd`. | ||
| /// | ||
| /// Panics if not enough bytes can be read. |
There was a problem hiding this comment.
not sure panic is the right thing to do here.
we probably want to return an error
| pub fn write_fast_using_splice<R: Read + AsFd + AsRawFd, S: AsRawFd + AsFd>( | ||
| handle: &R, | ||
| write_fd: &S, | ||
| ) -> nix::Result<(usize, bool)> { |
There was a problem hiding this comment.
would it be possible to use UError https://docs.rs/uucore/0.0.28/uucore/error/trait.UError.html ?
|
GNU testsuite comparison: |
|
huh, i just realized that
it is, however, subject to change. should we keep the reimplementation? |
|
Interesting! did you do some benchmarking ? |
|
nope, not yet. that's sounds interesting to do, i will see which one performs better |
|
it seems like the reimplementation using splice wins here, at least on my linux machine i did some tests on Reimplementation, 100 runs:
using
could be related to the chunk size |
|
you should use hyperfine for benchmarking :) |
|
Oh yeah i did, or.. i'm supposed to just pass the commands to hyperfine directly? |
|
tried more reimplementation, 1G chunk, /dev/zero to file (100 runs):
reimplementation, 1G chunk, file to file (100 runs):
i took a look at the implementation of set that to my splice and..
it's a biiit slower. But still faster than using i traced the syscalls made for both and both seem to be using |
2bf5075 to
0d92ff6
Compare
|
GNU testsuite comparison: |
|
could you please properly rebase your patches? the diff is showing unrelated changes |
|
yeah yeah idk why i messed up the branch |
Splice is a Linux-specific syscall that allows direct data copying from
one file descriptor to another without user-space buffer. As of now, this
is used by `cp`, `cat`, and `install` when compiled for Linux and Android.
0d92ff6 to
625c49d
Compare
|
ok there |
|
GNU testsuite comparison: |
|
thanks |
Splice is a Linux-specific syscall that allows direct data copying from one file descriptor to another without user-space buffer. This can be used by several utilities to perform optimized copy under Linux and Android.