From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: Christoph Hellwig <hch@lst.de>
Cc: Chris Mason <clm@fb.com>, Josef Bacik <josef@toxicpanda.com>,
David Sterba <dsterba@suse.com>,
linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 10/16] btrfs: remove non-standard extent handling in __extent_writepage_io
Date: Tue, 13 Feb 2024 09:36:24 +1030 [thread overview]
Message-ID: <1268fba4-de90-44c6-8bfa-382f5faad2a0@gmx.com> (raw)
In-Reply-To: <20240212155230.GA29259@lst.de>
On 2024/2/13 02:22, Christoph Hellwig wrote:
> On Sat, Feb 10, 2024 at 08:09:47PM +1030, Qu Wenruo wrote:
>>> @@ -1419,10 +1418,14 @@ static noinline_for_stack int __extent_writepage_io(struct btrfs_inode *inode,
>>> ASSERT(cur < end);
>>> ASSERT(IS_ALIGNED(em->start, fs_info->sectorsize));
>>> ASSERT(IS_ALIGNED(em->len, fs_info->sectorsize));
>>> +
>>> block_start = em->block_start;
>>> - compressed = test_bit(EXTENT_FLAG_COMPRESSED, &em->flags);
>>> disk_bytenr = em->block_start + extent_offset;
>>>
>>> + ASSERT(!test_bit(EXTENT_FLAG_COMPRESSED, &em->flags));
>>> + ASSERT(block_start != EXTENT_MAP_HOLE);
>>
>> For subpage cases, __extent_writepage_io() can be triggered to write
>> only a subset of the page, from extent_write_locked_range().
>
> Yes.
>
>> In that case, if we have submitted the target range, since our @len is
>> to the end of the page, we can hit a hole.
>>
>> In that case, this ASSERT() would be triggered.
>> And even worse, if CONFIG_BTRFS_ASSERT() is not enabled, we can do wrong
>> writeback using the wrong disk_bytenr.
>>
>> So at least we need to skip the hole ranges for subpage.
>> And thankfully the remaining two cases are impossible for subpage.
>
> The patch below reinstates the hole handling. I don't have a system
> that tests the btrfs subpage code right now, so this is untested:
>
> diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
> index cfd2967f04a293..a106036641104c 100644
> --- a/fs/btrfs/extent_io.c
> +++ b/fs/btrfs/extent_io.c
> @@ -1388,7 +1388,6 @@ static noinline_for_stack int __extent_writepage_io(struct btrfs_inode *inode,
> disk_bytenr = em->block_start + extent_offset;
>
> ASSERT(!extent_map_is_compressed(em));
> - ASSERT(block_start != EXTENT_MAP_HOLE);
> ASSERT(block_start != EXTENT_MAP_INLINE);
>
> /*
> @@ -1399,6 +1398,15 @@ static noinline_for_stack int __extent_writepage_io(struct btrfs_inode *inode,
> free_extent_map(em);
> em = NULL;
>
> + if (block_start == EXTENT_MAP_HOLE) {
> + btrfs_mark_ordered_io_finished(inode, page, cur, iosize,
> + true);
> + btrfs_folio_clear_dirty(fs_info, page_folio(page), cur,
> + iosize);
> + cur += iosize;
> + continue;
> + }
> +
> btrfs_set_range_writeback(inode, cur, cur + iosize - 1);
> if (!PageWriteback(page)) {
> btrfs_err(inode->root->fs_info,
There are more problem than I initially thought.
In fact, I went another path to make __extent_writepage_io() to only
submit IO for the desired range.
But we would have another problem related to @locked_page handling.
For extent_write_locked_range(), we expect to unlock the @locked_page.
But for subpage case, we can have multiple dirty ranges.
In that case, if we unlock @locked_page for the first iteration, the
next extent_write_locked_range() iteration can still try to get the same
page, and found the page unlocked, triggering an ASSERT().
So the patch itself is not the root cause, it's the lack of subpage
locking causing the problem.
Sorry for the false alerts.
Thanks,
Qu
next prev parent reply other threads:[~2024-02-12 23:06 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-31 6:04 writeback fixlets and tidyups v2 Christoph Hellwig
2023-05-31 6:04 ` [PATCH 01/16] btrfs: fix range_end calculation in extent_write_locked_range Christoph Hellwig
2023-05-31 6:04 ` [PATCH 02/16] btrfs: factor out a btrfs_verify_page helper Christoph Hellwig
2023-05-31 6:04 ` [PATCH 03/16] btrfs: fix fsverify read error handling in end_page_read Christoph Hellwig
2023-05-31 6:04 ` [PATCH 04/16] btrfs: don't check PageError in btrfs_verify_page Christoph Hellwig
2023-05-31 6:04 ` [PATCH 05/16] btrfs: don't fail writeback when allocating the compression context fails Christoph Hellwig
2023-05-31 6:04 ` [PATCH 06/16] btrfs: rename cow_file_range_async to run_delalloc_compressed Christoph Hellwig
2023-05-31 6:04 ` [PATCH 07/16] btrfs: don't check PageError in __extent_writepage Christoph Hellwig
2023-05-31 6:04 ` [PATCH 08/16] btrfs: stop setting PageError in the data I/O path Christoph Hellwig
2023-05-31 6:04 ` [PATCH 09/16] btrfs: remove PAGE_SET_ERROR Christoph Hellwig
2023-05-31 6:04 ` [PATCH 10/16] btrfs: remove non-standard extent handling in __extent_writepage_io Christoph Hellwig
2024-02-10 9:39 ` Qu Wenruo
2024-02-12 15:52 ` Christoph Hellwig
2024-02-12 23:06 ` Qu Wenruo [this message]
2023-05-31 6:05 ` [PATCH 11/16] btrfs: move nr_to_write to __extent_writepage Christoph Hellwig
2023-05-31 6:05 ` [PATCH 12/16] btrfs: only call __extent_writepage_io from extent_write_locked_range Christoph Hellwig
2023-05-31 6:05 ` [PATCH 13/16] btrfs: don't treat zoned writeback as being from an async helper thread Christoph Hellwig
2023-05-31 6:05 ` [PATCH 14/16] btrfs: don't redirty the locked page for extent_write_locked_range Christoph Hellwig
2023-06-05 21:00 ` David Sterba
2023-05-31 6:05 ` [PATCH 15/16] btrfs: refactor the zoned device handling in cow_file_range Christoph Hellwig
2023-06-06 14:20 ` Naohiro Aota
2023-06-07 7:27 ` Christoph Hellwig
2023-05-31 6:05 ` [PATCH 16/16] btrfs: split page locking out of __process_pages_contig Christoph Hellwig
2023-05-31 16:39 ` writeback fixlets and tidyups v2 Josef Bacik
2023-06-05 21:01 ` David Sterba
2023-06-06 6:24 ` Christoph Hellwig
-- strict thread matches above, loose matches on Subject: below --
2023-05-23 8:13 writeback fixlets and tidyups Christoph Hellwig
2023-05-23 8:13 ` [PATCH 10/16] btrfs: remove non-standard extent handling in __extent_writepage_io Christoph Hellwig
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=1268fba4-de90-44c6-8bfa-382f5faad2a0@gmx.com \
--to=quwenruo.btrfs@gmx.com \
--cc=clm@fb.com \
--cc=dsterba@suse.com \
--cc=hch@lst.de \
--cc=josef@toxicpanda.com \
--cc=linux-btrfs@vger.kernel.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 NNTP newsgroup(s).