You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The cool thing about this is that all of it happens inside the Linux kernel, which means we won't copy a single byte to userspace (where our program runs). Ideally, splice works by remapping pages and does not actually copy any data, which may improve I/O performance.
The author even provided Rust code which was able to get a throughput of 5.9GiB/s (which is a lot as ordinary cat is able to deliver 1.9GiB/s).
externcrate nix;use std::env;use std::fs::File;use std::io;use std::os::unix::io::AsRawFd;use nix::fcntl::{splice,SpliceFFlags};use nix::unistd::pipe;constBUF_SIZE:usize = 16384;fn main(){for path in env::args().skip(1){let input = File::open(&path).expect(&format!("fcat: {}: No such file or directory", path));let(rd, wr) = pipe().unwrap();let stdout = io::stdout();let _handle = stdout.lock();loop{let res = splice(
input.as_raw_fd(),None,
wr,None,BUF_SIZE,SpliceFFlags::empty(),).unwrap();if res == 0{// We read 0 bytes from the input,// which means we're done copying.break;}let _res = splice(
rd,None,
stdout.as_raw_fd(),None,BUF_SIZE,SpliceFFlags::empty(),).unwrap();}}
The text was updated successfully, but these errors were encountered:
I've read in a blog post about splice.
The author even provided Rust code which was able to get a throughput of 5.9GiB/s (which is a lot as ordinary cat is able to deliver 1.9GiB/s).
The text was updated successfully, but these errors were encountered: