Linux zero-copy file I/O: skipping user-space buffers with copy_file_range, sendfile and splice
A typical read/write copy loop moves every byte from the page cache into a user buffer and back again, doubling memory traffic for no real benefit. Linux offers copy_file_range, sendfile and splice to avoid that round trip by performing the transfer inside the kernel. Each call has a different scope: copy_file_range handles regular file to regular file copies, sendfile serves files over sockets, and splice moves data to or from pipes. Each comes with constraints, such as requiring a pipe on one side or failing across filesystems, so portable code needs a fallback path. The read/write loop remains the right choice when the data must be inspected or transformed.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in