@@ -29,11 +29,9 @@ const FILE_ATTRIBUTE_NORMAL: u32 = 128;
2929#[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
3030use libc:: S_IFIFO ;
3131#[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
32- use uucore:: pipes:: { pipe, splice, splice_exact} ;
32+ use uucore:: pipes:: { MAX_ROOTLESS_PIPE_SIZE , pipe, splice, splice_exact} ;
3333
3434const BUF_SIZE : usize = 256 * 1024 ;
35- #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
36- const SPLICE_SIZE : usize = 128 * 1024 ;
3735
3836/// This is a Linux-specific function to count the number of bytes using the
3937/// `splice` system call, which is faster than using `read`.
@@ -55,11 +53,14 @@ fn count_bytes_using_splice(fd: &impl AsFd) -> Result<usize, usize> {
5553 // Bit of an edge case, but it has been known to happen
5654 return Err ( 0 ) ;
5755 }
56+ // todo: avoid generating broker if input is pipe (fcntl_setpipe_size succeed) and directly splice() to /dev/null to save RAM usage
5857 let ( pipe_rd, pipe_wr) = pipe ( ) . map_err ( |_| 0_usize ) ?;
5958
6059 let mut byte_count = 0 ;
60+ // improve throughput from pipe
61+ let _ = rustix:: pipe:: fcntl_setpipe_size ( fd, MAX_ROOTLESS_PIPE_SIZE ) ;
6162 loop {
62- match splice ( fd, & pipe_wr, SPLICE_SIZE ) {
63+ match splice ( fd, & pipe_wr, MAX_ROOTLESS_PIPE_SIZE ) {
6364 Ok ( 0 ) => break ,
6465 Ok ( res) => {
6566 byte_count += res;
0 commit comments