From eb45f683771506bbaa2584e5f78798a8790764f2 Mon Sep 17 00:00:00 2001 From: Jake Abendroth Date: Mon, 19 Oct 2026 17:11:02 -0700 Subject: [PATCH] uucore: skip the pipe resize for small send_n_bytes copies again #15086 had send_n_bytes size every new pipe at 1 MiB, adding an fcntl to small copies like head -c 10. Only resize when the copy is larger than the default pipe size, as before. Co-authored-by: oech3 <79379754+oech3@users.noreply.github.com> --- src/uucore/src/lib/features/pipes.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/uucore/src/lib/features/pipes.rs b/src/uucore/src/lib/features/pipes.rs index aa135a46e39..83918ce67d9 100644 --- a/src/uucore/src/lib/features/pipes.rs +++ b/src/uucore/src/lib/features/pipes.rs @@ -149,12 +149,20 @@ pub fn splice_unbounded_auto(source: &impl AsFd, dest: &mut impl AsFd) -> Splice #[inline] pub fn send_n_bytes(input: impl AsFd, target: impl AsFd, n: u64) -> std::io::Result { let pipe_size = n.min(MAX_ROOTLESS_PIPE_SIZE as u64) as usize; + let resize = pipe_size > KERNEL_DEFAULT_PIPE_SIZE; // improve throughput if output is pipe // expected that input is already extended if it is coming from splice - if pipe_size > KERNEL_DEFAULT_PIPE_SIZE { + if resize { let _ = fcntl_setpipe_size(&target, pipe_size); } - let Ok((broker_r, broker_w)) = PIPE_CACHE.take().map_or_else(pipe::, Ok) else { + let Some((broker_r, broker_w)) = PIPE_CACHE.take().or_else(|| { + // use std::io::pipe to avoid fcntl when it is not useful + let pair = std::io::pipe().ok()?; + if resize { + let _ = fcntl_setpipe_size(&pair.0, pipe_size); + } + Some(pair) + }) else { return std::io::copy(&mut RawReader(input).take(n), &mut RawWriter(target)); }; let mut n = n;