-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would it be possible to add unit tests in this file ? thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh yeah
#[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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please document these "magic numbers"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
damn not the author of this 😄 hmm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from here src/uu/cat/src/splice.rs ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah. it's taken from there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, leave it like this then :)
I will have a look
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure sure
|
||
/// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.