From 1f45676f595d36153bb3019c6abb6999299f1660 Mon Sep 17 00:00:00 2001 From: oech3 <79379754+oech3@users.noreply.github.com> Date: Sat, 4 Apr 2026 03:15:39 +0900 Subject: [PATCH] cp: improve throughput with pipe input --- src/uucore/src/lib/features/buf_copy/linux.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/uucore/src/lib/features/buf_copy/linux.rs b/src/uucore/src/lib/features/buf_copy/linux.rs index 1048def2a..3f7768794 100644 --- a/src/uucore/src/lib/features/buf_copy/linux.rs +++ b/src/uucore/src/lib/features/buf_copy/linux.rs @@ -7,7 +7,7 @@ use crate::{ error::UResult, - pipes::{pipe, splice, splice_exact}, + pipes::{MAX_ROOTLESS_PIPE_SIZE, pipe, splice, splice_exact}, }; /// Buffer-based copying utilities for unix (excluding Linux). @@ -28,7 +28,6 @@ pub trait FdWritable: Write + AsFd + AsRawFd {} impl FdWritable for T where T: Write + AsFd + AsRawFd {} -const SPLICE_SIZE: usize = 1024 * 128; const BUF_SIZE: usize = 1024 * 16; /// Conversion from a `rustix::io::Errno` into our `Error` which implements `UError`. @@ -92,9 +91,14 @@ where { let (pipe_rd, pipe_wr) = pipe()?; let mut bytes: u64 = 0; + // improve throughput + // no need to increase pipe size of input fd since + // - sender with splice probably increased size already + // - sender without splice is bottleneck + let _ = rustix::pipe::fcntl_setpipe_size(dest, MAX_ROOTLESS_PIPE_SIZE); loop { - match splice(&source, &pipe_wr, SPLICE_SIZE) { + match splice(&source, &pipe_wr, MAX_ROOTLESS_PIPE_SIZE) { Ok(n) => { if n == 0 { return Ok((bytes, false));