From: Andreas Gruenbacher <agruenba@redhat.com>
To: "Matthew Wilcox (Oracle)" <willy@infradead.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
linux-ext4@vger.kernel.org, gfs2@lists.linux.dev,
linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org,
"Darrick J . Wong" <djwong@kernel.org>,
linux-erofs@lists.ozlabs.org, "Theodore Ts'o" <tytso@mit.edu>,
Andreas Dilger <adilger.kernel@dilger.ca>
Subject: Re: [PATCH 2/3] mm: Add folio_fill_tail() and use it in iomap
Date: Thu, 9 Nov 2023 22:50:45 +0100 [thread overview]
Message-ID: <CAHc6FU550j_AYgWz5JgRu84mw5HqrSwd+hYZiHVArnget3gb4w@mail.gmail.com> (raw)
In-Reply-To: <20231107212643.3490372-3-willy@infradead.org>
On Tue, Nov 7, 2023 at 10:27 PM Matthew Wilcox (Oracle)
<willy@infradead.org> wrote:
> The iomap code was limited to PAGE_SIZE bytes; generalise it to cover
> an arbitrary-sized folio, and move it to be a common helper.
>
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> ---
> fs/iomap/buffered-io.c | 14 ++------------
> include/linux/highmem.h | 38 ++++++++++++++++++++++++++++++++++++++
> 2 files changed, 40 insertions(+), 12 deletions(-)
>
> diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c
> index f72df2babe56..093c4515b22a 100644
> --- a/fs/iomap/buffered-io.c
> +++ b/fs/iomap/buffered-io.c
> @@ -305,28 +305,18 @@ static int iomap_read_inline_data(const struct iomap_iter *iter,
> {
> const struct iomap *iomap = iomap_iter_srcmap(iter);
> size_t size = i_size_read(iter->inode) - iomap->offset;
> - size_t poff = offset_in_page(iomap->offset);
> size_t offset = offset_in_folio(folio, iomap->offset);
> - void *addr;
>
> if (folio_test_uptodate(folio))
> return 0;
>
> - if (WARN_ON_ONCE(size > PAGE_SIZE - poff))
> - return -EIO;
> - if (WARN_ON_ONCE(size > PAGE_SIZE -
> - offset_in_page(iomap->inline_data)))
> - return -EIO;
> if (WARN_ON_ONCE(size > iomap->length))
> return -EIO;
> if (offset > 0)
> ifs_alloc(iter->inode, folio, iter->flags);
>
> - addr = kmap_local_folio(folio, offset);
> - memcpy(addr, iomap->inline_data, size);
> - memset(addr + size, 0, PAGE_SIZE - poff - size);
> - kunmap_local(addr);
> - iomap_set_range_uptodate(folio, offset, PAGE_SIZE - poff);
> + folio_fill_tail(folio, offset, iomap->inline_data, size);
> + iomap_set_range_uptodate(folio, offset, folio_size(folio) - offset);
> return 0;
> }
>
> diff --git a/include/linux/highmem.h b/include/linux/highmem.h
> index 1b81416196dd..0fbb60ffefc9 100644
> --- a/include/linux/highmem.h
> +++ b/include/linux/highmem.h
> @@ -521,6 +521,44 @@ static inline __must_check void *folio_zero_tail(struct folio *folio,
> return kaddr;
> }
>
> +/**
> + * folio_fill_tail - Copy some data to a folio and pad with zeroes.
> + * @folio: The destination folio.
> + * @offset: The offset into @folio at which to start copying.
> + * @from: The data to copy.
> + * @len: How many bytes of data to copy.
> + *
> + * This function is most useful for filesystems which support inline data.
> + * When they want to copy data from the inode into the page cache, this
> + * function does everything for them. It supports large folios even on
> + * HIGHMEM configurations.
> + */
> +static inline void folio_fill_tail(struct folio *folio, size_t offset,
> + const char *from, size_t len)
> +{
> + char *to = kmap_local_folio(folio, offset);
> +
> + VM_BUG_ON(offset + len > folio_size(folio));
> +
> + if (folio_test_highmem(folio)) {
> + size_t max = PAGE_SIZE - offset_in_page(offset);
> +
> + while (len > max) {
> + memcpy(to, from, max);
> + kunmap_local(to);
> + len -= max;
> + from += max;
> + offset += max;
> + max = PAGE_SIZE;
> + to = kmap_local_folio(folio, offset);
> + }
> + }
> +
> + memcpy(to, from, len);
> + to = folio_zero_tail(folio, offset, to);
This needs to be:
to = folio_zero_tail(folio, offset + len, to + len);
> + kunmap_local(to);
> +}
> +
> /**
> * memcpy_from_file_folio - Copy some bytes from a file folio.
> * @to: The destination buffer.
> --
> 2.42.0
>
Reviewed-by: Andreas Gruenbacher <agruenba@redhat.com>
Thanks,
Andreas
next prev parent reply other threads:[~2023-11-09 21:51 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-07 21:26 [PATCH 0/3] Add folio_zero_tail() and folio_fill_tail() Matthew Wilcox (Oracle)
2023-11-07 21:26 ` [PATCH 1/3] mm: Add folio_zero_tail() and use it in ext4 Matthew Wilcox (Oracle)
2023-11-08 23:06 ` Andrew Morton
2023-11-09 0:12 ` Andreas Grünbacher
2023-11-09 17:27 ` Andrew Morton
2023-11-09 17:37 ` Matthew Wilcox
2023-11-09 21:50 ` Andreas Gruenbacher
2023-11-07 21:26 ` [PATCH 2/3] mm: Add folio_fill_tail() and use it in iomap Matthew Wilcox (Oracle)
2023-11-09 21:50 ` Andreas Gruenbacher [this message]
2023-11-10 17:09 ` Matthew Wilcox
2023-11-10 17:50 ` Andreas Grünbacher
2023-11-11 4:02 ` Gao Xiang
2023-11-07 21:26 ` [PATCH 3/3] gfs2: Convert stuffed_readpage() to stuffed_read_folio() Matthew Wilcox (Oracle)
2023-11-09 21:52 ` Andreas Gruenbacher
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAHc6FU550j_AYgWz5JgRu84mw5HqrSwd+hYZiHVArnget3gb4w@mail.gmail.com \
--to=agruenba@redhat.com \
--cc=adilger.kernel@dilger.ca \
--cc=akpm@linux-foundation.org \
--cc=djwong@kernel.org \
--cc=gfs2@lists.linux.dev \
--cc=linux-erofs@lists.ozlabs.org \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=tytso@mit.edu \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).