From c14925fcb047758c6c1c7c1f846ce7e7fc3ba973 Mon Sep 17 00:00:00 2001 From: oech3 <79379754+oech3@users.noreply.github.com> Date: Fri, 24 Apr 2026 17:28:39 +0900 Subject: [PATCH] tail: improve throughput for -c N file --- src/uu/tail/src/tail.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/uu/tail/src/tail.rs b/src/uu/tail/src/tail.rs index c38a146ba36..a51fee1c626 100644 --- a/src/uu/tail/src/tail.rs +++ b/src/uu/tail/src/tail.rs @@ -576,6 +576,7 @@ fn unbounded_tail(reader: &mut BufReader, settings: &Settings) -> UR } // Print the target section of the file +// use zero-copy on Linux fn print_target_section< #[cfg(any(target_os = "linux", target_os = "android"))] R: Read + rustix::fd::AsFd, #[cfg(not(any(target_os = "linux", target_os = "android")))] R: Read, @@ -586,10 +587,14 @@ fn print_target_section< let stdout = stdout(); let mut stdout = stdout.lock(); if let Some(limit) = limit { - let mut reader = file.take(limit); - io::copy(&mut reader, &mut stdout)?; + #[cfg(any(target_os = "linux", target_os = "android"))] + uucore::pipes::send_n_bytes(file, &mut stdout, limit)?; + #[cfg(not(any(target_os = "linux", target_os = "android")))] + { + let mut reader = file.take(limit); + io::copy(&mut reader, &mut stdout)?; + } } else { - // zero-copy fast-path #[cfg(any(target_os = "linux", target_os = "android"))] if uucore::pipes::splice_unbounded_broker(file, &mut stdout)? { io::copy(file, &mut stdout)?;