Re: [PATCH v2 08/10] btrfs: relocation: Remove the open-coded goto loop for breadth-first search

Qu Wenruo
2020-03-05T08:38:05Z

On 2020/3/5 下午4:17, Nikolay Borisov wrote:
>
>
> On 5.03.20 г. 2:40 ч., Qu Wenruo wrote:
>>
>>
>> On 2020/3/4 下午10:24, Nikolay Borisov wrote:
>>>
>> [...]
>>>> + int err = 0;
>>>> +
>>>> + iter = btrfs_backref_iter_alloc(rc->extent_root->fs_info, GFP_NOFS);
>>>> + if (!iter)
>>>> + return ERR_PTR(-ENOMEM);
>>>
>>> This iterator can be made private to handle_one_tree_block as I don't see it being used outside of that function.
>>
>> It's kinda a performance optimization.
>>
>> Instead of allocating memory for each loop, we allocate the memory just
>> once, and reuse it until the whole backref map for the bytenr is built.
>>>
>>>> + path = btrfs_alloc_path();
>>>> + if (!path) {
>>>> + err = -ENOMEM;
>>>> + goto out;
>>>> + }
>>>
>>> Same thing with this path. Overall this will reduce the argument to handle_one_tree_block by 2.
>>
>> Same performance optimization here.
>
> Ok, fair point.
>>
>>>
>
> <snip>
>
>>>
>>> or simply if (!edge)
>>> break;
>>>
>>> Also this loop can be rewritten as a do {} while() and it will look:
>>
>> Yep, but I'm not sure if such do {} while() loop is preferred.
>> IIRC there are some docs saying to avoid such loop?
>
> I'm not aware of any such docs, can you point me to them?

Then I guess it's not a problem. Pretty happy to utilize do {} while ()
loop in the future.

Thanks,
Qu
>
>>
>> If there is no such restriction, I would be pretty happy to go that way.
>>
>> Thanks,
>> Qu
>>
>
> <snip>
>