Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: Filipe Manana <fdmanana@kernel.org>, Qu Wenruo <wqu@suse.com>
Cc: linux-btrfs@vger.kernel.org, David Sterba <dsterba@suse.com>
Subject: Re: [PATCH v2 04/11] btrfs: introduce extra sanity checks for extent maps
Date: Tue, 14 May 2024 08:04:04 +0930	[thread overview]
Message-ID: <cb485082-3361-4b3a-bf7d-5b5465da10dd@gmx.com> (raw)
In-Reply-To: <CAL3q7H7BPGFcAaqhcAO2vNax8ShhbFm=HcXbvODa-GJshuSs2A@mail.gmail.com>



在 2024/5/13 21:51, Filipe Manana 写道:
> On Fri, May 3, 2024 at 7:02 AM Qu Wenruo <wqu@suse.com> wrote:
>>
>> Since extent_map structure has the all the needed members to represent a
>> file extent directly, we can apply all the file extent sanity checks to an extent
>> map.
>>
>> The new sanity checks would cross check both the old members
>> (block_start/block_len/orig_start) and the new members
>> (disk_bytenr/disk_num_bytes/offset).
>>
>> There is a special case for offset/orig_start/start cross check, we only
>> do such sanity check for compressed extent:
>>
>> - Only compressed read/encoded write really utilize orig_start
>>    This can be proved by the cleanup patch of orig_start.
>>
>> - Merged data extents can lead to false alerts
>>    The problem is, with disk_bytenr/disk_num_bytes, if we're merging
>>    two extent maps like this:
>>
>>      |<- data extent A -->|<-- data extent B -->|
>>                |<- em 1 ->|<- em 2 ->|
>>
>>    Let's assume em2 has orig_offset of 0 and start of 0, and obvisouly
>>    offset 0.
>
> obvisouly -> obviously
>
> I'm confused. How can em2 have a "start" of 0?
> By "start" you mean file offset I suppose, since that's what it is
> before this patchset. That would mean em 1 would have a negative
> "start".

My bad, I screwed up the example numbers.

For "offset" I mean the the offset inside the data extent, aka,
"btrfs_file_extent_item::offset"
And for "start" I mean filepos, aka the key.offset.

And in above case, it's all dependent on the filepos of the em1/em2.

I would change the example to something like this:

em1: file pos 4k, len 4k, extent offset 4k, ram bytes 8k, disk_bytenr X,
disk_num_bytes 8K, compress none.

Then it's orig_start should be 0.

em2: file pos 8k, len 4k, extent offset 0, ram_bytes 8K,
disk_bytenr X + 8K, disk_num_bytes 8K, compress none.

And its orig_start should be 8K.

>
> And by "offset" you mean extent offset?
>
>>
>>    But after merging, the merged em would have offset of em1, screwing up
>
> But this suggests that by "offset" you mean file offset and not the
> offset within an extent's range.

No, I still mean "extent offset".

As the "merged" em would be:

em merged: filepos 4k, len 8K, extent offset 4K, ram_bytes 16K,
disk_bytenr X, disk_num_bytes 16K, compress none.

Thus the orig_offset would be still be 0, the same as the em1 before
merging.

> So did you mean "start" here?
>
>>    whatever the @orig_start cross check against @start.
>>
>> The checks happens at the following timing:
>>
>> - add_extent_mapping()
>>    This is for newly added extent map
>>
>> - replace_extent_mapping()
>>    This is for btrfs_drop_extent_map_range() and split_extent_map()
>>
>> - try_merge_map()
>>
>> Since the check is way more strict than before, the following code has
>> to be modified to pass the check:
>>
>> - extent-map-tests
>>    Previously the test case never populate ram_bytes, not to mention the
>>    newly introduced disk_bytenr/disk_num_bytes.
>>    Populate the involved numbers mostly to follow the existing
>>    block_start/block_len values.
>>
>>    There are two special cases worth mentioning:
>>    - test_case_3()
>>      The test case is already way too invalid that tree-checker will
>>      reject almost all extents.
>>
>>      And there is a special unaligned regular extent which has mismatch
>>      disk_num_bytes (4096) and ram_bytes (4096 - 1).
>>      Fix it by all assigned the disk_num_bytes and ram_bytes to 4096 - 1.
>
> Looking at the diff for test_case_3(), I don't see any assignment of
> 4096 - 1 anywhere.
> All the assignments I see have a value of SZ_4K or SZ_16K.

It's in fact setup_file_extents() from inode-tests.c, I got confused
with other fixes.

