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
Subject: Re: [PATCH 1/4] btrfs: cleanup the bytenr usage inside btrfs_extent_item_to_extent_map()
Date: Tue, 25 Jun 2024 20:18:22 +0930	[thread overview]
Message-ID: <3f0450b8-b43b-4451-bf62-17a088e05ab7@gmx.com> (raw)
In-Reply-To: <CAL3q7H4eayxdogMgJKtPTNZVO-qcsZ9tcQrRGVCoEAzbsa0PEQ@mail.gmail.com>



在 2024/6/25 19:49, Filipe Manana 写道:
> On Tue, Jun 25, 2024 at 6:08 AM Qu Wenruo <wqu@suse.com> wrote:
>>
>> [PROBLEMS]
>
> I wouldn't call this "problems", there are no bugs here or anything harmful.
>
>> Before commit 85de2be7129c ("btrfs: remove extent_map::block_start
>> member"), we utilized @bytenr variable inside
>> btrfs_extent_item_to_extent_map() to calculate block_start.
>>
>> But that commit removed block_start completely, we have no need to
>> advance @bytenr at all.
>>
>> Furthermore with recent enhanced btrfs-progs check for ram_bytes
>> mimsatch, it turns out that for truncated ordered extents, their
>
> mimsatch -> mismatch
>
>> ram_bytes can be smaller than disk_num_bytes.
>>
>> [ENHANCEMENT]
>> Thankfully all above problems are not really going to affect end users,
>> fix them by:
>>
>> - Declare @bytenr only inside the if branch and make it const
>>    So we can remove the unnecessary advance of @bytenr.
>>
>> - Manually override extent_map::ram_bytes using disk_num_bytes
>>    This is for non-compressed regular/preallocated extents.
>
> I don't see anything in the patch changing ram_bytes.
> Perhaps this is from an early patch version never submitted, or from
> some other patch?

My bad, when re-editing the commit message, I got confused with later
patches.

I will remove the ram_bytes related part.

Thanks,
Qu
>
> The code itself looks good.
> Thanks.
>
>>
>> Signed-off-by: Qu Wenruo <wqu@suse.com>
>> ---
>>   fs/btrfs/file-item.c | 9 ++++-----
>>   1 file changed, 4 insertions(+), 5 deletions(-)
>>
>> diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c
>> index 55703c833f3d..2cc61c792ee6 100644
>> --- a/fs/btrfs/file-item.c
>> +++ b/fs/btrfs/file-item.c
>> @@ -1281,7 +1281,6 @@ void btrfs_extent_item_to_extent_map(struct btrfs_inode *inode,
>>          const int slot = path->slots[0];
>>          struct btrfs_key key;
>>          u64 extent_start;
>> -       u64 bytenr;
>>          u8 type = btrfs_file_extent_type(leaf, fi);
>>          int compress_type = btrfs_file_extent_compression(leaf, fi);
>>
>> @@ -1291,22 +1290,22 @@ void btrfs_extent_item_to_extent_map(struct btrfs_inode *inode,
>>          em->generation = btrfs_file_extent_generation(leaf, fi);
>>          if (type == BTRFS_FILE_EXTENT_REG ||
>>              type == BTRFS_FILE_EXTENT_PREALLOC) {
>> +               const u64 disk_bytenr = btrfs_file_extent_disk_bytenr(leaf, fi);
>> +
>>                  em->start = extent_start;
>>                  em->len = btrfs_file_extent_end(path) - extent_start;
>> -               bytenr = btrfs_file_extent_disk_bytenr(leaf, fi);
>> -               if (bytenr == 0) {
>> +               if (disk_bytenr == 0) {
>>                          em->disk_bytenr = EXTENT_MAP_HOLE;
>>                          em->disk_num_bytes = 0;
>>                          em->offset = 0;
>>                          return;
>>                  }
>> -               em->disk_bytenr = btrfs_file_extent_disk_bytenr(leaf, fi);
>> +               em->disk_bytenr = disk_bytenr;
>>                  em->disk_num_bytes = btrfs_file_extent_disk_num_bytes(leaf, fi);
>>                  em->offset = btrfs_file_extent_offset(leaf, fi);
>>                  if (compress_type != BTRFS_COMPRESS_NONE) {
>>                          extent_map_set_compression(em, compress_type);
>>                  } else {
>> -                       bytenr += btrfs_file_extent_offset(leaf, fi);
>>                          if (type == BTRFS_FILE_EXTENT_PREALLOC)
>>                                  em->flags |= EXTENT_FLAG_PREALLOC;
>>                  }
>> --
>> 2.45.2
>>
>>
>

  reply	other threads:[~2024-06-25 10:48 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-25  5:07 [PATCH 0/4] btrfs: detect and fix the ram_bytes mismatch Qu Wenruo
2024-06-25  5:07 ` [PATCH 1/4] btrfs: cleanup the bytenr usage inside btrfs_extent_item_to_extent_map() Qu Wenruo
2024-06-25 10:19   ` Filipe Manana
2024-06-25 10:48     ` Qu Wenruo [this message]
2024-06-25  5:07 ` [PATCH 2/4] btrfs: make validate_extent_map() to catch ram_bytes mismatch Qu Wenruo
2024-06-25 10:25   ` Filipe Manana
2024-06-25  5:07 ` [PATCH 3/4] btrfs: fix the ram_bytes assignment for truncated ordered extents Qu Wenruo
2024-06-25 10:32   ` Filipe Manana
2024-06-25  5:07 ` [PATCH 4/4] btrfs: tree-checker: add extra ram_bytes and disk_num_bytes check Qu Wenruo
2024-06-25 10:37   ` 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=3f0450b8-b43b-4451-bf62-17a088e05ab7@gmx.com \
    --to=quwenruo.btrfs@gmx.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