All of lore.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <wqu@suse.com>
To: Johannes Thumshirn <Johannes.Thumshirn@wdc.com>,
	Qu Wenruo <quwenruo.btrfs@gmx.com>,
	"linux-btrfs@vger.kernel.org" <linux-btrfs@vger.kernel.org>
Subject: Re: [PATCH v3 2/2] btrfs: use ilog2() to replace if () branches for btrfs_bg_flags_to_raid_index()
Date: Wed, 20 Apr 2022 17:45:30 +0800	[thread overview]
Message-ID: <1d1dcbd6-d9bb-ff2b-fc70-75bbd926ff78@suse.com> (raw)
In-Reply-To: <PH0PR04MB741682A87F86554F81F5AE839BF59@PH0PR04MB7416.namprd04.prod.outlook.com>



On 2022/4/20 16:41, Johannes Thumshirn wrote:
> On 20/04/2022 10:38, Qu Wenruo wrote:
>>
>>
>> On 2022/4/20 16:25, Johannes Thumshirn wrote:
>>> On 20/04/2022 10:09, Qu Wenruo wrote:
>>>> In function btrfs_bg_flags_to_raid_index(), we use quite some if () to
>>>> convert the BTRFS_BLOCK_GROUP_* bits to a index number.
>>>>
>>>> But the truth is, there is really no such need for so many branches at
>>>> all.
>>>> Since all BTRFS_BLOCK_GROUP_* flags are just one single bit set inside
>>>> BTRFS_BLOCK_GROUP_PROFILES_MASK, we can easily use ilog2() to calculate
>>>> their values.
>>>>
>>>> This calculation has an anchor point, the lowest PROFILE bit, which is
>>>> RAID0.
>>>>
>>>> Even it's fixed on-disk format and should never change, here I added
>>>> extra compile time checks to make it super safe:
>>>>
>>>> 1. Make sure RAID0 is always the lowest bit in PROFILE_MASK
>>>>      This is done by finding the first (least significant) bit set of
>>>>      RAID0 and PROFILE_MASK & ~RAID0.
>>>>
>>>> 2. Make sure RAID0 bit set beyond the highest bit of TYPE_MASK
>>>
>>> TBH I think this change obscures the code more than it improves it.
>>>
>> Right, that kinda makes sense.
>>
>> Will update the patchset to remove that line if needed.
> 
> I think the whole patch makes the code harder to follow. As of now you can
> just look it up, now you have to look how the calculation is done etc.

The problem is, why you need to look the index up?

The index is pretty straight forward, just a enum for each profile, one 
should not really bother whatever the value is.

> 
> If you want to get rid of the branches (which I still don't see a reason for)

The new code is just 5 asm commands on x86_64.

> have you considered creating a lookup table?

The index is used for the lookup table of btrfs_raid_type.

Thanks,
Qu


  reply	other threads:[~2022-04-20  9:45 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-20  8:08 [PATCH v3 0/2] btrfs: re-define btrfs_raid_types Qu Wenruo
2022-04-20  8:08 ` [PATCH v3 1/2] btrfs: move definition of btrfs_raid_types to volumes.h Qu Wenruo
2022-04-20  8:13   ` Johannes Thumshirn
2022-04-20  8:08 ` [PATCH v3 2/2] btrfs: use ilog2() to replace if () branches for btrfs_bg_flags_to_raid_index() Qu Wenruo
2022-04-20  8:25   ` Johannes Thumshirn
2022-04-20  8:38     ` Qu Wenruo
2022-04-20  8:41       ` Johannes Thumshirn
2022-04-20  9:45         ` Qu Wenruo [this message]
2022-04-20 15:16         ` David Sterba
2022-04-20 23:01           ` Qu Wenruo
2022-04-22 20:30 ` [PATCH v3 0/2] btrfs: re-define btrfs_raid_types David Sterba

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=1d1dcbd6-d9bb-ff2b-fc70-75bbd926ff78@suse.com \
    --to=wqu@suse.com \
    --cc=Johannes.Thumshirn@wdc.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=quwenruo.btrfs@gmx.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.