>
>>
>>    - test_case_7()
>>      An extent is inserted with 16K length, but on-disk extent size is
>>      only 4K.
>>      This means it must be a compressed extent, so set the compressed flag
>>      for it.
>>
>> - setup_relocation_extent_mapping()
>>    This is mostly utilized by relocation code to read the chunk like an
>>    inode.
>
> Not "mostly" - it's exclusively used by the relocation code.
>
>>    So populate the extent map using a regular non-compressed extent.
>
> Isn't that what we already do? I'm confused.
> We are already creating a regular non-compressed extent, and all the
> diff does is to initialize some fields unrelated to that.

It's more like initializing the remaining members, or those
uninitialized members would not pass cross-check.

I guess I should put the missing initialization where I introduced them?

>
>>
>> In fact, the new cross checks already exposed a bug in
>> btrfs_drop_extent_map_range(), and caught tons of bugs in the new
>> members assignment.
>
> I remember one bug in btrfs_drop_extent_map_range(), which fortunately
> didn't have any consequences.
> Those tons of bugs you mention are only in the code added by the
> patchset if I understand you correctly.

Isn't that why I mention is as "in the new members assignment"?

Or should I just drop the mention completely?

Thanks,
Qu

  reply	other threads:[~2024-05-13 22:34 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-03  6:01 [PATCH v2 00/11] btrfs: extent-map: unify the members with btrfs_ordered_extent Qu Wenruo
2024-05-03  6:01 ` [PATCH v2 01/11] btrfs: rename extent_map::orig_block_len to disk_num_bytes Qu Wenruo
2024-05-09 16:15   ` Filipe Manana
2024-05-03  6:01 ` [PATCH v2 02/11] btrfs: export the expected file extent through can_nocow_extent() Qu Wenruo
2024-05-09 16:22   ` Filipe Manana
2024-05-09 21:55     ` Qu Wenruo
2024-05-03  6:01 ` [PATCH v2 03/11] btrfs: introduce new members for extent_map Qu Wenruo
2024-05-09 17:05   ` Filipe Manana
2024-05-09 22:11     ` Qu Wenruo
2024-05-10 11:26       ` Filipe Manana
2024-05-10 22:26         ` Qu Wenruo
2024-05-13 12:48   ` Filipe Manana
2024-05-13 12:54     ` Filipe Manana
2024-05-13 17:31   ` Filipe Manana
2024-05-03  6:01 ` [PATCH v2 04/11] btrfs: introduce extra sanity checks for extent maps Qu Wenruo
2024-05-13 12:21   ` Filipe Manana
2024-05-13 22:34     ` Qu Wenruo [this message]
2024-05-03  6:01 ` [PATCH v2 05/11] btrfs: remove extent_map::orig_start member Qu Wenruo
2024-05-13 13:09   ` Filipe Manana
2024-05-13 22:14     ` Qu Wenruo
2024-05-03  6:01 ` [PATCH v2 06/11] btrfs: remove extent_map::block_len member Qu Wenruo
2024-05-13 17:44   ` Filipe Manana
2024-05-14  7:09     ` Qu Wenruo
2024-05-03  6:01 ` [PATCH v2 07/11] btrfs: remove extent_map::block_start member Qu Wenruo
2024-05-16 17:28   ` Filipe Manana
2024-05-16 22:45     ` Qu Wenruo
2024-05-03  6:01 ` [PATCH v2 08/11] btrfs: cleanup duplicated parameters related to can_nocow_file_extent_args Qu Wenruo
2024-05-20 15:55   ` Filipe Manana
2024-05-20 22:13     ` Qu Wenruo
2024-05-03  6:01 ` [PATCH v2 09/11] btrfs: cleanup duplicated parameters related to btrfs_alloc_ordered_extent Qu Wenruo
2024-05-20 16:31   ` Filipe Manana
2024-05-03  6:01 ` [PATCH v2 10/11] btrfs: cleanup duplicated parameters related to create_io_em() Qu Wenruo
2024-05-20 16:46   ` Filipe Manana
2024-05-03  6:01 ` [PATCH v2 11/11] btrfs: cleanup duplicated parameters related to btrfs_create_dio_extent() Qu Wenruo
2024-05-20 16:48   ` Filipe Manana
2024-05-23  4:03     ` Qu Wenruo
2024-05-03 11:53 ` [PATCH v2 00/11] btrfs: extent-map: unify the members with btrfs_ordered_extent David Sterba
2024-05-20 16:55 ` Filipe Manana

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=cb485082-3361-4b3a-bf7d-5b5465da10dd@gmx.com \
    --to=quwenruo.btrfs@gmx.com \
    --cc=dsterba@suse.com \
    --cc=fdmanana@kernel.org \
    --cc=linux-btrfs@vger.kernel.org \
    --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