Re: [PATCH 08/15] ubifs: Convert ubifs_write_begin() to use a folio

Matthew Wilcox
2024-01-23T03:07:19Z

On Tue, Jan 23, 2024 at 10:15:50AM +0800, Zhihao Cheng wrote:
> 在 2024/1/22 22:43, Matthew Wilcox 写道:
> > On Mon, Jan 22, 2024 at 07:51:03PM +0800, Zhihao Cheng wrote:
> > > Why not len == folio_size(folio)? Although 'len >= folio_size(folio)' is not
> > > wrong.
> >
> > This is based on my experience with iomap. Today, the caller passes in
> > min(length-of-write, PAGE_SIZE). In order to be able to create large
> > folios in the write path, we want to change the caller of write_begin
> > to pass in the length of the write, so we can see a len which is larger
> > than the size of the folio we found.
>
> I guess you are preparing for adding large folio support for
> generic_perform_write path, may I have a look for the demo code? I'm a

https://lore.kernel.org/linux-fsdevel/20240111192513.3505769-1-willy@infradead.org/
(now withdrawn because it breaks ext4)

> little confused for this words "we want to change the caller of write_begin
> to pass in the length of the write". According to the implementation of
> iomap_write_iter(), I find the write length in each iteration is
> min(write_bytes, folio_size), so I guess the write length passed in
> ubifs_write_begin won't exceed folio_size.

But that happens after write_begin, because we don't know what the folio
size will be until we've called write_begin.

ie we call write_begin, passing in the size remaining from the write.
If write_begin finds an existing folio in the page cache, we use it.
If not, we allocate a folio based on the size of the write. After
write_begin returns a folio, we limit the number of bytes copied to the
size of the folio.