[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <9b270d10-a62d-46ae-ba4c-3325b0877942@wdc.com>
Date: Tue, 13 Aug 2024 10:34:13 +0000
From: Johannes Thumshirn <Johannes.Thumshirn@....com>
To: Qu Wenruo <quwenruo.btrfs@....com>, Johannes Thumshirn <jth@...nel.org>,
Chris Mason <clm@...com>, Josef Bacik <josef@...icpanda.com>, David Sterba
<dsterba@...e.com>, "open list:BTRFS FILE SYSTEM"
<linux-btrfs@...r.kernel.org>, open list <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] btrfs: reduce chunk_map lookups in btrfs_map_block
On 13.08.24 00:33, Qu Wenruo wrote:
>
>
> 在 2024/8/13 02:29, Johannes Thumshirn 写道:
>> From: Johannes Thumshirn <johannes.thumshirn@....com>
>>
>> Currently we're calling btrfs_num_copies() before btrfs_get_chunk_map() in
>> btrfs_map_block(). But btrfs_num_copies() itself does a chunk map lookup
>> to be able to calculate the number of copies.
>>
>> So split out the code getting the number of copies from btrfs_num_copies()
>> into a helper called btrfs_chunk_map_num_copies() and directly call it
>> from btrfs_map_block() and btrfs_num_copies().
>>
>> This saves us one rbtree lookup per btrfs_map_block() invocation.
>>
>> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@....com>
>
> Reviewed-by: Qu Wenruo <wqu@...e.com>
>
> Just one nitpick inlined below.
>
>> ---
>> fs/btrfs/volumes.c | 50 +++++++++++++++++++++++++++-------------------
>> 1 file changed, 29 insertions(+), 21 deletions(-)
>>
>> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
>> index e07452207426..4863bdb4d6f4 100644
>> --- a/fs/btrfs/volumes.c
>> +++ b/fs/btrfs/volumes.c
>> @@ -5781,10 +5781,33 @@ void btrfs_mapping_tree_free(struct btrfs_fs_info *fs_info)
>> write_unlock(&fs_info->mapping_tree_lock);
>> }
>>
>> +static int btrfs_chunk_map_num_copies(struct btrfs_chunk_map *map)
>> +{
>> + enum btrfs_raid_types index = btrfs_bg_flags_to_raid_index(map->type);
>> +
>> + /* Non-RAID56, use their ncopies from btrfs_raid_array. */
>> + if (!(map->type & BTRFS_BLOCK_GROUP_RAID56_MASK))
>> + return btrfs_raid_array[index].ncopies;
>> +
>> + if (map->type & BTRFS_BLOCK_GROUP_RAID5)
>> + return 2;
>> +
>> + /*
>> + * There could be two corrupted data stripes, we need
>> + * to loop retry in order to rebuild the correct data.
>> + *
>> + * Fail a stripe at a time on every retry except the
>> + * stripe under reconstruction.
>> + */
>> + if (map->type & BTRFS_BLOCK_GROUP_RAID6)
>> + return map->num_stripes;
>> +
>> + return 1;
>
> IIRC above if()s have checks all profiles.
>
> Thus should we call ASSERT() instead? Or return map->num_stripes since
> that's the only remaining possible case.
I was also thinking of an ASSERT(), but moving that case:
>> + /* Non-RAID56, use their ncopies from btrfs_raid_array. */
>> + if (!(map->type & BTRFS_BLOCK_GROUP_RAID56_MASK))
>> + return btrfs_raid_array[index].ncopies;
to the end would be enough (without the if obviously).
Powered by blists - more mailing lists