Re: copy on write for splice() from file to pipe?

From: Linus Torvalds
Date: Fri Feb 10 2023 - 15:51:48 EST


On Fri, Feb 10, 2023 at 12:45 PM Stefan Metzmacher <metze@xxxxxxxxx> wrote:
>
> I guess it would be easy to pass a flag (maybe SPLICE_F_FORCE_COPY)
> down to generic_file_splice_read() and let it create dedicated pages
> and use memcpy() from the page cache to the dedicated pages.

I really think you'd be much better off passing it off to the
*destination*, not the source.

The destination knows whether it needs to copy or not, and in the case
of at least networking, already has the copy option.

The destination might also already know whether it can use the data
synchronously, so that there isn't even any issue with "data may
change later".

In contrast, the source has no clue. It just knows "I'm a page cache
page". It would have to always copy.

Linus