From: David Sterba <dsterba@suse.cz>
To: Qu Wenruo <quwenruo.btrfs@gmx.com>
Cc: dsterba@suse.cz, Qu Wenruo <wqu@suse.com>, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 2/3] btrfs: use folio_contains() for EOF detection
Date: Wed, 9 Apr 2025 01:12:26 +0200 [thread overview]
Message-ID: <20250408231226.GF13292@twin.jikos.cz> (raw)
In-Reply-To: <313da654-15aa-437a-847d-e125e83df977@gmx.com>
On Tue, Apr 08, 2025 at 07:28:58AM +0930, Qu Wenruo wrote:
> 在 2025/4/8 04:09, David Sterba 写道:
> > On Fri, Apr 04, 2025 at 12:17:41PM +1030, Qu Wenruo wrote:
> >> Currently we use the following pattern to detect if the folio contains
> >> the end of a file:
> >>
> >> if (folio->index == end_index)
> >> folio_zero_range();
> >>
> >> But that only works if the folio is page sized.
> >>
> >> For the following case, it will not work and leave the range beyond EOF
> >> uninitialized:
> >>
> >> The page size is 4K, and the fs block size is also 4K.
> >>
> >> 16K 20K 24K
> >> | | | |
> >> |
> >> EOF at 22K
> >>
> >> And we have a large folio sized 8K at file offset 16K.
> >>
> >> In that case, the old "folio->index == end_index" will not work, thus
> >> we the range [22K, 24K) will not be zeroed out.
> >>
> >> Fix the following call sites which use the above pattern:
> >>
> >> - add_ra_bio_pages()
> >>
> >> - extent_writepage()
> >>
> >> Signed-off-by: Qu Wenruo <wqu@suse.com>
> >> ---
> >> fs/btrfs/compression.c | 2 +-
> >> fs/btrfs/extent_io.c | 6 +++---
> >> 2 files changed, 4 insertions(+), 4 deletions(-)
> >>
> >> diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c
> >> index cb954f9bc332..7aa63681f92a 100644
> >> --- a/fs/btrfs/compression.c
> >> +++ b/fs/btrfs/compression.c
> >> @@ -523,7 +523,7 @@ static noinline int add_ra_bio_pages(struct inode *inode,
> >> free_extent_map(em);
> >> unlock_extent(tree, cur, page_end, NULL);
> >>
> >> - if (folio->index == end_index) {
> >> + if (folio_contains(folio, end_index)) {
> >> size_t zero_offset = offset_in_folio(folio, isize);
> >>
> >> if (zero_offset) {
> >> diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
> >> index 013268f70621..f0d51f6ed951 100644
> >> --- a/fs/btrfs/extent_io.c
> >> +++ b/fs/btrfs/extent_io.c
> >> @@ -221,7 +221,7 @@ static void __process_folios_contig(struct address_space *mapping,
> >> }
> >>
> >> static noinline void unlock_delalloc_folio(const struct inode *inode,
> >> - const struct folio *locked_folio,
> >> + struct folio *locked_folio,
> >
> > I'm not happy to see removing const from the parameters as it's quite
> > tedious to find them. Here it's not necessary as it's still not changing
> > the folio, only required because folio API is not const-clean,
> > folio_contains() in particular.
> >
>
> Yes, I'm not happy with that either, and I'm planning to constify the
> parameters for those helpers in a dedicated series.
Thanks, but don't let it distract you from the more important folio
changes. I noticed there are missing consts in the page API too, like
page_offset() or the folio/page boundary like folio_pos() or
folio_pgoff(). This is can wait, my comment was more like a note to self
to have a look later.
next prev parent reply other threads:[~2025-04-08 23:12 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-04 1:47 [PATCH 0/3] btrfs: fsstress hang fix for large data folios Qu Wenruo
2025-04-04 1:47 ` [PATCH 1/3] btrfs: remove unnecessary early exits in delalloc folio lock and unlock Qu Wenruo
2025-04-04 16:04 ` Filipe Manana
2025-04-04 21:44 ` Qu Wenruo
2025-04-05 17:54 ` Filipe Manana
2025-04-04 1:47 ` [PATCH 2/3] btrfs: use folio_contains() for EOF detection Qu Wenruo
2025-04-04 16:09 ` Filipe Manana
2025-04-07 18:39 ` David Sterba
2025-04-07 21:58 ` Qu Wenruo
2025-04-08 23:12 ` David Sterba [this message]
2025-04-08 23:16 ` Qu Wenruo
2025-04-04 1:47 ` [PATCH 3/3] btrfs: get rid of filemap_get_folios_contig() calls Qu Wenruo
2025-04-04 16:38 ` Filipe Manana
2025-04-04 21:51 ` Qu Wenruo
2025-04-04 22:00 ` Qu Wenruo
2025-04-22 22:47 ` Qu Wenruo
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=20250408231226.GF13292@twin.jikos.cz \
--to=dsterba@suse.cz \
--cc=linux-btrfs@vger.kernel.org \
--cc=quwenruo.btrfs@gmx.com \
--cc=wqu@suse.com \
/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