Re: [PATCH v20 23/32] splice: Convert trace/seq to use direct_splice_read()
From: David Howells
Date: Mon May 22 2023 - 10:51:05 EST
Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:
> > In the future, something better can probably be done by gifting pages from
> > seq->buf into the pipe, but that would require changing seq->buf into a
> > vmap over an array of pages.
>
> If you can give me a POC of what needs to be done, I could possibly
> implement it.
I wrote my idea up here for Masami[*]:
We could implement seq_splice_read(). What we would need to do is to change
how the seq buffer is allocated: bulk allocate a bunch of arbitrary pages
which we then vmap(). When we need to splice, we read into the buffer, do a
vunmap() and then splice the pages holding the data we used into the pipe.
If we don't manage to splice all the data, we can continue splicing from the
pages we have left next time. If a read() comes along to view partially
spliced data, we would need to copy from the individual pages.
When we use up all the data, we discard all the pages we might have spliced
from and shuffle down the other pages, call the bulk allocator to replenish
the buffer and then vmap() it again.
Any pages we've spliced from must be discarded and replaced and not rewritten.
If a read() comes without the buffer having been spliced from, it can do as it
does now.
David
---
[*] https://lore.kernel.org/linux-fsdevel/20230522-pfund-ferngeblieben-53fad9c0e527@brauner/T/#mc03959454c76cc3f29024b092c62d88c90f7c071