From nobody Mon Apr 6 23:23:28 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D98883F880C for ; Tue, 17 Mar 2026 19:11:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773774706; cv=none; b=dSuP/k1aVCYvL3L+/qG79bv8EMl9iO+i4aArx9U4uUPABDsODNlGI/ZPL/yMMVz8qF2/oOSSCLrj1ynEoV0wnxqR3Jcr8uCqm5ArDp3+s8r993xIh75jvQt0S4dvrWYgFwffU7vuJlSXzvspGV7kyTlr+6edPQkZk1TY8Wh9xyk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773774706; c=relaxed/simple; bh=PR5tgNyhL+CVQhWVK3kXM+OexXjXaQ+bvPHkvSxbGGA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SxaIndEyASK0Djl+KeqsIqxj2iqykStjAnbOzIQjPju0MDVAbV4Bnj7clwYQf0aQwcxxYTX/+dz4Sm+gYzpnmLXDdOcaoFFaspH1vVYsyDyVX8HdVFmJ4EbVvlNjKORt57aLcy+xCddG3+2pL0Q9fhbdyQ2OHMte/n7GFbIk2dU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=I9sZ2tas; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="I9sZ2tas" Received: by smtp.kernel.org (Postfix) with ESMTPS id AB3D6C2BCB5; Tue, 17 Mar 2026 19:11:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1773774706; bh=PR5tgNyhL+CVQhWVK3kXM+OexXjXaQ+bvPHkvSxbGGA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=I9sZ2tasDiP0g700EGkQYGCAU2P+C4HkLcesZCj12GUpEE9rl1xDAeZqqRicvUy+l Vf9ryMshXE9irVWyBvZ7GJmsQKfOUHSrarnRxMbaeM2t+yh3IUKw6CW7PE8VgP+45c n35fU4JwFiKiyG7QBgbdyiR5C/DlXZWP37daWMRXMemKSYe29QQTh3zhh6UcPIIKuI HHw/HyiuyA4TgFLtJAdPPZVVewhy7pK+m4SwvQEqm79kn+O9TY66XUr/vFc/9oFWL5 SaSIj/niptGGqazBoQT6UpPxYeuZ6hpPcbiy+1C7GYsscbWjLIuLDPrkgW/+UpJ63P Ek6J6M6QVYJAg== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id A1C46FEDA15; Tue, 17 Mar 2026 19:11:46 +0000 (UTC) From: Kairui Song via B4 Relay Date: Wed, 18 Mar 2026 03:09:00 +0800 Subject: [PATCH 4/8] mm/mglru: scan and count the exact number of folios Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260318-mglru-reclaim-v1-4-2c46f9eb0508@tencent.com> References: <20260318-mglru-reclaim-v1-0-2c46f9eb0508@tencent.com> In-Reply-To: <20260318-mglru-reclaim-v1-0-2c46f9eb0508@tencent.com> To: linux-mm@kvack.org Cc: Andrew Morton , Axel Rasmussen , Yuanchu Xie , Wei Xu , Johannes Weiner , David Hildenbrand , Michal Hocko , Qi Zheng , Shakeel Butt , Lorenzo Stoakes , Barry Song , David Stevens , Chen Ridong , Leno Hou , Yafang Shao , Yu Zhao , Zicheng Wang , Kalesh Singh , Suren Baghdasaryan , Chris Li , Vernon Yang , linux-kernel@vger.kernel.org, Kairui Song X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1773774704; l=3146; i=kasong@tencent.com; s=kasong-sign-tencent; h=from:subject:message-id; bh=ky1RNKZLvXcrdMH1kH0GOekvj38YuXZMcHy4rmbDVXw=; b=553cnEXzCmztoDDKU1GnFdlSR+/vyXytKxAb9StLKpS6UvhbV0dykEwBCqNffnCFJo5+JaTEK 2Ihc40Wy2N/BFNiKqlIvvQgFHbhIaFzs+7QgAGC09dLP7kT7vmNdIM1 X-Developer-Key: i=kasong@tencent.com; a=ed25519; pk=kCdoBuwrYph+KrkJnrr7Sm1pwwhGDdZKcKrqiK8Y1mI= X-Endpoint-Received: by B4 Relay for kasong@tencent.com/kasong-sign-tencent with auth_id=562 X-Original-From: Kairui Song Reply-To: kasong@tencent.com From: Kairui Song Make the scan helpers return the exact number of folios being scanned or isolated. This should make the scan more accurate and easier to follow. Now there is no more need for special handling when there is no progress made. The old livelock prevention `(return isolated || !remaining ? scanned : 0)` is replaced by the natural scan budget exhaustion in try_to_shrink_lruvec, and sort_folio moves ineligible folios to newer generations. Signed-off-by: Kairui Song --- mm/vmscan.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index ed5b5f8dd3c7..4f4548ff3a17 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -4680,7 +4680,7 @@ static bool isolate_folio(struct lruvec *lruvec, stru= ct folio *folio, struct sca =20 static int scan_folios(unsigned long nr_to_scan, struct lruvec *lruvec, struct scan_control *sc, int type, int tier, - struct list_head *list) + struct list_head *list, int *isolatedp) { int i; int gen; @@ -4750,11 +4750,9 @@ static int scan_folios(unsigned long nr_to_scan, str= uct lruvec *lruvec, type ? LRU_INACTIVE_FILE : LRU_INACTIVE_ANON); if (type =3D=3D LRU_GEN_FILE) sc->nr.file_taken +=3D isolated; - /* - * There might not be eligible folios due to reclaim_idx. Check the - * remaining to prevent livelock if it's not making progress. - */ - return isolated || !remaining ? scanned : 0; + + *isolatedp =3D isolated; + return scanned; } =20 static int get_tier_idx(struct lruvec *lruvec, int type) @@ -4819,23 +4817,24 @@ static int isolate_folios(unsigned long nr_to_scan,= struct lruvec *lruvec, int *type_scanned, struct list_head *list) { int i; + int scanned =3D 0; + int isolated =3D 0; int type =3D get_type_to_scan(lruvec, swappiness); =20 for_each_evictable_type(i, swappiness) { - int scanned; int tier =3D get_tier_idx(lruvec, type); =20 *type_scanned =3D type; =20 - scanned =3D scan_folios(nr_to_scan, lruvec, sc, - type, tier, list); - if (scanned) + scanned +=3D scan_folios(nr_to_scan, lruvec, sc, + type, tier, list, &isolated); + if (isolated) return scanned; =20 type =3D !type; } =20 - return 0; + return scanned; } =20 static int evict_folios(unsigned long nr_to_scan, struct lruvec *lruvec, @@ -4852,7 +4851,6 @@ static int evict_folios(unsigned long nr_to_scan, str= uct lruvec *lruvec, struct reclaim_stat stat; struct lru_gen_mm_walk *walk; bool skip_retry =3D false; - struct lru_gen_folio *lrugen =3D &lruvec->lrugen; struct mem_cgroup *memcg =3D lruvec_memcg(lruvec); struct pglist_data *pgdat =3D lruvec_pgdat(lruvec); =20 @@ -4860,10 +4858,7 @@ static int evict_folios(unsigned long nr_to_scan, st= ruct lruvec *lruvec, =20 scanned =3D isolate_folios(nr_to_scan, lruvec, sc, swappiness, &type, &li= st); =20 - scanned +=3D try_to_inc_min_seq(lruvec, swappiness); - - if (evictable_min_seq(lrugen->min_seq, swappiness) + MIN_NR_GENS > lrugen= ->max_seq) - scanned =3D 0; + try_to_inc_min_seq(lruvec, swappiness); =20 lruvec_unlock_irq(lruvec); =20 --=20 2.53.0