[PATCH v4 0/2] ext4: fix shrinker scan budget accounting, plus a related cleanup

From: Qiliang Yuan

Date: Thu Oct 01 2026 - 03:47:50 EST


This reverts the v3 simplification of the ext4_es_scan() shrinker
scan-budget fix, keeping the unrelated locked_ei cleanup from v3.

Patch 1 keys SHRINK_STOP off nr_scanned (extents actually examined)
again instead of nr_shrunk (extents actually freed). Jan Kara pointed
out that a batch finding every extent still referenced and freeing
none of it is still real, useful aging progress, not "nothing left to
reclaim"; Sashiko AI review independently flagged the same issue.
This restores Jan Kara's v1 Reviewed-by: the diff in ext4_es_scan()
and __es_shrink() is unchanged from what he reviewed there (only the
explanatory comment reads differently).

Patch 2 is unchanged from v3: it removes __es_shrink()'s locked_ei
parameter, which Zhang Yi noted is dead since its sole caller always
passes NULL. It keeps Jan Kara's Reviewed-by from v3, which still
applies unchanged.

Signed-off-by: Qiliang Yuan <odys.yuan@xxxxxxxxx>
---
V3 -> V4:
- Revert the v3 simplification in patch 1: key SHRINK_STOP off
nr_scanned (extents actually examined) again, not nr_shrunk
(extents actually freed). Jan Kara rejected v3 on exactly this
point; Sashiko AI review independently flagged the same issue.
Restore Jan Kara's v1 Reviewed-by on patch 1, since the diff is
unchanged from what he reviewed there. Patch 2 is untouched by
this revert and keeps Jan Kara's Reviewed-by from v3.
- Re-measure patch 1's test data against the reverted fix
(239 -> 1 calls with nr_scanned == 0, vs v3's 238 -> 1 with
nr_shrunk == 0).

V2 -> V3:
- Drop the sc->nr_scanned computation entirely; just return
SHRINK_STOP when __es_shrink() frees nothing (Zhang Yi, Sashiko AI
review).
- Add patch 2/2: remove the now-dead locked_ei parameter (Zhang Yi).
- Add a Fixes: tag for the commit that split count_objects()/
scan_objects() apart, and Cc: stable, matching the equivalent jbd2
fix.
- Re-measure test data against the simplified fix (429 -> 238 calls).

V1 -> V2:
- Correct the comment and commit message: nr_scanned == 0 is not
only reachable when sbi->s_es_list is genuinely empty, also when
every inode walked was skipped or had nothing currently
shrinkable. No code or test data changes.

v3: https://lore.kernel.org/r/20260930-fix-ext4-es-scan-nr-scanned-v3-0-9aef0be87d21@xxxxxxxxx
v2: https://lore.kernel.org/r/20260929-fix-ext4-es-scan-nr-scanned-v2-1-f4e8f6f6b8b1@xxxxxxxxx
v1: https://lore.kernel.org/r/20260928-fix-ext4-es-scan-nr-scanned-v1-1-91d88228b0c8@xxxxxxxxx

---
Qiliang Yuan (2):
ext4: fix shrinker scan budget accounting in ext4_es_scan()
ext4: remove unused locked_ei parameter from __es_shrink()

fs/ext4/extents_status.c | 37 +++++++++++++++++++++++++++++--------
1 file changed, 29 insertions(+), 8 deletions(-)
---
base-commit: 502d801f0ab03e4f32f9a33d203154ce84887921
change-id: 20260928-fix-ext4-es-scan-nr-scanned-5af70744f6cd

Best regards,
--
Qiliang Yuan <odys.yuan@xxxxxxxxx>