I know with a splice, we can all stay in the kernel. But I am not sure whether it is the data or the whereabouts info that get passed to the pipe.
EDIT 1:
Thanks @vinayak, now I know there is actually data copy to and from the pipe buffer. But then, I just wonder why we can not just pass whereabouts and length info to the pipe?
- Within a single process, the address space is the same
- Between difference processes, it also works if the pipe buffer is linear mapped. If not, we may use the DMA address.
refer here
A splice() is a system call mechanism to do i/o from one file to
another file in kernel space without doing copying from/to user
space.It is a way of improving I/O performance. The splice system call
avoids all data copy from user space to kernel space & vice versa. It
reads from the specified offset from the input file & writes to a pipe
in the kernel space. There is no copying of data to user space.Then it
can be called to write the data from the pipe to the output file at
the specified/current offset.
splice() works by using the pipe buffer mechanism to open a file
descriptor for a data source and another for a data sink then by using
splice() it can join the two together. In other words, splice() work
on a kernel buffer that the user has control over and moves data
to/from the buffer from/to an arbitrary file descriptor. Specifying
offset with pipe is an error as usual. If no offset is specified with
an input/output file descriptor then the current offset will be
assumed to be the offset specified. Currently one of the file
descriptor must be pipe otherwise it is an error.