Re: [PATCH v5 05/14] mm/mglru: scan and count the exact number of folios

From: Baolin Wang

Date: Tue Apr 14 2026 - 23:16:39 EST




On 4/13/26 12:48 AM, Kairui Song via B4 Relay wrote:
From: Kairui Song <kasong@xxxxxxxxxxx>

Make the scan helpers return the exact number of folios being scanned
or isolated. Since the reclaim loop now has a natural scan budget that
controls the scan progress, returning the scan number and consume the
budget should make the scan more accurate and easier to follow.

The number of scanned folios for each iteration is always positive and
larger than 0, unless the reclaim must stop for a forced aging, so
there is no more need for any special handling when there is no
progress made:

- `return isolated || !remaining ? scanned : 0` in scan_folios: both
the function and the call now just return the exact scan count,
combined with the scan budget introduced in the previous commit to
avoid livelock or under scan.

- `scanned += try_to_inc_min_seq` in evict_folios: adding a bool as a
scan count was kind of confusing and no longer needed to, as scan
number should never be zero as long as there are still evictable
gens. We may encounter a empty old gen that return 0 scan count,
to avoid that, do a try_to_inc_min_seq before isolation which
have slight to none overhead in most cases.

- `evictable_min_seq + MIN_NR_GENS > max_seq` guard in evict_folios:
the per-type get_nr_gens == MIN_NR_GENS check in scan_folios
naturally returns 0 when only two gens remain and breaks the loop.

Also change try_to_inc_min_seq to return void, as its return value is
no longer used by any caller. Move the call before isolate_folios so
that any empty gens created by external folio freeing are flushed, and
add another call after isolate_folios to also flush empty gens that
isolation itself may create.

As I mentioned earlier, the try_to_inc_min_seq() changes here indeed fall outside the scope of "Make the scan helpers return the exact number of folios being scanned or isolated." However, the changes still make sense to me. Anyway, I don't have a strong opinion on this (there's no need for another iteration), so:

Reviewed-by: Baolin Wang <baolin.wang@xxxxxxxxxxxxxxxxx>