Re: [PATCH mm-new v6 2/5] mm: khugepaged: refine scan progress number
From: Dev Jain
Date: Thu Feb 05 2026 - 09:25:45 EST
On 05/02/26 5:41 pm, David Hildenbrand (arm) wrote:
> On 2/5/26 07:08, Vernon Yang wrote:
>> On Thu, Feb 5, 2026 at 5:35 AM David Hildenbrand (arm)
>> <david@xxxxxxxxxx> wrote:
>>>
>>> [...]
>>>
>>>> + if (cur_progress) {
>>>> + if (_pte >= pte + HPAGE_PMD_NR)
>>>> + *cur_progress = HPAGE_PMD_NR;
>>>> + else
>>>> + *cur_progress = _pte - pte + 1;
>>>
>>> *cur_progress = max(_pte - pte + 1, HPAGE_PMD_NR);
>>
>> I guess, your meaning is "min(_pte - pte + 1, HPAGE_PMD_NR)", not max().
>
> Yes!
>
>>
>>> ?
>>>
>>> It's still a bit nasty, though.
>>>
>>> Can't we just add one at the beginning of the loop and let the compiler
>>> optimize that? ;)
>>
>> I'm also worried that the compiler can't optimize this since the body of
>> the loop is complex, as with Dev's opinion [1].
>
> Why do we even have to optimize this? :)
>
> Premature ... ? :)
I mean .... we don't, but the alternate is a one liner using max().
The objective is to compute the number of iterations of the for-loop.
It just seems weird to me to track that in the loop, when we have the
loop iterator, which *literally* does that only.
Anyhow, I won't shout in any case : ) If you deem incrementing in the
loop prettier, that's fine.