I'm trying to figure out the semantics of splice(2)
(man page here).
Let's say I've got a regular file on disk, and I want to write a portion of its current contents into a pipe (actually into /dev/fuse
on a system with the FUSE_SPLICE_WRITE
capability). I assume this looks something like:
splice(file_fd, &range_start, fuse_fd, NULL, range_size, 0);
The man page says this:
Though we talk of copying, actual copies are generally avoided. The kernel does this by implementing a pipe buffer as a set of reference-counted pointers to pages of kernel memory. The kernel creates "copies" of pages in a buffer by creating new pointers (for the output buffer) referring to the pages, and increasing the reference counts for the pages: only pointers are copied, not the pages of the buffer.
This makes me worry about what happens if the file contents subsequently change in the range of interest. Does the data in the pipe continue to reflect the previous contents of the file? (If so, how is that implemented?)
Does any of this change if SPLICE_F_MOVE
is set? I realize that this flag is ignored on modern kernels, but I'm talking about the intended semantics, since the man page claims it may be restored some day.