[PATCH 3/5] mm: add a batched helper to clear the young flag for large folios

Baolin Wang baolin.wang at linux.alibaba.com
Tue Feb 24 18:05:01 PST 2026



On 2/25/26 6:03 AM, Rik van Riel wrote:
> On Tue, 2026-02-24 at 09:56 +0800, Baolin Wang wrote:
>>
>> +static inline int test_and_clear_young_ptes(struct vm_area_struct
>> *vma,
>> +					    unsigned long addr,
>> pte_t *ptep,
>> +					    unsigned int nr)
>> +{
>> +	int young = 0;
>> +
>> +	for (;;) {
>> +		young |= ptep_test_and_clear_young(vma, addr, ptep);
>> +		if (--nr == 0)
>> +			break;
>> +		ptep++;
>> +		addr += PAGE_SIZE;
>> +	}
> 
> This may be a nitpick, but could the --nr thing be
> stuck into the loop conditional?
> 
> Something that looks like an infinite loop just
> seems wrong for something so bounded.

It seems that people have different preferences regarding loop patterns.

The current code keeps this loop pattern consistent with other similar 
functions in the same file, as previously suggested by David [1].

[1] 
https://lore.kernel.org/all/3d5cb9a4-6604-4302-a110-3d8ff91baa56@kernel.org/



More information about the linux-arm-kernel mailing list