From nobody Mon Apr 6 13:45:42 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 5DA9B1096F for ; Thu, 2 Apr 2026 18:53:41 +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=1775156021; cv=none; b=ZTnjql/3a3rc+ENAlTi2051HCZ0lnTRohqudoop4OYkvv/NIcjJEXCGQ1yy4Y/+SYjAuBmU2arY9yasdZ5XdrEgbDAt2shV6O8d9M5txw5odrmL6v9ct6qROei3wOyMXg2gNpgWUJeA6Qx5XFeAxw+bNJM7XeNRbia5XEP94pzI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775156021; c=relaxed/simple; bh=pu/4aSrd7KSa0bxFp6wbeBj72fjrUtTNvGBmWMpcIZ0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=S8p6rXPC2tuN2C4b79lftHSKbdCsKUHTv9ttChLtwFd9qpUuPL0Ms0wuxVhTxiJAJYTZUD2hUzSPc2kHkxyAeZ+Blg4/uii4Ymsx84nJ3Jpq4YY0Szmvnsc5dJ5ZYs/bJB7xQtfBsJnDFPd/Mjh21jRIffEBumGhc8E6PL+xaHA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=m7571P2y; 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="m7571P2y" Received: by smtp.kernel.org (Postfix) with ESMTPS id 25D37C2BCAF; Thu, 2 Apr 2026 18:53:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775156021; bh=pu/4aSrd7KSa0bxFp6wbeBj72fjrUtTNvGBmWMpcIZ0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=m7571P2y00QevWVbuV7/Y4W9iWXwf0BBNsgFp6Xip5qVAkHcvVioaALVPtuh6PfrJ SdeVtjCm9sbx+/f9LwQruGe51pbpsbrM4bde8dUQ+PqKIoATtJJgSYIl3bgzF+pRTJ OCH0JGE6gpIodKzLS7n9h0pg0//uFpURAf4E7KPbG66f3wEDyM6SeJqkNSUsWPWNh3 ySmchgTLPpXu5TcbpsBM0UxjXmOan3sv1QGunSMDX1KZV0isnu1XOai9YR7nU6u+vo WhkrRRnKNP3fLRC3PrggCoea5Q5G8sDo7fyT+VJocEQAlbnuPAfqd4vigkKJTcK+b5 hHl/r/zfp3nmg== 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 0ADFFD6AAF8; Thu, 2 Apr 2026 18:53:41 +0000 (UTC) From: Kairui Song via B4 Relay Date: Fri, 03 Apr 2026 02:53:27 +0800 Subject: [PATCH v3 01/14] mm/mglru: consolidate common code for retrieving evictable size 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: <20260403-mglru-reclaim-v3-1-a285efd6ff91@tencent.com> References: <20260403-mglru-reclaim-v3-0-a285efd6ff91@tencent.com> In-Reply-To: <20260403-mglru-reclaim-v3-0-a285efd6ff91@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, Qi Zheng , Baolin Wang , Kairui Song X-Mailer: b4 0.15.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1775156018; l=3179; i=kasong@tencent.com; s=kasong-sign-tencent; h=from:subject:message-id; bh=lovGNHm1LZYPq5LXk6kp/WVa26J2TdTx/242vg8RH/A=; b=URh7Mqe3jKmhJPz6rFFWysHrVdbxBs4LBSBylx8UBXj0H6es/WNz+eCO20qz09X3nbrdpG4lj QWuNUtc4ovjCIzjmhWKTa/Bj1ph3lntXNkCtGALz4CsfcWpSVmmtZsO 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 Merge commonly used code for counting evictable folios in a lruvec. No behavior change. Return unsigned long instead of long as suggested [ Axel Rasmussen ] Acked-by: Yuanchu Xie Reviewed-by: Barry Song Reviewed-by: Chen Ridong Reviewed-by: Axel Rasmussen Reviewed-by: Baolin Wang Signed-off-by: Kairui Song --- mm/vmscan.c | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 5a8c8fcccbfc..adc07501a137 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -4084,27 +4084,33 @@ static void set_initial_priority(struct pglist_data= *pgdat, struct scan_control sc->priority =3D clamp(priority, DEF_PRIORITY / 2, DEF_PRIORITY); } =20 -static bool lruvec_is_sizable(struct lruvec *lruvec, struct scan_control *= sc) +static unsigned long lruvec_evictable_size(struct lruvec *lruvec, int swap= piness) { int gen, type, zone; - unsigned long total =3D 0; - int swappiness =3D get_swappiness(lruvec, sc); + unsigned long seq, total =3D 0; struct lru_gen_folio *lrugen =3D &lruvec->lrugen; - struct mem_cgroup *memcg =3D lruvec_memcg(lruvec); DEFINE_MAX_SEQ(lruvec); DEFINE_MIN_SEQ(lruvec); =20 for_each_evictable_type(type, swappiness) { - unsigned long seq; - for (seq =3D min_seq[type]; seq <=3D max_seq; seq++) { gen =3D lru_gen_from_seq(seq); - for (zone =3D 0; zone < MAX_NR_ZONES; zone++) total +=3D max(READ_ONCE(lrugen->nr_pages[gen][type][zone]), 0L); } } =20 + return total; +} + +static bool lruvec_is_sizable(struct lruvec *lruvec, struct scan_control *= sc) +{ + unsigned long total; + int swappiness =3D get_swappiness(lruvec, sc); + struct mem_cgroup *memcg =3D lruvec_memcg(lruvec); + + total =3D lruvec_evictable_size(lruvec, swappiness); + /* whether the size is big enough to be helpful */ return mem_cgroup_online(memcg) ? (total >> sc->priority) : total; } @@ -4909,9 +4915,6 @@ static int evict_folios(unsigned long nr_to_scan, str= uct lruvec *lruvec, static bool should_run_aging(struct lruvec *lruvec, unsigned long max_seq, int swappiness, unsigned long *nr_to_scan) { - int gen, type, zone; - unsigned long size =3D 0; - struct lru_gen_folio *lrugen =3D &lruvec->lrugen; DEFINE_MIN_SEQ(lruvec); =20 *nr_to_scan =3D 0; @@ -4919,18 +4922,7 @@ static bool should_run_aging(struct lruvec *lruvec, = unsigned long max_seq, if (evictable_min_seq(min_seq, swappiness) + MIN_NR_GENS > max_seq) return true; =20 - for_each_evictable_type(type, swappiness) { - unsigned long seq; - - for (seq =3D min_seq[type]; seq <=3D max_seq; seq++) { - gen =3D lru_gen_from_seq(seq); - - for (zone =3D 0; zone < MAX_NR_ZONES; zone++) - size +=3D max(READ_ONCE(lrugen->nr_pages[gen][type][zone]), 0L); - } - } - - *nr_to_scan =3D size; + *nr_to_scan =3D lruvec_evictable_size(lruvec, swappiness); /* better to run aging even though eviction is still possible */ return evictable_min_seq(min_seq, swappiness) + MIN_NR_GENS =3D=3D max_se= q; } --=20 2.53.0 From nobody Mon Apr 6 13:45:42 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 79B403009D4 for ; Thu, 2 Apr 2026 18:53:41 +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=1775156021; cv=none; b=tZlGPFQecq2rmERkDOvZXihlfniJz9IHmO1X7v6jvtntNTGxsbDa0ztSiQB8rFaCIONAWS3LzSVytjI8Y91Cs0wiRVV5CpNdGoqEvZhErehmuZposWO6jFie78HyqUmLgQux1f+UeWoUZY/BSEHBii66+UDqvfMmud95DraUIJs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775156021; c=relaxed/simple; bh=DQicmTjn/9uIWRRyCuPoh78Bba+5rJExO8FhG4MsE2s=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=s39p58dEj1R2HYN9dr7kKrHa8fOfpaax5YJ1jV6XFxNYh77gXW5DlZ2OScglWdfR2goXkJVyBZLGjcSOfOphl+AkBAHxlPLCHzurfr68UGUPQ94WRmFwjxJ0pYQRxmKHMsdRgyWxveOcEQ1WIXnfPwm0ca8XQaSAkZXGRbIeS5g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Fi5d6JaY; 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="Fi5d6JaY" Received: by smtp.kernel.org (Postfix) with ESMTPS id 314A5C2BC9E; Thu, 2 Apr 2026 18:53:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775156021; bh=DQicmTjn/9uIWRRyCuPoh78Bba+5rJExO8FhG4MsE2s=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=Fi5d6JaYWFGBWO7nqVVqxAFv84bvrJQqCq0Gl6as4ctb3GNE9XCTCs06kDNbSLNo7 bJeu60FZD1C41jcC7gsVI2bsKwgyjsVnMjvaRkyGAuT/inLpBadBM21/SEioIGS8tM NuQ0fmSlO2AjXPYQ56JeQEu+1C31mzuaBg0cOiRowUN4TIH1zd3E+UI8QXN+CyrlHn xna4pUwtDVDS0AwQhwbaqkPq9Ib61Na0zNmfKy8uoq3ptiGp6Mvr+ivhIGq5pxCY+f CfG7ER7n5U4n/SSkvP2YfpLSQ4j7WF1KmGsE6KYFF7uszW+7BBaeM1c+nBw6v3Xegx KGyq/yin8bw1A== 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 1E3BAD6AAFB; Thu, 2 Apr 2026 18:53:41 +0000 (UTC) From: Kairui Song via B4 Relay Date: Fri, 03 Apr 2026 02:53:28 +0800 Subject: [PATCH v3 02/14] mm/mglru: rename variables related to aging and rotation 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: <20260403-mglru-reclaim-v3-2-a285efd6ff91@tencent.com> References: <20260403-mglru-reclaim-v3-0-a285efd6ff91@tencent.com> In-Reply-To: <20260403-mglru-reclaim-v3-0-a285efd6ff91@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, Qi Zheng , Baolin Wang , Kairui Song X-Mailer: b4 0.15.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1775156018; l=2938; i=kasong@tencent.com; s=kasong-sign-tencent; h=from:subject:message-id; bh=YopP967rKY4tLhCMH601exObOhC9opQifFAJV2p2rAQ=; b=6oMSdHXhw34r4i7royuF3rsQq+nRLzRJEu33doWBmrFDxJ2Th0GvQNX3FAHhrxQPU9YE17DNv SVU/XJObNf4BiXsS8RuQ7x2mhz3kGgFA0Omkzod7vXYBX0VkVdDD2Sc 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 The current variable name isn't helpful. Make the variable names more meaningful. Only naming change, no behavior change. Suggested-by: Barry Song Reviewed-by: Baolin Wang Reviewed-by: Chen Ridong Reviewed-by: Barry Song Signed-off-by: Kairui Song Reviewed-by: Axel Rasmussen --- mm/vmscan.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index adc07501a137..f336f89a2de6 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -4934,7 +4934,7 @@ static bool should_run_aging(struct lruvec *lruvec, u= nsigned long max_seq, */ static long get_nr_to_scan(struct lruvec *lruvec, struct scan_control *sc,= int swappiness) { - bool success; + bool need_aging; unsigned long nr_to_scan; struct mem_cgroup *memcg =3D lruvec_memcg(lruvec); DEFINE_MAX_SEQ(lruvec); @@ -4942,7 +4942,7 @@ static long get_nr_to_scan(struct lruvec *lruvec, str= uct scan_control *sc, int s if (mem_cgroup_below_min(sc->target_mem_cgroup, memcg)) return -1; =20 - success =3D should_run_aging(lruvec, max_seq, swappiness, &nr_to_scan); + need_aging =3D should_run_aging(lruvec, max_seq, swappiness, &nr_to_scan); =20 /* try to scrape all its memory if this memcg was deleted */ if (nr_to_scan && !mem_cgroup_online(memcg)) @@ -4951,7 +4951,7 @@ static long get_nr_to_scan(struct lruvec *lruvec, str= uct scan_control *sc, int s nr_to_scan =3D apply_proportional_protection(memcg, sc, nr_to_scan); =20 /* try to get away with not aging at the default priority */ - if (!success || sc->priority =3D=3D DEF_PRIORITY) + if (!need_aging || sc->priority =3D=3D DEF_PRIORITY) return nr_to_scan >> sc->priority; =20 /* stop scanning this lruvec as it's low on cold folios */ @@ -5040,7 +5040,7 @@ static bool try_to_shrink_lruvec(struct lruvec *lruve= c, struct scan_control *sc) =20 static int shrink_one(struct lruvec *lruvec, struct scan_control *sc) { - bool success; + bool need_rotate; unsigned long scanned =3D sc->nr_scanned; unsigned long reclaimed =3D sc->nr_reclaimed; struct mem_cgroup *memcg =3D lruvec_memcg(lruvec); @@ -5058,7 +5058,7 @@ static int shrink_one(struct lruvec *lruvec, struct s= can_control *sc) memcg_memory_event(memcg, MEMCG_LOW); } =20 - success =3D try_to_shrink_lruvec(lruvec, sc); + need_rotate =3D try_to_shrink_lruvec(lruvec, sc); =20 shrink_slab(sc->gfp_mask, pgdat->node_id, memcg, sc->priority); =20 @@ -5068,10 +5068,10 @@ static int shrink_one(struct lruvec *lruvec, struct= scan_control *sc) =20 flush_reclaim_state(sc); =20 - if (success && mem_cgroup_online(memcg)) + if (need_rotate && mem_cgroup_online(memcg)) return MEMCG_LRU_YOUNG; =20 - if (!success && lruvec_is_sizable(lruvec, sc)) + if (!need_rotate && lruvec_is_sizable(lruvec, sc)) return 0; =20 /* one retry if offlined or too small */ --=20 2.53.0 From nobody Mon Apr 6 13:45:42 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 93B5631619B for ; Thu, 2 Apr 2026 18:53:41 +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=1775156021; cv=none; b=ZNIpKzP2jd0qyX0gtQqCZ/3Rg8h+e7plWnVQ1WfPKTgBMm1GJ9ic7EQsthWrCowpnQ3lg6ShHccHSjTabcno47PPBEgyOgE7n8ANz5ZaVWxasjFNY/he3Gh2nAMnj/stth2IsjWIf0Png12ff30ZBfnbfAEWtTEZoFHluwzDYlU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775156021; c=relaxed/simple; bh=VkpgFkQP9kSm8dY+9afCyPiICs3NYwoC96e7crLfYA8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ViXmBR7RcGIZbZLbLshw1jMdxfhjAa8lJYLjRnwVsUVUkf22mzvEE55ui2JDP7AQg6TMLM1m2VHWvYf1eBFd8X3ISjL4kzhM8Nw8+m4NHqgXl8roQNyyIWm7qvZOAunwy5U5T1ZO7uOYqvx/eYZiyTvbmDlfgaoDLDMevPFqhQQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OtWGs+0r; 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="OtWGs+0r" Received: by smtp.kernel.org (Postfix) with ESMTPS id 504DCC2BCC4; Thu, 2 Apr 2026 18:53:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775156021; bh=VkpgFkQP9kSm8dY+9afCyPiICs3NYwoC96e7crLfYA8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=OtWGs+0rTZdlWsMw64Jz7GYlD8+ZV+Zj+xo6RoMeqkwM310pC6mv256ZLZOnjfqmz vdVKqIpkqw/34k7z5IouUTzkOV189OfKk54GS4n3yLY+DzQWs521r6FM3BwdNJNQCn DpieNCr2CO0R45w2DDxg/fh7Ho1b3YD9DZ1v33ZrYNzFLUe4S1tpFD5G5vVtTGijXN NGn+CLwVrBphmjRm1prRYbwLPbHUjo7GZsdUqQwcBEjNh0fO95f+HDIvP787GO6ziK 5OnX4P/FlkLbTPFRFkTHQKDPbjaziaXuxHEcnB0YYKuWiNk6ms9oKLbCL9fE+gQGwX 9UItINeihXF2A== 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 45FF5D6AAFC; Thu, 2 Apr 2026 18:53:41 +0000 (UTC) From: Kairui Song via B4 Relay Date: Fri, 03 Apr 2026 02:53:29 +0800 Subject: [PATCH v3 03/14] mm/mglru: relocate the LRU scan batch limit to callers 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: <20260403-mglru-reclaim-v3-3-a285efd6ff91@tencent.com> References: <20260403-mglru-reclaim-v3-0-a285efd6ff91@tencent.com> In-Reply-To: <20260403-mglru-reclaim-v3-0-a285efd6ff91@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, Qi Zheng , Baolin Wang , Kairui Song X-Mailer: b4 0.15.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1775156018; l=3260; i=kasong@tencent.com; s=kasong-sign-tencent; h=from:subject:message-id; bh=t1HUAx5d1QFG9Hfnk5BrzG1D63onxNMjgtf1TQ7zmGc=; b=GOjNFgd9u+a6HEbec8EHvZzLzVytLP1RAikjRqZr9s0k06yP5i/tq4xusoK34nfAQQAD+B6LE PMP181WbUVHCL1WzYp0UrS49WfvMRLmOi3pDESCUEKVzbA5lYoqSf0m 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 Same as active / inactive LRU, MGLRU isolates and scans folios in batches. The batch split is done hidden deep in the helper, which makes the code harder to follow. The helper's arguments are also confusing since callers usually request more folios than the batch size, so the helper almost never processes the full requested amount. Move the batch splitting into the top loop to make it cleaner, there should be no behavior change. Reviewed-by: Axel Rasmussen Reviewed-by: Baolin Wang Reviewed-by: Barry Song Signed-off-by: Kairui Song --- mm/vmscan.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index f336f89a2de6..963362523782 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -4695,10 +4695,10 @@ static int scan_folios(unsigned long nr_to_scan, st= ruct lruvec *lruvec, int scanned =3D 0; int isolated =3D 0; int skipped =3D 0; - int scan_batch =3D min(nr_to_scan, MAX_LRU_BATCH); - int remaining =3D scan_batch; + unsigned long remaining =3D nr_to_scan; struct lru_gen_folio *lrugen =3D &lruvec->lrugen; =20 + VM_WARN_ON_ONCE(nr_to_scan > MAX_LRU_BATCH); VM_WARN_ON_ONCE(!list_empty(list)); =20 if (get_nr_gens(lruvec, type) =3D=3D MIN_NR_GENS) @@ -4751,7 +4751,7 @@ static int scan_folios(unsigned long nr_to_scan, stru= ct lruvec *lruvec, mod_lruvec_state(lruvec, item, isolated); mod_lruvec_state(lruvec, PGREFILL, sorted); mod_lruvec_state(lruvec, PGSCAN_ANON + type, isolated); - trace_mm_vmscan_lru_isolate(sc->reclaim_idx, sc->order, scan_batch, + trace_mm_vmscan_lru_isolate(sc->reclaim_idx, sc->order, nr_to_scan, scanned, skipped, isolated, type ? LRU_INACTIVE_FILE : LRU_INACTIVE_ANON); if (type =3D=3D LRU_GEN_FILE) @@ -4987,7 +4987,7 @@ static bool should_abort_scan(struct lruvec *lruvec, = struct scan_control *sc) =20 static bool try_to_shrink_lruvec(struct lruvec *lruvec, struct scan_contro= l *sc) { - long nr_to_scan; + long nr_batch, nr_to_scan; unsigned long scanned =3D 0; int swappiness =3D get_swappiness(lruvec, sc); =20 @@ -4998,7 +4998,8 @@ static bool try_to_shrink_lruvec(struct lruvec *lruve= c, struct scan_control *sc) if (nr_to_scan <=3D 0) break; =20 - delta =3D evict_folios(nr_to_scan, lruvec, sc, swappiness); + nr_batch =3D min(nr_to_scan, MAX_LRU_BATCH); + delta =3D evict_folios(nr_batch, lruvec, sc, swappiness); if (!delta) break; =20 @@ -5623,6 +5624,7 @@ static int run_aging(struct lruvec *lruvec, unsigned = long seq, static int run_eviction(struct lruvec *lruvec, unsigned long seq, struct s= can_control *sc, int swappiness, unsigned long nr_to_reclaim) { + int nr_batch; DEFINE_MAX_SEQ(lruvec); =20 if (seq + MIN_NR_GENS > max_seq) @@ -5639,8 +5641,8 @@ static int run_eviction(struct lruvec *lruvec, unsign= ed long seq, struct scan_co if (sc->nr_reclaimed >=3D nr_to_reclaim) return 0; =20 - if (!evict_folios(nr_to_reclaim - sc->nr_reclaimed, lruvec, sc, - swappiness)) + nr_batch =3D min(nr_to_reclaim - sc->nr_reclaimed, MAX_LRU_BATCH); + if (!evict_folios(nr_batch, lruvec, sc, swappiness)) return 0; =20 cond_resched(); --=20 2.53.0 From nobody Mon Apr 6 13:45:42 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 A1AA935A39D for ; Thu, 2 Apr 2026 18:53:41 +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=1775156021; cv=none; b=bkgft1AsbxxKXSVnlngU18bkxSdJo2VeFjfvE8G5+xz7e0UQXS/6Wl7MK0eEFC5/4Y6ZfDr+6J+umKckPpU5XhLZT1hIYVW0UNCyH2sEoUOTsmxhovuzqmoYgHCNwg48PKvtIFfpqPXagoqhL1g5OT2IJydLQ+I8xwQUArsIFdA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775156021; c=relaxed/simple; bh=hFax/AJR7bXH8oWQu+9VlOcr2nxZvl2KLMxTavwO1yQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=VD8qG3bRsAXVdAqidSYYKmDvMl+RRm8rNasG8O8vQcFmAzny3+16G9MD8sly7hJWcGh7RiWDoXY7xYMVZkwEwq5j2U1EFHweU35esYhOLzAGc8GC/rYRQoGpnz5+vCZKfht8EYO0tihJ7+w5R98cBZF6weMqfJCooqlCzydaLBw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sftjierH; 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="sftjierH" Received: by smtp.kernel.org (Postfix) with ESMTPS id 6405DC2BCB0; Thu, 2 Apr 2026 18:53:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775156021; bh=hFax/AJR7bXH8oWQu+9VlOcr2nxZvl2KLMxTavwO1yQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=sftjierHx+QAPwJU4sSL/inATfAl9632hi7PgveGFykQPscPPeSTxP1tm21AXqCpy Yndwpgn0xQ5Fthh/p8elPDArPRpswmExNmKWvCWQwj2IF3/0g9KRks7Wm2Y4NNS5zi HViVifu057I8FmAOrvAQ0imIrOU5HZe6xteFqPAgLg3F06JQFRPgsQm0AJdK64MuWO cjb04enNHyIHSSUdceSQBOH3wJDiBBPH2eVdj/CAdnpm8VTMlZ0Hg5rZDSzlqmofyl LVTg6W1nASm9MsSF19dxk6Jj3OilnasP0770WaMwICerHjOs7AmND08H62zzsZSRO5 S6YyM8ZWuzFRg== 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 59554D6AAF9; Thu, 2 Apr 2026 18:53:41 +0000 (UTC) From: Kairui Song via B4 Relay Date: Fri, 03 Apr 2026 02:53:30 +0800 Subject: [PATCH v3 04/14] mm/mglru: restructure the reclaim loop 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: <20260403-mglru-reclaim-v3-4-a285efd6ff91@tencent.com> References: <20260403-mglru-reclaim-v3-0-a285efd6ff91@tencent.com> In-Reply-To: <20260403-mglru-reclaim-v3-0-a285efd6ff91@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, Qi Zheng , Baolin Wang , Kairui Song X-Mailer: b4 0.15.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1775156018; l=6279; i=kasong@tencent.com; s=kasong-sign-tencent; h=from:subject:message-id; bh=n1QR1XMc/29NkkvOx9rKp1KXHPY21ys1yUuIEmcMTFs=; b=G2FlHwh8fkci9hkqgt8brGGRiFDG3vSgUQKIiPALDlcX9XXO7hjk0OmtODfv1ItaZGTgJN5e8 wl31xAq/atNCjkLJtnO4p+155BUSX2PKlRhdTZPG/V5WmwIHXdwQ6gU 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 The current loop will calculate the scan number on each iteration. The number of folios to scan is based on the LRU length, with some unclear behaviors, eg, the scan number is only shifted by reclaim priority when aging is not needed or when at the default priority, and it couples the number calculation with aging and rotation. Adjust, simplify it, and decouple aging and rotation. Just calculate the scan number for once at the beginning of the reclaim, always respect the reclaim priority, and make the aging and rotation more explicit. This slightly changes how aging and offline memcg reclaim works: Previously, aging was always skipped at DEF_PRIORITY even when eviction was impossible. Now, aging is always triggered when it is necessary to make progress. The old behavior may waste a reclaim iteration only to escalate priority, potentially causing over-reclaim of slab and breaking reclaim balance in multi-cgroup setups. Similar for offline memcg. Previously, offline memcg wouldn't be aged unless it didn't have any evictable folios. Now, we might age it if it has only 3 generations and the reclaim priority is less than DEF_PRIORITY, which should be fine. On one hand, offline memcg might still hold long-term folios, and in fact, a long-existing offline memcg must be pinned by some long-term folios like shmem. These folios might be used by other memcg, so aging them as ordinary memcg seems correct. Besides, aging enables further reclaim of an offlined memcg, which will certainly happen if we keep shrinking it. And offline memcg might soon be no longer an issue with reparenting. Overall, the memcg LRU rotation, as described in mmzone.h, remains the same. Reviewed-by: Axel Rasmussen Signed-off-by: Kairui Song --- mm/vmscan.c | 74 +++++++++++++++++++++++++++++++++------------------------= ---- 1 file changed, 40 insertions(+), 34 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 963362523782..93ffb3d98fed 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -4913,49 +4913,44 @@ static int evict_folios(unsigned long nr_to_scan, s= truct lruvec *lruvec, } =20 static bool should_run_aging(struct lruvec *lruvec, unsigned long max_seq, - int swappiness, unsigned long *nr_to_scan) + struct scan_control *sc, int swappiness) { DEFINE_MIN_SEQ(lruvec); =20 - *nr_to_scan =3D 0; /* have to run aging, since eviction is not possible anymore */ if (evictable_min_seq(min_seq, swappiness) + MIN_NR_GENS > max_seq) return true; =20 - *nr_to_scan =3D lruvec_evictable_size(lruvec, swappiness); + /* try to get away with not aging at the default priority */ + if (sc->priority =3D=3D DEF_PRIORITY) + return false; + /* better to run aging even though eviction is still possible */ return evictable_min_seq(min_seq, swappiness) + MIN_NR_GENS =3D=3D max_se= q; } =20 -/* - * For future optimizations: - * 1. Defer try_to_inc_max_seq() to workqueues to reduce latency for memcg - * reclaim. - */ -static long get_nr_to_scan(struct lruvec *lruvec, struct scan_control *sc,= int swappiness) +static long get_nr_to_scan(struct lruvec *lruvec, struct scan_control *sc, + struct mem_cgroup *memcg, int swappiness) { - bool need_aging; - unsigned long nr_to_scan; - struct mem_cgroup *memcg =3D lruvec_memcg(lruvec); - DEFINE_MAX_SEQ(lruvec); - - if (mem_cgroup_below_min(sc->target_mem_cgroup, memcg)) - return -1; - - need_aging =3D should_run_aging(lruvec, max_seq, swappiness, &nr_to_scan); + unsigned long evictable, nr_to_scan; =20 + evictable =3D lruvec_evictable_size(lruvec, swappiness); + nr_to_scan =3D evictable; /* try to scrape all its memory if this memcg was deleted */ - if (nr_to_scan && !mem_cgroup_online(memcg)) + if (!mem_cgroup_online(memcg)) return nr_to_scan; =20 nr_to_scan =3D apply_proportional_protection(memcg, sc, nr_to_scan); =20 - /* try to get away with not aging at the default priority */ - if (!need_aging || sc->priority =3D=3D DEF_PRIORITY) - return nr_to_scan >> sc->priority; + /* + * Always respect scan priority, minimally target some folios + * to keep reclaim moving forwards. + */ + nr_to_scan >>=3D sc->priority; + if (!nr_to_scan) + nr_to_scan =3D min(evictable, SWAP_CLUSTER_MAX); =20 - /* stop scanning this lruvec as it's low on cold folios */ - return try_to_inc_max_seq(lruvec, max_seq, swappiness, false) ? -1 : 0; + return nr_to_scan; } =20 static bool should_abort_scan(struct lruvec *lruvec, struct scan_control *= sc) @@ -4985,31 +4980,43 @@ static bool should_abort_scan(struct lruvec *lruvec= , struct scan_control *sc) return true; } =20 +/* + * For future optimizations: + * 1. Defer try_to_inc_max_seq() to workqueues to reduce latency for memcg + * reclaim. + */ static bool try_to_shrink_lruvec(struct lruvec *lruvec, struct scan_contro= l *sc) { + bool need_rotate =3D false; long nr_batch, nr_to_scan; - unsigned long scanned =3D 0; int swappiness =3D get_swappiness(lruvec, sc); + struct mem_cgroup *memcg =3D lruvec_memcg(lruvec); =20 - while (true) { + nr_to_scan =3D get_nr_to_scan(lruvec, sc, memcg, swappiness); + while (nr_to_scan > 0) { int delta; + DEFINE_MAX_SEQ(lruvec); =20 - nr_to_scan =3D get_nr_to_scan(lruvec, sc, swappiness); - if (nr_to_scan <=3D 0) + if (mem_cgroup_below_min(sc->target_mem_cgroup, memcg)) { + need_rotate =3D true; break; + } + + if (should_run_aging(lruvec, max_seq, sc, swappiness)) { + if (try_to_inc_max_seq(lruvec, max_seq, swappiness, false)) + need_rotate =3D true; + break; + } =20 nr_batch =3D min(nr_to_scan, MAX_LRU_BATCH); delta =3D evict_folios(nr_batch, lruvec, sc, swappiness); if (!delta) break; =20 - scanned +=3D delta; - if (scanned >=3D nr_to_scan) - break; - if (should_abort_scan(lruvec, sc)) break; =20 + nr_to_scan -=3D delta; cond_resched(); } =20 @@ -5035,8 +5042,7 @@ static bool try_to_shrink_lruvec(struct lruvec *lruve= c, struct scan_control *sc) reclaim_throttle(pgdat, VMSCAN_THROTTLE_WRITEBACK); } =20 - /* whether this lruvec should be rotated */ - return nr_to_scan < 0; + return need_rotate; } =20 static int shrink_one(struct lruvec *lruvec, struct scan_control *sc) --=20 2.53.0 From nobody Mon Apr 6 13:45:42 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 B4C41362130 for ; Thu, 2 Apr 2026 18:53:41 +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=1775156021; cv=none; b=JfKfxP/P8WZPECIer0bAx7qbeAInkaqBkdaDNA1dttM4Mnw6Hn1Q/1PgUAwHDiTEpeVL8J5mLDxw3Ac0SzjaeIA54FDbZGfm+pJ7agl3vjnB0qWCOVaFkSMssX6DezgscePlFGxCyGvV0IKvhzzRVc9vY46aLOs6XICITqD3sOY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775156021; c=relaxed/simple; bh=nLUcryvh8JhOr7k78Kv6A3d7lpY5EZnKbtRKNSfM9YY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=N6tHzN9rbBahukiSKkUcBFG88dY2naWVXDzgcgsqDZ0x3WsxkGIJexrv6VtPm8mHR2dV/BMf49OwI4c7rcgyExjdsjDkP1Xpec+tbXWe8w5/Icfe1VWhp9eAmyDpAoTxmR803dqyHuLpE6ride5OFxxE48PbLpZ7unDXe7d56h0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sg7iA4bO; 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="sg7iA4bO" Received: by smtp.kernel.org (Postfix) with ESMTPS id 780D3C2BCF6; Thu, 2 Apr 2026 18:53:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775156021; bh=nLUcryvh8JhOr7k78Kv6A3d7lpY5EZnKbtRKNSfM9YY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=sg7iA4bOK0uttvuXryrD47L5kZOWQYqf9VXU6lCx8sxSh7WHkotGnTZ7PGw8axokQ NsrLlM8l5IOJoQDWFRj80xw2tYLoPpR/2Wjfgz1G80o6XiTOtf7r9/hxO3yZRpCcyG qzzLVKA9SxV1D6peiv+qqUFAJiA+QnnJl8qkJ3qs59mSlrz+26sgu5B5LvKCcobeq9 GFoWIDfdWJSLCi76D8RdinGNLrvOY9NI7U5t0o6pQBYtZnfVYBO789jXIVPJro9gVo RhmLTl/iWNuxnezZO34iCsv9o9GNtsHKbLniTwtQIgMtojio/+zZAN1JeSp3wlyWyE DJJPka+KOg0LA== 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 6BF4CD6AAF8; Thu, 2 Apr 2026 18:53:41 +0000 (UTC) From: Kairui Song via B4 Relay Date: Fri, 03 Apr 2026 02:53:31 +0800 Subject: [PATCH v3 05/14] 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: <20260403-mglru-reclaim-v3-5-a285efd6ff91@tencent.com> References: <20260403-mglru-reclaim-v3-0-a285efd6ff91@tencent.com> In-Reply-To: <20260403-mglru-reclaim-v3-0-a285efd6ff91@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, Qi Zheng , Baolin Wang , Kairui Song X-Mailer: b4 0.15.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1775156018; l=7080; i=kasong@tencent.com; s=kasong-sign-tencent; h=from:subject:message-id; bh=CYDE9ec7Cz1H+HSpLojRtRdyUXE6Vvbwr0W8YOLFv64=; b=pwjY+MndiwmgMz/YebgPM9NYr5g9YjMfJpvIkVtia9stPEJLx9oEpYdW0Mm1K4Ah+Em0zIgIJ yW78D6uQYKjAVFpm24ZXMaKiwHTW3XJjpkVpf7yqffaoz4XkVVRCs8b 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. 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 +=3D 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 =3D=3D 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. The scan still stops if there are only two gens left as the scan number will be zero, this behavior is same as before. This force gen protection may get removed or softened later to improve the reclaim a bit more. Signed-off-by: Kairui Song Reviewed-by: Axel Rasmussen --- mm/vmscan.c | 60 ++++++++++++++++++++++++++++++---------------------------= --- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 93ffb3d98fed..643f9fc10214 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -3878,10 +3878,9 @@ static bool inc_min_seq(struct lruvec *lruvec, int t= ype, int swappiness) return true; } =20 -static bool try_to_inc_min_seq(struct lruvec *lruvec, int swappiness) +static void try_to_inc_min_seq(struct lruvec *lruvec, int swappiness) { int gen, type, zone; - bool success =3D false; bool seq_inc_flag =3D false; struct lru_gen_folio *lrugen =3D &lruvec->lrugen; DEFINE_MIN_SEQ(lruvec); @@ -3907,11 +3906,10 @@ static bool try_to_inc_min_seq(struct lruvec *lruve= c, int swappiness) =20 /* * If min_seq[type] of both anonymous and file is not increased, - * we can directly return false to avoid unnecessary checking - * overhead later. + * return here to avoid unnecessary checking overhead later. */ if (!seq_inc_flag) - return success; + return; =20 /* see the comment on lru_gen_folio */ if (swappiness && swappiness <=3D MAX_SWAPPINESS) { @@ -3929,10 +3927,7 @@ static bool try_to_inc_min_seq(struct lruvec *lruvec= , int swappiness) =20 reset_ctrl_pos(lruvec, type, true); WRITE_ONCE(lrugen->min_seq[type], min_seq[type]); - success =3D true; } - - return success; } =20 static bool inc_max_seq(struct lruvec *lruvec, unsigned long seq, int swap= piness) @@ -4686,7 +4681,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; @@ -4756,11 +4751,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) @@ -4804,33 +4797,36 @@ static int get_type_to_scan(struct lruvec *lruvec, = int swappiness) =20 static int isolate_folios(unsigned long nr_to_scan, struct lruvec *lruvec, struct scan_control *sc, int swappiness, - int *type_scanned, struct list_head *list) + struct list_head *list, int *isolated, + int *isolate_type, int *isolate_scanned) { int i; + int scanned =3D 0; int type =3D get_type_to_scan(lruvec, swappiness); =20 for_each_evictable_type(i, swappiness) { - int scanned; + int type_scan; int tier =3D get_tier_idx(lruvec, type); =20 - *type_scanned =3D type; + type_scan =3D scan_folios(nr_to_scan, lruvec, sc, + type, tier, list, isolated); =20 - scanned =3D scan_folios(nr_to_scan, lruvec, sc, type, tier, list); - if (scanned) - return scanned; + scanned +=3D type_scan; + if (*isolated) { + *isolate_type =3D type; + *isolate_scanned =3D type_scan; + break; + } =20 type =3D !type; } =20 - return 0; + return scanned; } =20 static int evict_folios(unsigned long nr_to_scan, struct lruvec *lruvec, struct scan_control *sc, int swappiness) { - int type; - int scanned; - int reclaimed; LIST_HEAD(list); LIST_HEAD(clean); struct folio *folio; @@ -4838,19 +4834,23 @@ static int evict_folios(unsigned long nr_to_scan, s= truct lruvec *lruvec, enum node_stat_item item; struct reclaim_stat stat; struct lru_gen_mm_walk *walk; + int scanned, reclaimed; + int isolated =3D 0, type, type_scanned; 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 lruvec_lock_irq(lruvec); =20 - scanned =3D isolate_folios(nr_to_scan, lruvec, sc, swappiness, &type, &li= st); + /* In case folio deletion left empty old gens, flush them */ + try_to_inc_min_seq(lruvec, swappiness); =20 - scanned +=3D try_to_inc_min_seq(lruvec, swappiness); + scanned =3D isolate_folios(nr_to_scan, lruvec, sc, swappiness, + &list, &isolated, &type, &type_scanned); =20 - if (evictable_min_seq(lrugen->min_seq, swappiness) + MIN_NR_GENS > lrugen= ->max_seq) - scanned =3D 0; + /* Isolation might create empty gen, flush them */ + if (scanned) + try_to_inc_min_seq(lruvec, swappiness); =20 lruvec_unlock_irq(lruvec); =20 @@ -4861,7 +4861,7 @@ static int evict_folios(unsigned long nr_to_scan, str= uct lruvec *lruvec, sc->nr.unqueued_dirty +=3D stat.nr_unqueued_dirty; sc->nr_reclaimed +=3D reclaimed; trace_mm_vmscan_lru_shrink_inactive(pgdat->node_id, - scanned, reclaimed, &stat, sc->priority, + type_scanned, reclaimed, &stat, sc->priority, type ? LRU_INACTIVE_FILE : LRU_INACTIVE_ANON); =20 list_for_each_entry_safe_reverse(folio, next, &list, lru) { --=20 2.53.0 From nobody Mon Apr 6 13:45:42 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 B7B95371CF5 for ; Thu, 2 Apr 2026 18:53:41 +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=1775156021; cv=none; b=UO7ro8RuqalGqEv9wWswLUEyo5QF7Uoe2lx4g6qdBq3RFp/33vEjShuaT2fiOMzFT8k6j4Sg0mTINN1vpsAkRxdeXqPQZcnWw9V6F72trG4UC1LCh1dW3+N7uN8uWhvUOx3qlEKhgdsQoA2TAtzf6j8HNXwFJ916MUGN+JM0UPc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775156021; c=relaxed/simple; bh=x2iJwRWxsNWZo0hiLp3oKxL+smbwMKj3xOseviAzoms=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lPDVWTAmRwisywze1RA0RFRVNp2ntGa0CWla3q53H1j+tsOFZ+M1QyXhYpq5tZRaD9R56nyaDB0NgwxHngRTdIzYLsfhkCMMCbL/bUO5io85oubc9kJdjmlEMEFEtGtd5ZiCrPM5V2RwooZ4dE6IWZjM3yT96BEIN0+qIUuX7XA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cm6w2Vkg; 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="cm6w2Vkg" Received: by smtp.kernel.org (Postfix) with ESMTPS id 89325C2BCB7; Thu, 2 Apr 2026 18:53:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775156021; bh=x2iJwRWxsNWZo0hiLp3oKxL+smbwMKj3xOseviAzoms=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=cm6w2Vkgwa6C6VFPcS5n7ghuj6S0F2SG01gFw/0eROrsBejbSW8GizVCkoY6qZDaQ qHqzY4K3eNx8IFJSQ+1G8Yi3HoEKLyD2qTKIEkid7DXCNHQMIWKr3kEme6nOohpumH a7k7zaxJUw7tQAmYXtJFWJsSVHcoKbzrZO3AkA7AnxLojm2GfS3bRpVfyJj2MSB3eA WWJyacKDXfRYzT+56QnKqQSXq4HViQX9cXZ7/+E09yzSkGVpfneo1krdTEf/PMO+zb tFOPfaoohPb17JsRvg8XLZS2GiUSlUrJ012SuYtsWCJdufuNEr99vDD72t2Xt2kxA7 tFAt4TaHnjbCg== 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 7ECF8D6AAF9; Thu, 2 Apr 2026 18:53:41 +0000 (UTC) From: Kairui Song via B4 Relay Date: Fri, 03 Apr 2026 02:53:32 +0800 Subject: [PATCH v3 06/14] mm/mglru: use a smaller batch for reclaim 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: <20260403-mglru-reclaim-v3-6-a285efd6ff91@tencent.com> References: <20260403-mglru-reclaim-v3-0-a285efd6ff91@tencent.com> In-Reply-To: <20260403-mglru-reclaim-v3-0-a285efd6ff91@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, Qi Zheng , Baolin Wang , Kairui Song X-Mailer: b4 0.15.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1775156018; l=994; i=kasong@tencent.com; s=kasong-sign-tencent; h=from:subject:message-id; bh=QDWywh4OipGEfwenRADOn5rGg3c0b7fQ30+q0TRFWgY=; b=mZJyHWd8S2PbDZMX7PzME79oAFtxlbgMKsejQcQCfPstJyIfIcrT1wcurlc9jyTtCfzVeYrht Mb68Bn3exRTB6hO4s+5WGWGxGEfgELP3IjZa3HSB+PX+CC7TnGDarI5 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 With a fixed number to reclaim calculated at the beginning, making each following step smaller should reduce the lock contention and avoid over-aggressive reclaim of folios, as it will abort earlier when the number of folios to be reclaimed is reached. Reviewed-by: Axel Rasmussen Reviewed-by: Chen Ridong Reviewed-by: Baolin Wang Signed-off-by: Kairui Song --- mm/vmscan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 643f9fc10214..9c28afb0219c 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -5008,7 +5008,7 @@ static bool try_to_shrink_lruvec(struct lruvec *lruve= c, struct scan_control *sc) break; } =20 - nr_batch =3D min(nr_to_scan, MAX_LRU_BATCH); + nr_batch =3D min(nr_to_scan, MIN_LRU_BATCH); delta =3D evict_folios(nr_batch, lruvec, sc, swappiness); if (!delta) break; --=20 2.53.0 From nobody Mon Apr 6 13:45:42 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 CC4A239B949 for ; Thu, 2 Apr 2026 18:53:41 +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=1775156021; cv=none; b=qj3I+6fQ9Pecra//LuQ/9PpOh9JgWL+ImUewgddxQQRGO37l+rQjyRyddLYQeU5IoaTrVRJyu+EV96dbOgXzCq9h7fsYKVzCCZyPFTJBkxgPbu92lLJcI1/krfHSdPz5DnBHP2YYQrHtxMPYnkdkEUrbr+gYfe8b37oSD7VuVFc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775156021; c=relaxed/simple; bh=EATGoxb144ySghfszsyByP5U86/ZHl8CVCI8i+wfQTE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=s+TVkOtM5j9zOYQ0kIlShpkx/URTqJpLmEATR5D7ndvyCph9F+P+EZGcMtQx7kGzLxYgKm1oB9CnjCbniCIWufPxYNgdVYxwJwF+1rwryNfFXGBD+Zzgvq462318ClsVw4m9LBQ7L/02d7n3bADBzMoKFcADBu7ASTjV+YGy9Kg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sPchXNEV; 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="sPchXNEV" Received: by smtp.kernel.org (Postfix) with ESMTPS id 9C56FC2BCFB; Thu, 2 Apr 2026 18:53:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775156021; bh=EATGoxb144ySghfszsyByP5U86/ZHl8CVCI8i+wfQTE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=sPchXNEVBkAynbKsWBA0BhCbH+FoYVVoxz3JSWFEi+VIlKhfjAyFjmsRAYzNFpOhY 8cPS6Ou/23phVRazFFz1ELEmlc5TsaELxyGghrtTafZ+3QZcEg9ly9NzExOQdoFOVV KghmwhzkXAIs+Jk+Oruxxm8d6L7LTO6BjmU9gqIO/LzmbVvRBtXleWsr2QPrkZh6Gq tbgSOl8qe06t9Zdhw+uh77i0oAz7uYE/lm+KZ3FHXlTjktVDaPzhl4TCqPmSnFO2dy vg0aOIpzNiLYnP17gjFCtgYqsnspkmm46XMGR333krO9k5e6dJSx/VUeRbQBFY3vUh ZEKnu0A+w5Vbw== 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 911EFD6AAFD; Thu, 2 Apr 2026 18:53:41 +0000 (UTC) From: Kairui Song via B4 Relay Date: Fri, 03 Apr 2026 02:53:33 +0800 Subject: [PATCH v3 07/14] mm/mglru: don't abort scan immediately right after aging 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: <20260403-mglru-reclaim-v3-7-a285efd6ff91@tencent.com> References: <20260403-mglru-reclaim-v3-0-a285efd6ff91@tencent.com> In-Reply-To: <20260403-mglru-reclaim-v3-0-a285efd6ff91@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, Qi Zheng , Baolin Wang , Kairui Song X-Mailer: b4 0.15.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1775156018; l=3449; i=kasong@tencent.com; s=kasong-sign-tencent; h=from:subject:message-id; bh=bSy2f/NXeY/jTEGjpMc5skrp7OityVUKdYtvXUwM9i8=; b=QnCc+Y5vPX1EtMTnDjPqM98CZyYXa7TzJ9o1gvPr99U5A7mK5FSBlop3VqXGnX99Bxl5JRVJd 4OapmGaqoHAA3OGBA0cf2x/09kPXxW6LXW+v/C+H3lSS/MVsGNiepHl 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 Right now, if eviction triggers aging, the reclaimer will abort. This is not the optimal strategy for several reasons. Aborting the reclaim early wastes a reclaim cycle when under pressure, and for concurrent reclaim, if the LRU is under aging, all concurrent reclaimers might fail. And if the age has just finished, new cold folios exposed by the aging are not reclaimed until the next reclaim iteration. What's more, the current aging trigger is quite lenient, having 3 gens with a reclaim priority lower than default will trigger aging, and blocks reclaiming from one memcg. This wastes reclaim retry cycles easily. And in the worst case, if the reclaim is making slower progress and all following attempts fail due to being blocked by aging, it triggers unexpected early OOM. And if a lruvec requires aging, it doesn't mean it's hot. Instead, the lruvec could be idle for quite a while, and hence it might contain lots of cold folios to be reclaimed. While it's helpful to rotate memcg LRU after aging for global reclaim, as global reclaim fairness is coupled with the rotation in shrink_many, memcg fairness is instead handled by cgroup iteration in shrink_node_memcgs. So, for memcg level pressure, this abort is not the key part for keeping the fairness. And in most cases, there is no need to age, and fairness must be achieved by upper-level reclaim control. So instead, just keep the scanning going unless one whole batch of folios failed to be isolated or enough folios have been scanned, which is triggered by evict_folios returning 0. And only abort for global reclaim after one batch, so when there are fewer memcgs, progress is still made, and the fairness mechanism described above still works fine. And in most cases, the one more batch attempt for global reclaim might just be enough to satisfy what the reclaimer needs, hence improving global reclaim performance by reducing reclaim retry cycles. Rotation is still there after the reclaim is done, which still follows the comment in mmzone.h. And fairness still looking good. Signed-off-by: Kairui Song Reviewed-by: Axel Rasmussen --- mm/vmscan.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 9c28afb0219c..b3371877762a 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -4987,7 +4987,7 @@ static bool should_abort_scan(struct lruvec *lruvec, = struct scan_control *sc) */ static bool try_to_shrink_lruvec(struct lruvec *lruvec, struct scan_contro= l *sc) { - bool need_rotate =3D false; + bool need_rotate =3D false, should_age =3D false; long nr_batch, nr_to_scan; int swappiness =3D get_swappiness(lruvec, sc); struct mem_cgroup *memcg =3D lruvec_memcg(lruvec); @@ -5005,7 +5005,7 @@ static bool try_to_shrink_lruvec(struct lruvec *lruve= c, struct scan_control *sc) if (should_run_aging(lruvec, max_seq, sc, swappiness)) { if (try_to_inc_max_seq(lruvec, max_seq, swappiness, false)) need_rotate =3D true; - break; + should_age =3D true; } =20 nr_batch =3D min(nr_to_scan, MIN_LRU_BATCH); @@ -5016,6 +5016,10 @@ static bool try_to_shrink_lruvec(struct lruvec *lruv= ec, struct scan_control *sc) if (should_abort_scan(lruvec, sc)) break; =20 + /* For cgroup reclaim, fairness is handled by iterator, not rotation */ + if (root_reclaim(sc) && should_age) + break; + nr_to_scan -=3D delta; cond_resched(); } --=20 2.53.0 From nobody Mon Apr 6 13:45:42 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 E7A9D3D8917 for ; Thu, 2 Apr 2026 18:53:41 +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=1775156022; cv=none; b=eNe3DY3NiQOh2m/zuizD9fdi1e3CkYEOQAYGaw57vUdd/1DPQHvZFHBgbdOE4cGlghYCQFpRIQI7Ut2rdUcTs0zlBnmS4ZaXfnRllhLe3Q8Rn+EoHtLIvs5tT2A/Wk8JrsznkUH2XqXpi8FgWIXacGQ/Sm/u1YilZ+2KGZ3RxHM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775156022; c=relaxed/simple; bh=IYAPEgDe1ZC9FL2VLGQGQRai548GZydVegIAQogLakg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=uReBPpwGftcGCzxnvQ6nflyCNuv1zrY+BuAZmCefrRXf2vPkPLphH34CMT9vwGyUY0gYJ3+B47vghVe5AtqQ14xclOWf85nJej+co+me71Rp/F0HymrTlTQLbmy7gBxtSZcxH6EI+JfRbvqs0ADUUq99QdI4U61MfT6THEAA+eM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YyGJbVsL; 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="YyGJbVsL" Received: by smtp.kernel.org (Postfix) with ESMTPS id B7302C2BCB3; Thu, 2 Apr 2026 18:53:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775156021; bh=IYAPEgDe1ZC9FL2VLGQGQRai548GZydVegIAQogLakg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=YyGJbVsLOaqsX7/m/sGgyQr/+58MOXeZj/9YxYzF7+zfKLiv6pCWbSqT2V48oBCNh jHozI9+s9ZjvnMbuX89YD7cIEJlf4p41nw52ppWQyEnAa+xssAiDjYCQ2nWE3C6w0J 7xcDsqdRVbMV8EibxJ0Sb9GPxv2NuBiTEZf/Fe5Sn7DVhTQnWAlepGo+I7PpgmzbGQ JrtL19GUk91Ke2JkXCjn57o2FbO7qNBUCFDu+YfRIY149vacCjlRb1rm9S+Fnpcyxm J93BMkcdriWIoITyFhmoRUjBgZ8X422SkmtO++nJ/LNSDTg2LZm5M2NRk7iHsDK/iK OVviwYmLXhBsQ== 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 A40F3D6AAF8; Thu, 2 Apr 2026 18:53:41 +0000 (UTC) From: Kairui Song via B4 Relay Date: Fri, 03 Apr 2026 02:53:34 +0800 Subject: [PATCH v3 08/14] mm/mglru: remove redundant swap constrained check upon isolation 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: <20260403-mglru-reclaim-v3-8-a285efd6ff91@tencent.com> References: <20260403-mglru-reclaim-v3-0-a285efd6ff91@tencent.com> In-Reply-To: <20260403-mglru-reclaim-v3-0-a285efd6ff91@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, Qi Zheng , Baolin Wang , Kairui Song X-Mailer: b4 0.15.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1775156018; l=1646; i=kasong@tencent.com; s=kasong-sign-tencent; h=from:subject:message-id; bh=1TfqZLNVczjhCnyip5hVhPMQqwJr5jWsOeWwr3Bdzvk=; b=ilTesXd1t2BD/bIF52H2EsuropqcuewGrWOmfkHjdaL8AkqD8RL1vxH2/gVtcW3I8zauOsvna tPUt+JQZf7PAtOK5rLkTU8LnR4Kn4yJVmFGtH21QztflnbfWDQspOoQ 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 Remove the swap-constrained early reject check upon isolation. This check is a micro optimization when swap IO is not allowed, so folios are rejected early. But it is redundant and overly broad since shrink_folio_list() already handles all these cases with proper granularity. Notably, this check wrongly rejected lazyfree folios, and it doesn't cover all rejection cases. shrink_folio_list() uses may_enter_fs(), which distinguishes non-SWP_FS_OPS devices from filesystem-backed swap and does all the checks after folio is locked, so flags like swap cache are stable. This check also covers dirty file folios, which are not a problem now since sort_folio() already bumps dirty file folios to the next generation, but causes trouble for unifying dirty folio writeback handling. And there should be no performance impact from removing it. We may have lost a micro optimization, but unblocked lazyfree reclaim for NOIO contexts, which is not a common case in the first place. Signed-off-by: Kairui Song Reviewed-by: Axel Rasmussen --- mm/vmscan.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index b3371877762a..9f4512a4d35f 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -4650,12 +4650,6 @@ static bool isolate_folio(struct lruvec *lruvec, str= uct folio *folio, struct sca { bool success; =20 - /* swap constrained */ - if (!(sc->gfp_mask & __GFP_IO) && - (folio_test_dirty(folio) || - (folio_test_anon(folio) && !folio_test_swapcache(folio)))) - return false; - /* raced with release_pages() */ if (!folio_try_get(folio)) return false; --=20 2.53.0 From nobody Mon Apr 6 13:45:42 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 E7A0A3D8128 for ; Thu, 2 Apr 2026 18:53:41 +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=1775156022; cv=none; b=A3QVITPovuG49DDGrdUqIflVMq9cxsjOzvQTm6gvyt/GIC/0sD8YNIJnazaTOzZPi1QQN6snNQpmm6SuY2o+JYhGaD3G7EdSDqskCfzXw8cwpnfIkH7jmZ+ZO7uvJntgL1lLkRo2Un208EYn5WYHqSXtv6/uOuxtiW8Ex2rloss= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775156022; c=relaxed/simple; bh=2VrNcvAFxwhtYfLD7SRMhvh+xHXxnXAiLxIFBOgX9kM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Do55qztDfSLau6VDgsD7hAKTKHLM1IVVnzzBB9/PwgNV0oAS5zFwAKDrGgp+nsddFhDQTRKq63qCIZ47zLjUo5ZfVJaxCaJXC31VqhrrCT+wjXJDdrlTN4h0wM2ryhhGdAjie/VxAEObhY1Im6+S4CKdnrBdlY/YzGVU5N3TtaQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZBSrQmqC; 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="ZBSrQmqC" Received: by smtp.kernel.org (Postfix) with ESMTPS id C2063C2BC9E; Thu, 2 Apr 2026 18:53:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775156021; bh=2VrNcvAFxwhtYfLD7SRMhvh+xHXxnXAiLxIFBOgX9kM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=ZBSrQmqCj9MVilaJpGU5xhFHpz2NUX05pb/bCGx9CPAmui3vbKnwQWccuun9W4/Ck t9uYKsabmUBHpmsy1CXKZiOXeotR/V88JdhcrrM3i3UGEcJ7RSdd8mmZzpWRjUTCPS lbjHbuH1+3dm25YC/6ogvq+WLPcEv/OGaBrMQqhzHxa3oJykvE9jryelyER70XN5N2 6HWm7kenBoVY3TW36hZWxtRSC4uXr7sioS6ZsMDtlDtXf+HTvL/Ih6tyWcC05Sq24D FafDFPZ0CDAG2bK9KRfmF8evUk/15/KJksYhbZ4CMB7wxb2NAt+UbZ3Q3+AlRLiMtS LYoWnSCxci68A== 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 B6B15D6AAFA; Thu, 2 Apr 2026 18:53:41 +0000 (UTC) From: Kairui Song via B4 Relay Date: Fri, 03 Apr 2026 02:53:35 +0800 Subject: [PATCH v3 09/14] mm/mglru: use the common routine for dirty/writeback reactivation 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: <20260403-mglru-reclaim-v3-9-a285efd6ff91@tencent.com> References: <20260403-mglru-reclaim-v3-0-a285efd6ff91@tencent.com> In-Reply-To: <20260403-mglru-reclaim-v3-0-a285efd6ff91@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, Qi Zheng , Baolin Wang , Kairui Song X-Mailer: b4 0.15.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1775156018; l=2740; i=kasong@tencent.com; s=kasong-sign-tencent; h=from:subject:message-id; bh=1fGU9ybQ5gFaLofblHVGMFlVdGupfTZeucnLqWkcozw=; b=qbDO5xQDJ/A3sbmqRNwdWrxQdbrMGyslVtbnU0pYRi2mPjxtxWVTHjvGTF6EiGkv24u4OlDCw uu28LZ4FGAoBj58CCG7sr1Q6XlUF6m9vA6Hfib0XVBDjXh20yZD0uh6 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 Currently MGLRU will move the dirty writeback folios to the second oldest gen instead of reactivate them like the classical LRU. This might help to reduce the LRU contention as it skipped the isolation. But as a result we will see these folios at the LRU tail more frequently leading to inefficient reclaim. Besides, the dirty / writeback check after isolation in shrink_folio_list is more accurate and covers more cases. So instead, just drop the special handling for dirty writeback, use the common routine and re-activate it like the classical LRU. This should in theory improve the scan efficiency. These folios will be rotated back to LRU tail once writeback is done so there is no risk of hotness inversion. And now each reclaim loop will have a higher success rate. This also prepares for unifying the writeback and throttling mechanism with classical LRU, we keep these folios far from tail so detecting the tail batch will have a similar pattern with classical LRU. The micro optimization that avoids LRU contention by skipping the isolation is gone, which should be fine. Compared to IO and writeback cost, the isolation overhead is trivial. Reviewed-by: Axel Rasmussen Signed-off-by: Kairui Song --- mm/vmscan.c | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 9f4512a4d35f..2a36cf937061 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -4578,7 +4578,6 @@ static bool sort_folio(struct lruvec *lruvec, struct = folio *folio, struct scan_c int tier_idx) { bool success; - bool dirty, writeback; int gen =3D folio_lru_gen(folio); int type =3D folio_is_file_lru(folio); int zone =3D folio_zonenum(folio); @@ -4628,21 +4627,6 @@ static bool sort_folio(struct lruvec *lruvec, struct= folio *folio, struct scan_c return true; } =20 - dirty =3D folio_test_dirty(folio); - writeback =3D folio_test_writeback(folio); - if (type =3D=3D LRU_GEN_FILE && dirty) { - sc->nr.file_taken +=3D delta; - if (!writeback) - sc->nr.unqueued_dirty +=3D delta; - } - - /* waiting for writeback */ - if (writeback || (type =3D=3D LRU_GEN_FILE && dirty)) { - gen =3D folio_inc_gen(lruvec, folio, true); - list_move(&folio->lru, &lrugen->folios[gen][type][zone]); - return true; - } - return false; } =20 @@ -4664,9 +4648,6 @@ static bool isolate_folio(struct lruvec *lruvec, stru= ct folio *folio, struct sca if (!folio_test_referenced(folio)) set_mask_bits(&folio->flags.f, LRU_REFS_MASK, 0); =20 - /* for shrink_folio_list() */ - folio_clear_reclaim(folio); - success =3D lru_gen_del_folio(lruvec, folio, true); VM_WARN_ON_ONCE_FOLIO(!success, folio); =20 --=20 2.53.0 From nobody Mon Apr 6 13:45:42 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 023A73164AA for ; Thu, 2 Apr 2026 18:53:42 +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=1775156022; cv=none; b=KSyVr/HQY3hxcI2M45R36f1AbQRpvEpTkpVHKaBKYGNf/A3X7/TuEnNFk8RTNSCpjjJHQD9NuOz9200uY9a+HaNWKMP6MvFlm6BF7CIcvA8wBxO4jjl+9pzjDQD/tJcQXcL6IjeyKUKA6Zd+bN/w+y+Qe4xl+X1f4ZLo1UP2DxE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775156022; c=relaxed/simple; bh=63nEWfwkNNkk9J++qrkxrJVSy188Dx52Qvrtm+1BaGs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mktSJ8S8CjN1WcRGyC8i0GeqCfEV8YUPXiloTXtAAkYLHJ9SxBAC8DvwMluvwLuszHHkzbZk4sHFrdy9nLF4SwxMAck13Fnumlaolsamqt9iLkmpUdnfOgO0ulN18ihnLrtaf0rbMOsLdGrI81rNW7Sw3HudUAlQndOtKuj823w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ASiGTN3V; 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="ASiGTN3V" Received: by smtp.kernel.org (Postfix) with ESMTPS id D6244C2BCB5; Thu, 2 Apr 2026 18:53:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775156021; bh=63nEWfwkNNkk9J++qrkxrJVSy188Dx52Qvrtm+1BaGs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=ASiGTN3V5lLKskHiafX2Q0dnO62ymSFp7sdXqmcdYIkkHkHv+uw7tGvC5QDnUljO5 ktke/cSdCLHwUtMklH0OXxA12xD907BwJtEu1H2dp/qilvY7/Ghp9JWaHyQ8p5NGse 5JemgLRflD+d9u8qfHZ+iWuFheOKmsBeg5uziv/eQoo6oJWXNh2S2RxrlshBLFiQgy 2zAaAVTQmkD+emqmIFoxQdo+VM/yF2BU2Rwy38eeFj91QXa1WMD4jyUDnUeLeJ4Nnx nlEqnicDmX35zHsuUm3m4QQHyaY9iFhCsH4cscY/JiP+tjwg8mZ2FFrhsRuCMhvEQL L1Nj5Pz4/+pPw== 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 C8F16D6AAF9; Thu, 2 Apr 2026 18:53:41 +0000 (UTC) From: Kairui Song via B4 Relay Date: Fri, 03 Apr 2026 02:53:36 +0800 Subject: [PATCH v3 10/14] mm/mglru: simplify and improve dirty writeback handling 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: <20260403-mglru-reclaim-v3-10-a285efd6ff91@tencent.com> References: <20260403-mglru-reclaim-v3-0-a285efd6ff91@tencent.com> In-Reply-To: <20260403-mglru-reclaim-v3-0-a285efd6ff91@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, Qi Zheng , Baolin Wang , Kairui Song X-Mailer: b4 0.15.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1775156018; l=4353; i=kasong@tencent.com; s=kasong-sign-tencent; h=from:subject:message-id; bh=hVu3ISonYulOgbgDjpADHQN2QCCwFiXdmGgk/BQPxSU=; b=kkEuh+8AqhlfqE5nr5RrlNP81wjM+EdWclsP/JUJJxh32ldb9EaSVYEdYH+0la/BG+SZlGhMe fp6Kn8c2mXcAzxSGGt/ekc4X+n3yxuXsgAFprbRwFbWETApZovUH9ht 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 Right now the flusher wakeup mechanism for MGLRU is less responsive and unlikely to trigger compared to classical LRU. The classical LRU wakes the flusher if one batch of folios passed to shrink_folio_list is unevictable due to under writeback. MGLRU instead check and handle this after the whole reclaim loop is done. We previously even saw OOM problems due to passive flusher, which were fixed but still not perfect [1]. We have just unified the dirty folio counting and activation routine, now just move the dirty flush into the loop right after shrink_folio_list. This improves the performance a lot for workloads involving heavy writeback and prepares for throttling too. Test with YCSB workloadb showed a major performance improvement: Before this series: Throughput(ops/sec): 62485.02962831822 AverageLatency(us): 500.9746963330107 pgpgin 159347462 workingset_refault_file 34522071 After this commit: Throughput(ops/sec): 80857.08510208207 AverageLatency(us): 386.653262968934 pgpgin 112233121 workingset_refault_file 19516246 The performance is a lot better with significantly lower refault. We also observed similar or higher performance gain for other real-world workloads. We were concerned that the dirty flush could cause more wear for SSD: that should not be the problem here, since the wakeup condition is when the dirty folios have been pushed to the tail of LRU, which indicates that memory pressure is so high that writeback is blocking the workload already. Reviewed-by: Axel Rasmussen Link: https://lore.kernel.org/linux-mm/20241026115714.1437435-1-jingxiangze= ng.cas@gmail.com/ [1] Signed-off-by: Kairui Song --- mm/vmscan.c | 41 ++++++++++++++++------------------------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 2a36cf937061..bd2bf45826de 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -4724,8 +4724,6 @@ static int scan_folios(unsigned long nr_to_scan, stru= ct lruvec *lruvec, trace_mm_vmscan_lru_isolate(sc->reclaim_idx, sc->order, nr_to_scan, scanned, skipped, isolated, type ? LRU_INACTIVE_FILE : LRU_INACTIVE_ANON); - if (type =3D=3D LRU_GEN_FILE) - sc->nr.file_taken +=3D isolated; =20 *isolatedp =3D isolated; return scanned; @@ -4833,12 +4831,27 @@ static int evict_folios(unsigned long nr_to_scan, s= truct lruvec *lruvec, return scanned; retry: reclaimed =3D shrink_folio_list(&list, pgdat, sc, &stat, false, memcg); - sc->nr.unqueued_dirty +=3D stat.nr_unqueued_dirty; sc->nr_reclaimed +=3D reclaimed; trace_mm_vmscan_lru_shrink_inactive(pgdat->node_id, type_scanned, reclaimed, &stat, sc->priority, type ? LRU_INACTIVE_FILE : LRU_INACTIVE_ANON); =20 + /* + * If too many file cache in the coldest generation can't be evicted + * due to being dirty, wake up the flusher. + */ + if (stat.nr_unqueued_dirty =3D=3D isolated) { + wakeup_flusher_threads(WB_REASON_VMSCAN); + + /* + * For cgroupv1 dirty throttling is achieved by waking up + * the kernel flusher here and later waiting on folios + * which are in writeback to finish (see shrink_folio_list()). + */ + if (!writeback_throttling_sane(sc)) + reclaim_throttle(pgdat, VMSCAN_THROTTLE_WRITEBACK); + } + list_for_each_entry_safe_reverse(folio, next, &list, lru) { DEFINE_MIN_SEQ(lruvec); =20 @@ -4999,28 +5012,6 @@ static bool try_to_shrink_lruvec(struct lruvec *lruv= ec, struct scan_control *sc) cond_resched(); } =20 - /* - * If too many file cache in the coldest generation can't be evicted - * due to being dirty, wake up the flusher. - */ - if (sc->nr.unqueued_dirty && sc->nr.unqueued_dirty =3D=3D sc->nr.file_tak= en) { - struct pglist_data *pgdat =3D lruvec_pgdat(lruvec); - - wakeup_flusher_threads(WB_REASON_VMSCAN); - - /* - * For cgroupv1 dirty throttling is achieved by waking up - * the kernel flusher here and later waiting on folios - * which are in writeback to finish (see shrink_folio_list()). - * - * Flusher may not be able to issue writeback quickly - * enough for cgroupv1 writeback throttling to work - * on a large system. - */ - if (!writeback_throttling_sane(sc)) - reclaim_throttle(pgdat, VMSCAN_THROTTLE_WRITEBACK); - } - return need_rotate; } =20 --=20 2.53.0 From nobody Mon Apr 6 13:45:42 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 174403F0772 for ; Thu, 2 Apr 2026 18:53:42 +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=1775156022; cv=none; b=Gg4rfCJ06qoUi5yoLS/1gd7KKWooivr56clsIpTUM5s/zVor7xXW+/ilg1NS6Jgr9s8w9XigMIJ6ytaPuagsN9qj7Rqw3CPd1rMCSsz72HhfDHNh2S8Rr1qLUpo+X2MCBnkQcpbyCI4Q+vK6l53ZGXyxHg+pO/LQf1f81vuEeLY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775156022; c=relaxed/simple; bh=5XP6DMQU/MpEX364Bg4dBKO713N/bgpO63sM9BowO0U=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kbhCT4Trc4bX4UnPBid9nU/g3WgpSt6+PKqu5yFB/Up2IFSYTpemzCkMP8E4rxhtpcG1IJ5Up7iIKItqtLj3RCu1S1axOjYnuyjE5oQXcdQO0poXxS+lWZ76DlBFYOhmvJFZ6pA6qdsFUR0ZpLNztyssAJ949RIbvhoflV3vtnQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hz+HC1bQ; 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="hz+HC1bQ" Received: by smtp.kernel.org (Postfix) with ESMTPS id ECBC7C2BCC4; Thu, 2 Apr 2026 18:53:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775156022; bh=5XP6DMQU/MpEX364Bg4dBKO713N/bgpO63sM9BowO0U=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=hz+HC1bQbjq3hI5JI2d5IWDVzdP3I8AicHwjsiW/oSn+x4t51HCiWEHFHZ/CxdooZ oABD6vYcIy0y4opXyJb1kURDmdAZz+9OeNuQcaqaLt9mZS66kel9BjHV24Dvk47KwA NjeKqDxrG9gJxboAKh3YJWJP99HqFPHA2GKjUFTWiHJ6M9EI104WAzsMWG8HkvZsSj m3vmWh5A13h25HVV8ZXISjDbTh9S5qoY7OWtTWpSNP6rerUHIfuRBE/tY6up3eW962 gmznp+fjDaU/UYrJRwAeCyNtMgqZHLyKYzvzfzHTj1kJJdb3/TgBXtNQ3LtBIb7G7l /eB69nw7pcZLA== 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 DB6B3D6AAFC; Thu, 2 Apr 2026 18:53:41 +0000 (UTC) From: Kairui Song via B4 Relay Date: Fri, 03 Apr 2026 02:53:37 +0800 Subject: [PATCH v3 11/14] mm/mglru: remove no longer used reclaim argument for folio protection 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: <20260403-mglru-reclaim-v3-11-a285efd6ff91@tencent.com> References: <20260403-mglru-reclaim-v3-0-a285efd6ff91@tencent.com> In-Reply-To: <20260403-mglru-reclaim-v3-0-a285efd6ff91@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, Qi Zheng , Baolin Wang , Kairui Song X-Mailer: b4 0.15.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1775156018; l=2572; i=kasong@tencent.com; s=kasong-sign-tencent; h=from:subject:message-id; bh=KgV7etFzeAnK6AqSihOWX2NgT4FyFpQCpbEP9PRCiOs=; b=DukibqSLKidGFP97yV+KQCxS/VA0dvzM+NjLCJRdKi/iBntY+1hZKF6J+THVGASBUqV8cFwac vDWTFxah41uDkvnA+B87GXmGhkfRcaBulSvWxk7btOTPJmzyLNM3iHj 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 Now dirty reclaim folios are handled after isolation, not before, since dirty reactivation must take the folio off LRU first, and that helps to unify the dirty handling logic. So this argument is no longer needed. Just remove it. Signed-off-by: Kairui Song Reviewed-by: Axel Rasmussen --- mm/vmscan.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index bd2bf45826de..9bd0a3b94855 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -3220,7 +3220,7 @@ static int folio_update_gen(struct folio *folio, int = gen) } =20 /* protect pages accessed multiple times through file descriptors */ -static int folio_inc_gen(struct lruvec *lruvec, struct folio *folio, bool = reclaiming) +static int folio_inc_gen(struct lruvec *lruvec, struct folio *folio) { int type =3D folio_is_file_lru(folio); struct lru_gen_folio *lrugen =3D &lruvec->lrugen; @@ -3239,9 +3239,6 @@ static int folio_inc_gen(struct lruvec *lruvec, struc= t folio *folio, bool reclai =20 new_flags =3D old_flags & ~(LRU_GEN_MASK | LRU_REFS_FLAGS); new_flags |=3D (new_gen + 1UL) << LRU_GEN_PGOFF; - /* for folio_end_writeback() */ - if (reclaiming) - new_flags |=3D BIT(PG_reclaim); } while (!try_cmpxchg(&folio->flags.f, &old_flags, new_flags)); =20 lru_gen_update_size(lruvec, folio, old_gen, new_gen); @@ -3855,7 +3852,7 @@ static bool inc_min_seq(struct lruvec *lruvec, int ty= pe, int swappiness) VM_WARN_ON_ONCE_FOLIO(folio_is_file_lru(folio) !=3D type, folio); VM_WARN_ON_ONCE_FOLIO(folio_zonenum(folio) !=3D zone, folio); =20 - new_gen =3D folio_inc_gen(lruvec, folio, false); + new_gen =3D folio_inc_gen(lruvec, folio); list_move_tail(&folio->lru, &lrugen->folios[new_gen][type][zone]); =20 /* don't count the workingset being lazily promoted */ @@ -4607,7 +4604,7 @@ static bool sort_folio(struct lruvec *lruvec, struct = folio *folio, struct scan_c =20 /* protected */ if (tier > tier_idx || refs + workingset =3D=3D BIT(LRU_REFS_WIDTH) + 1) { - gen =3D folio_inc_gen(lruvec, folio, false); + gen =3D folio_inc_gen(lruvec, folio); list_move(&folio->lru, &lrugen->folios[gen][type][zone]); =20 /* don't count the workingset being lazily promoted */ @@ -4622,7 +4619,7 @@ static bool sort_folio(struct lruvec *lruvec, struct = folio *folio, struct scan_c =20 /* ineligible */ if (zone > sc->reclaim_idx) { - gen =3D folio_inc_gen(lruvec, folio, false); + gen =3D folio_inc_gen(lruvec, folio); list_move_tail(&folio->lru, &lrugen->folios[gen][type][zone]); return true; } --=20 2.53.0 From nobody Mon Apr 6 13:45:42 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 25F753F23AA for ; Thu, 2 Apr 2026 18:53:42 +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=1775156022; cv=none; b=k6C9bba4M2/BIAsYqtbL9qH+B177xu4KbcmFxB/cJ76yQxvcFC7YxTswGGqwQOaUaP27J65bgUmI45Szl5rudDvEr7f+dIstopL/K1mrHIoMeWNZooGSXwEGYwW+mM4HSkNWhdoCrFj+2nP5kvHCPObPYhf3AbZ6XRSDAavx/ms= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775156022; c=relaxed/simple; bh=kEHU1oiTi4HOuZjIN0Q3QHaLoeVjFYQ12m4ZGtyl71I=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MALLq0SOve7f3KUoU5LRK+cqxYfYEttj3UFBtHnnKgsKpv3eV+NXQeWuTTXeghinCaan2+aTA0r1lr1sROm2rJqtnHEW+4xHg7H8Ln0vHOlp4sGDJZwoMUGJI+bsRdVP7r6g5JNMOj/tfhEQetpYRHRVpvy05ChbPS27rS0ruR8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Jandxikq; 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="Jandxikq" Received: by smtp.kernel.org (Postfix) with ESMTPS id 05CEDC2BCB1; Thu, 2 Apr 2026 18:53:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775156022; bh=kEHU1oiTi4HOuZjIN0Q3QHaLoeVjFYQ12m4ZGtyl71I=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=Jandxikq2N/GzPM+KNbXoqxQPADghjlIqCb855Yxo/T9eqVPi8eTJb76D0Nm5MpdT b35I0ghny1YqOL7F+EbOVZm9OGE90EK0H52nryBKb5racpcKR0PD9kDgOquK0cFHBW 47Ju22ag43rWGHSle58AOp+HpJL98m4v5CUjvp+s2YHnCgmltGKuFD3yYEpCF7MvHr 4StoM6E/ADDB0myKhDCK96nzbjuouz/3omiHvrL7q6iRjdlbuYWPUj1ISTU6AWCBKG +yLUXmu4S2qb5zYjbU9p8aRAe89ENUq9e7ajJ33EpLV1BHIzjWV+9hqyerKTS3tXBW /LUjFfe/REQFw== 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 EE6B2D6AAFD; Thu, 2 Apr 2026 18:53:41 +0000 (UTC) From: Kairui Song via B4 Relay Date: Fri, 03 Apr 2026 02:53:38 +0800 Subject: [PATCH v3 12/14] mm/vmscan: remove sc->file_taken 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: <20260403-mglru-reclaim-v3-12-a285efd6ff91@tencent.com> References: <20260403-mglru-reclaim-v3-0-a285efd6ff91@tencent.com> In-Reply-To: <20260403-mglru-reclaim-v3-0-a285efd6ff91@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, Qi Zheng , Baolin Wang , Kairui Song X-Mailer: b4 0.15.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1775156018; l=963; i=kasong@tencent.com; s=kasong-sign-tencent; h=from:subject:message-id; bh=s/6eR1HUxQEtsk5vzGAFWPh5At357cjt43p3hyv6mmA=; b=69e68elfhQU+7zXdXP8fyodqmAoT8tWrsi2kngdIzTsXBRzTSINE7eOycRLPyVfpDkK6T+Xow fxVTwyWSWdoA6Z+4Ep21Xzj0dhxYn0FdFagt3ywo9vhonHYxo8ayx4B 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 No one is using it now, just remove it. Reviewed-by: Axel Rasmussen Reviewed-by: Baolin Wang Signed-off-by: Kairui Song --- mm/vmscan.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 9bd0a3b94855..e4f27fd22422 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -173,7 +173,6 @@ struct scan_control { unsigned int congested; unsigned int writeback; unsigned int immediate; - unsigned int file_taken; unsigned int taken; } nr; =20 @@ -2040,8 +2039,6 @@ static unsigned long shrink_inactive_list(unsigned lo= ng nr_to_scan, sc->nr.writeback +=3D stat.nr_writeback; sc->nr.immediate +=3D stat.nr_immediate; sc->nr.taken +=3D nr_taken; - if (file) - sc->nr.file_taken +=3D nr_taken; =20 trace_mm_vmscan_lru_shrink_inactive(pgdat->node_id, nr_scanned, nr_reclaimed, &stat, sc->priority, file); --=20 2.53.0 From nobody Mon Apr 6 13:45:42 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 383303F54B7 for ; Thu, 2 Apr 2026 18:53:42 +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=1775156022; cv=none; b=KD5NP2oLqiYKkrOqM0QKDhnzoKLG3T1MlBpGpeoa+gUAcQR5PiKLLD5Sj5+31YzUkIzprFm5+a6h8jxjvnmXsXI4u0B6B7j1NRbME9UVFPNwGKlTY146hYNqsYkwsDW4e3SO88yW3JlqHocaSE8gg+Ai1cxwp36m/QX7UYwV5EI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775156022; c=relaxed/simple; bh=C+b0qe8+WwLoSOukrhjp8oUBTkwqOJFRbwKbGr2dnNg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=E74kAmdqv6vqRsQ5MI63AS4xDZPZqeTNZNMjr9zoEvYT20rLFTXXHPmXY+4Dz8uKmvi/mmEFEgyxzZhOTx158hcT6hC+NDlzebRQhPvP9sVHDrYFAQzi9wDerT4Ri94NNbBayOIfHSoCWvc1rU6d7nJDkZMFhDiAWr6tQLIoCZQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fMIVSiCQ; 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="fMIVSiCQ" Received: by smtp.kernel.org (Postfix) with ESMTPS id 1665FC2BCF6; Thu, 2 Apr 2026 18:53:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775156022; bh=C+b0qe8+WwLoSOukrhjp8oUBTkwqOJFRbwKbGr2dnNg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=fMIVSiCQAUklaISRQoCqFzL55chab5pSI3LhKi4fMM1oFPqf/SLCFSmX3BkVmxql6 YJ6MzgwwoTfT9+nPdi/DVx9SlJkOj2yImaxzdcghLNM8e3zFY/zXsnSV0tPNmVafs2 6uKoKG1bXSpjE4jvccYjV67/U0yDnn2gKCpKvytpQD99dyGO3N/M1fXXt5EeqiOres 9nCzBsVmTu9uZy6KPRzfuYjMX8IrFus5eEugVolMAlGa5ewIsXg1P2sin618FGzwqM dQ/4zHWOuMe7cB8KOvme0c9dhTjGqqKJv+IzTHrdtfLhtIg8nmNaSW3EIJYd9wUlZ0 0Wa0cC/ME0nBg== 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 0C85AD6AAFA; Thu, 2 Apr 2026 18:53:42 +0000 (UTC) From: Kairui Song via B4 Relay Date: Fri, 03 Apr 2026 02:53:39 +0800 Subject: [PATCH v3 13/14] mm/vmscan: remove sc->unqueued_dirty 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: <20260403-mglru-reclaim-v3-13-a285efd6ff91@tencent.com> References: <20260403-mglru-reclaim-v3-0-a285efd6ff91@tencent.com> In-Reply-To: <20260403-mglru-reclaim-v3-0-a285efd6ff91@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, Qi Zheng , Baolin Wang , Kairui Song X-Mailer: b4 0.15.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1775156018; l=936; i=kasong@tencent.com; s=kasong-sign-tencent; h=from:subject:message-id; bh=e26nyKYLbSKDUtJliGN08CbrGD9gSe1V6+IS9z4KclM=; b=6RfwFUsNaOQsJCmIZR9jBEebpkVMA+ugGtcyI9hhtGMRsHXd3FE7z0CUa9CobREdLXlVjOORk jAEcEvC2s1ZAlqkMJ+7hhu27i8/1BUKAQstv4QRkUW5Bs6OLlS9LiOu 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 No one is using it now, just remove it. Suggested-by: Axel Rasmussen Reviewed-by: Baolin Wang Signed-off-by: Kairui Song Reviewed-by: Axel Rasmussen --- mm/vmscan.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index e4f27fd22422..9120d914445e 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -169,7 +169,6 @@ struct scan_control { =20 struct { unsigned int dirty; - unsigned int unqueued_dirty; unsigned int congested; unsigned int writeback; unsigned int immediate; @@ -2035,7 +2034,6 @@ static unsigned long shrink_inactive_list(unsigned lo= ng nr_to_scan, =20 sc->nr.dirty +=3D stat.nr_dirty; sc->nr.congested +=3D stat.nr_congested; - sc->nr.unqueued_dirty +=3D stat.nr_unqueued_dirty; sc->nr.writeback +=3D stat.nr_writeback; sc->nr.immediate +=3D stat.nr_immediate; sc->nr.taken +=3D nr_taken; --=20 2.53.0 From nobody Mon Apr 6 13:45:42 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 470423F54C7 for ; Thu, 2 Apr 2026 18:53:42 +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=1775156022; cv=none; b=Rq8BLGdslmclS3SobtzQVqqHZ5gXr34EGj0dSBgpPaNgBqAeQrnNUJmFI1AO8OeOLjTynNqR5eeRhqozwTqQSHlvmrpZ2rJBU61zr2GPkyIxPLYiCaoimZQVqzp81spflIZ0926X3syUvPpR7LCj8MGHY2Iyk4VhYJG/cUF2PTE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775156022; c=relaxed/simple; bh=JoTw5aUvhkz8VaY5u7uxlkTbs6iUI9G/SuKSxLly8S8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PUZ5wvteeadpb7l8pS0kfqNo9JZjnOaQi4j9GqfZPn9X7YGam5IINFqYCgp33fls8ym9jqtO8u3myarA+XAq+hDgsW9VZfoLTg1Yw6NPTIYaKWQi3E+PmMKil2+Weue3jyskNTU6dCWASIjUG+C8yqaNnRza2n/Zv5JgW06NNSo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gVr75AyE; 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="gVr75AyE" Received: by smtp.kernel.org (Postfix) with ESMTPS id 262D0C4AF0D; Thu, 2 Apr 2026 18:53:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775156022; bh=JoTw5aUvhkz8VaY5u7uxlkTbs6iUI9G/SuKSxLly8S8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=gVr75AyEWfcWQQbAhTlTTpzLKx2kdHlCTcHTM2xLbqqgR3ZaRP5htaPh68nXTf2w8 BV4r2W6gNxrQeNlMaur5pbAjfppLSLwRxiV1z+V8tjfjUIRuJnsnOO37Y+Wfovxi6/ 2gvlf52QkMhDIKJKLLj+ggJFRn3G+A8a1M2RJOn7EXIAbo2x2SynEBSu/8C2OECFQE +3Uoq4xUia1jkynUjqaglnqCuE6Uw+DpP4AMowftC216LNeaRUQ7uLp3bMkC+D+pE8 kctf95m4/HSFTNkUWMknFxfr5YrmbwJtkENP/NzwtRujfMGrbt8T8qHNp9/5V7AmL5 IIYTeicS1pmrA== 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 1D70BD6AAF8; Thu, 2 Apr 2026 18:53:42 +0000 (UTC) From: Kairui Song via B4 Relay Date: Fri, 03 Apr 2026 02:53:40 +0800 Subject: [PATCH v3 14/14] mm/vmscan: unify writeback reclaim statistic and throttling 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: <20260403-mglru-reclaim-v3-14-a285efd6ff91@tencent.com> References: <20260403-mglru-reclaim-v3-0-a285efd6ff91@tencent.com> In-Reply-To: <20260403-mglru-reclaim-v3-0-a285efd6ff91@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, Qi Zheng , Baolin Wang , Kairui Song X-Mailer: b4 0.15.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1775156018; l=6627; i=kasong@tencent.com; s=kasong-sign-tencent; h=from:subject:message-id; bh=HRyVJumaRGlmjmg7giWQoM7fAZ1aA3IIuyfVBBx3wZY=; b=xD+AQD0knA28MQKrusASwXm7UtsaKfBTKC9JBS15D+CeEKYFqH1uJ/6ScHUKnKVujGRyMe3N0 WvZa1Tu3h3iD8Aw8A6T62YMuetjGpPZWi00ERRjqfPGa5cpR9bK+k7t 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 Currently MGLRU and non-MGLRU handle the reclaim statistic and writeback handling very differently, especially throttling. Basically MGLRU just ignored the throttling part. Let's just unify this part, use a helper to deduplicate the code so both setups will share the same behavior. Test using following reproducer using bash: echo "Setup a slow device using dm delay" dd if=3D/dev/zero of=3D/var/tmp/backing bs=3D1M count=3D2048 LOOP=3D$(losetup --show -f /var/tmp/backing) mkfs.ext4 -q $LOOP echo "0 $(blockdev --getsz $LOOP) delay $LOOP 0 0 $LOOP 0 1000" | \ dmsetup create slow_dev mkdir -p /mnt/slow && mount /dev/mapper/slow_dev /mnt/slow echo "Start writeback pressure" sync && echo 3 > /proc/sys/vm/drop_caches mkdir /sys/fs/cgroup/test_wb echo 128M > /sys/fs/cgroup/test_wb/memory.max (echo $BASHPID > /sys/fs/cgroup/test_wb/cgroup.procs && \ dd if=3D/dev/zero of=3D/mnt/slow/testfile bs=3D1M count=3D192) echo "Clean up" echo "0 $(blockdev --getsz $LOOP) error" | dmsetup load slow_dev dmsetup resume slow_dev umount -l /mnt/slow && sync dmsetup remove slow_dev Before this commit, `dd` will get OOM killed immediately if MGLRU is enabled. Classic LRU is fine. After this commit, throttling is now effective and no more spin on LRU or premature OOM. Stress test on other workloads also looking good. Global throttling is not here yet, we will fix that separately later. Suggested-by: Chen Ridong Tested-by: Leno Hou Signed-off-by: Kairui Song Reviewed-by: Axel Rasmussen --- mm/vmscan.c | 90 ++++++++++++++++++++++++++++-----------------------------= ---- 1 file changed, 41 insertions(+), 49 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 9120d914445e..a7b3e5b6676b 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1942,6 +1942,44 @@ static int current_may_throttle(void) return !(current->flags & PF_LOCAL_THROTTLE); } =20 +static void handle_reclaim_writeback(unsigned long nr_taken, + struct pglist_data *pgdat, + struct scan_control *sc, + struct reclaim_stat *stat) +{ + /* + * If dirty folios are scanned that are not queued for IO, it + * implies that flushers are not doing their job. This can + * happen when memory pressure pushes dirty folios to the end of + * the LRU before the dirty limits are breached and the dirty + * data has expired. It can also happen when the proportion of + * dirty folios grows not through writes but through memory + * pressure reclaiming all the clean cache. And in some cases, + * the flushers simply cannot keep up with the allocation + * rate. Nudge the flusher threads in case they are asleep. + */ + if (stat->nr_unqueued_dirty =3D=3D nr_taken && nr_taken) { + wakeup_flusher_threads(WB_REASON_VMSCAN); + /* + * For cgroupv1 dirty throttling is achieved by waking up + * the kernel flusher here and later waiting on folios + * which are in writeback to finish (see shrink_folio_list()). + * + * Flusher may not be able to issue writeback quickly + * enough for cgroupv1 writeback throttling to work + * on a large system. + */ + if (!writeback_throttling_sane(sc)) + reclaim_throttle(pgdat, VMSCAN_THROTTLE_WRITEBACK); + } + + sc->nr.dirty +=3D stat->nr_dirty; + sc->nr.congested +=3D stat->nr_congested; + sc->nr.writeback +=3D stat->nr_writeback; + sc->nr.immediate +=3D stat->nr_immediate; + sc->nr.taken +=3D nr_taken; +} + /* * shrink_inactive_list() is a helper for shrink_node(). It returns the n= umber * of reclaimed pages @@ -2005,39 +2043,7 @@ static unsigned long shrink_inactive_list(unsigned l= ong nr_to_scan, lruvec_lock_irq(lruvec); lru_note_cost_unlock_irq(lruvec, file, stat.nr_pageout, nr_scanned - nr_reclaimed); - - /* - * If dirty folios are scanned that are not queued for IO, it - * implies that flushers are not doing their job. This can - * happen when memory pressure pushes dirty folios to the end of - * the LRU before the dirty limits are breached and the dirty - * data has expired. It can also happen when the proportion of - * dirty folios grows not through writes but through memory - * pressure reclaiming all the clean cache. And in some cases, - * the flushers simply cannot keep up with the allocation - * rate. Nudge the flusher threads in case they are asleep. - */ - if (stat.nr_unqueued_dirty =3D=3D nr_taken) { - wakeup_flusher_threads(WB_REASON_VMSCAN); - /* - * For cgroupv1 dirty throttling is achieved by waking up - * the kernel flusher here and later waiting on folios - * which are in writeback to finish (see shrink_folio_list()). - * - * Flusher may not be able to issue writeback quickly - * enough for cgroupv1 writeback throttling to work - * on a large system. - */ - if (!writeback_throttling_sane(sc)) - reclaim_throttle(pgdat, VMSCAN_THROTTLE_WRITEBACK); - } - - sc->nr.dirty +=3D stat.nr_dirty; - sc->nr.congested +=3D stat.nr_congested; - sc->nr.writeback +=3D stat.nr_writeback; - sc->nr.immediate +=3D stat.nr_immediate; - sc->nr.taken +=3D nr_taken; - + handle_reclaim_writeback(nr_taken, pgdat, sc, &stat); trace_mm_vmscan_lru_shrink_inactive(pgdat->node_id, nr_scanned, nr_reclaimed, &stat, sc->priority, file); return nr_reclaimed; @@ -4824,26 +4830,11 @@ static int evict_folios(unsigned long nr_to_scan, s= truct lruvec *lruvec, retry: reclaimed =3D shrink_folio_list(&list, pgdat, sc, &stat, false, memcg); sc->nr_reclaimed +=3D reclaimed; + handle_reclaim_writeback(isolated, pgdat, sc, &stat); trace_mm_vmscan_lru_shrink_inactive(pgdat->node_id, type_scanned, reclaimed, &stat, sc->priority, type ? LRU_INACTIVE_FILE : LRU_INACTIVE_ANON); =20 - /* - * If too many file cache in the coldest generation can't be evicted - * due to being dirty, wake up the flusher. - */ - if (stat.nr_unqueued_dirty =3D=3D isolated) { - wakeup_flusher_threads(WB_REASON_VMSCAN); - - /* - * For cgroupv1 dirty throttling is achieved by waking up - * the kernel flusher here and later waiting on folios - * which are in writeback to finish (see shrink_folio_list()). - */ - if (!writeback_throttling_sane(sc)) - reclaim_throttle(pgdat, VMSCAN_THROTTLE_WRITEBACK); - } - list_for_each_entry_safe_reverse(folio, next, &list, lru) { DEFINE_MIN_SEQ(lruvec); =20 @@ -4886,6 +4877,7 @@ static int evict_folios(unsigned long nr_to_scan, str= uct lruvec *lruvec, =20 if (!list_empty(&list)) { skip_retry =3D true; + isolated =3D 0; goto retry; } =20 --=20 2.53.0