Skip to content

Commit c4e9883

Browse files
committed
cat: avoid fcntl with smaller files
1 parent cbc0c78 commit c4e9883

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/uu/cat/src/splice.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ pub(super) fn write_fast_using_splice<R: FdReadable, S: AsRawFd + AsFd>(
2424
write_fd: &S,
2525
) -> CatResult<bool> {
2626
use nix::fcntl::{FcntlArg, fcntl};
27-
// improve performance
28-
if fcntl(
29-
write_fd,
30-
FcntlArg::F_SETPIPE_SZ(MAX_ROOTLESS_PIPE_SIZE as i32),
31-
)
32-
.is_ok()
33-
{
27+
const FIRST_PIPE_SIZE: usize = 64 * 1024;
28+
if splice(&handle.reader, &write_fd, FIRST_PIPE_SIZE).is_ok() {
29+
// fcntl improves performance for large file which is large overhead for small files
30+
let _ = fcntl(
31+
write_fd,
32+
FcntlArg::F_SETPIPE_SZ(MAX_ROOTLESS_PIPE_SIZE as i32),
33+
);
3434
loop {
3535
match splice(&handle.reader, &write_fd, MAX_ROOTLESS_PIPE_SIZE) {
36-
Ok(1..) => {},
36+
Ok(1..) => {}
3737
Ok(0) => return Ok(false),
3838
Err(_) => return Ok(true),
3939
}

0 commit comments

Comments
 (0)