From nobody Wed Apr 8 05:03:20 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 64CF23A75BE for ; Tue, 7 Apr 2026 12:04:51 +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=1775563491; cv=none; b=tXoj9lfL20frzioh6nScg8Asp9IzE5PwR0TqURuMvMjsWzZZh34BEYdPT9XPsEz5/kIUf92RGj8kMw5jxGI5IiGZ8nM4l6QnbD84+YPVz7HljXo6ZnQgNwNqoHLYOlviOBP0MTBqdMOP4th0+FA+G8hfVzQkpjJl/5QjnRdtEBY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775563491; c=relaxed/simple; bh=pu/4aSrd7KSa0bxFp6wbeBj72fjrUtTNvGBmWMpcIZ0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qhdzTwZmokXnS7gEZUvBd5XA/zrr/K+sPIFKx4UTWZMXAAQStxQyfVwrOu48ZQfh6Y9N+nOhS0urwFsXl6enIQ09zi3neixzfB2qqhdGyK8s1MuQQsCDWZO+LYNQqyW9X0Yai0iywwLgx8RL2hPIbs3KnpRnMpdU1IV76CRXofg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lJP8SWuI; 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="lJP8SWuI" Received: by smtp.kernel.org (Postfix) with ESMTPS id 137E2C19421; Tue, 7 Apr 2026 12:04:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775563491; bh=pu/4aSrd7KSa0bxFp6wbeBj72fjrUtTNvGBmWMpcIZ0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=lJP8SWuI2Cxb/iDi1p5tTrrt6aGer2/k95f2VKEx3Guj+WT3u5roMCn9lWmCncpaJ UmNJ1vdoZnp1t0xQoWb/vgmBfi2CPtMegug/i2wQxsSCog+3vyCykX4SizjJa5pZR5 MAvad6IKOnTkDiFx5J4T2lW2j1ymjwV9QuSlzlw9NIeAEzdYcb3754rFUHF9FJQbt7 LDcqSOfi3eKFBXL3r8LL2qGOiLuivjD0I9pkRzdF6rly9uL5p6DL4VUAur6sADgsGm YLC9TcvgCTNZhAOcUmINwUijCOgrDvB+Vpxa6Rb7sn+IMd8Qh6pXv4AjuOn/O6LrzV iqDfSXpw81t/A== 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 020BCFEEF2A; Tue, 7 Apr 2026 12:04:51 +0000 (UTC) From: Kairui Song via B4 Relay Date: Tue, 07 Apr 2026 19:57:30 +0800 Subject: [PATCH v4 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: <20260407-mglru-reclaim-v4-1-98cf3dc69519@tencent.com> References: <20260407-mglru-reclaim-v4-0-98cf3dc69519@tencent.com> In-Reply-To: <20260407-mglru-reclaim-v4-0-98cf3dc69519@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=1775563488; l=3179; i=kasong@tencent.com; s=kasong-sign-tencent; h=from:subject:message-id; bh=lovGNHm1LZYPq5LXk6kp/WVa26J2TdTx/242vg8RH/A=; b=o2kzXPa3l3rIWSBfx1cPEZpYC4ATtY1m/W9nz18i0dGJN0b2YZIoBFQXGdQLISGwrD5Z7mZ9h qBjFhO53C3oB1syItjM0cdtI7OxaJJYEgNdygTWef8m5r1HqcVFNbU9 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 Wed Apr 8 05:03:20 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 64C633A6B7E for ; Tue, 7 Apr 2026 12:04:51 +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=1775563491; cv=none; b=YCLO1UIvWulfcTqLy5fa6jB3e9jAZByRAMuITpQ+znH+ReyHsEEEtd4GhPURLw1E8Se1TT2Bpox3Tc3hYNFoPYSRLH4A2+hSZUlQg6iN7JOIklqJCkkvSwVH+8qzDOz29u2VOkr2LhzNOuB+D3zMZX9fpz3cnAlRyM4nJAXycac= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775563491; c=relaxed/simple; bh=nf8UOchn9pxNiBANW4ySdYqzcmGuZiLDqUsnkRCZFnk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=d7ey1BxXzhPnZf4oaQMqFp8cJJO+prFIZBYoKlmqtLGQHcyVzc/EUqffwWHdxFFWqSoJefbhxrsj/Sv8uzDLdRncZcjOll2cHFRdCQa2O8wvrheXs98TuJMxla3JqDMqWs0dXW0MtKmBsHD9AwJJL/FO1D+KCmP9nfZJ1Juiqsw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RKPeu853; 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="RKPeu853" Received: by smtp.kernel.org (Postfix) with ESMTPS id 251BAC2BCB3; Tue, 7 Apr 2026 12:04:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775563491; bh=nf8UOchn9pxNiBANW4ySdYqzcmGuZiLDqUsnkRCZFnk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=RKPeu853k0VrejA7oYOHJJCF2KZTstUFBLKLaYKoYyb2nwRCpjsTFDFpm4Q/rGfFB 2u8TYjJfPmeBygzkb8fUOdlJBO38kE+8GyXi2tob6O0T3I08FxauthAH1DBNe+FQvC IiZc2liThMLelbJ7yp6Bx2xh4SWV1tio4Ye8+NscS0QnMKOkzpmbEMByNI2dfPLlgG jwN2r6rL5iEwRbrQqOm+H8LU5Qvxf2FAopmnP57UzndD8bB7TpZLYPVt/Gwt0fElXb JfP+AJM/k7cGrP3IPOtbJSY1DqXequvD2mpjP34k5aAAA/texvizxMquIfkatpFjrQ D1Qh1p2xyC/1Q== 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 172AFFEEF29; Tue, 7 Apr 2026 12:04:51 +0000 (UTC) From: Kairui Song via B4 Relay Date: Tue, 07 Apr 2026 19:57:31 +0800 Subject: [PATCH v4 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: <20260407-mglru-reclaim-v4-2-98cf3dc69519@tencent.com> References: <20260407-mglru-reclaim-v4-0-98cf3dc69519@tencent.com> In-Reply-To: <20260407-mglru-reclaim-v4-0-98cf3dc69519@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=1775563488; l=2994; i=kasong@tencent.com; s=kasong-sign-tencent; h=from:subject:message-id; bh=uhTQOpFFZDYAXHD7SVVg5W6PNjRmTF38550AcmIU3G0=; b=Ehtr3Q47mha0PCMw1Dvi147XVFp9g1ZeA7WFCt4ArsMQbs2JOAtGPfshF73Pd3eRPypIYIlGh Vd0f1a1ow1EAUlU9O3KwKcgILPqwk+SdD8KrH6hbYvLMaHF0e3O1UVA 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 Reviewed-by: Axel Rasmussen Signed-off-by: Kairui Song --- 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 Wed Apr 8 05:03:20 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 67CE13AB28C for ; Tue, 7 Apr 2026 12:04:51 +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=1775563491; cv=none; b=UwXCRkjWymLyBsB+OHX5l+x9e9e8HbcC/fyTcXo1RUHDkTN/4KCW2Zcj6YIHXG8YG6V9jd8ryxjNSdEV0u+45ehIV5PFhGSaNKA8JqisnJoo7aNdA8PTE/z22UfrgcoVL5c1dRxH7TDbc/udFv6PbYWhYIxbwi15CAON2WLBjfo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775563491; c=relaxed/simple; bh=VkpgFkQP9kSm8dY+9afCyPiICs3NYwoC96e7crLfYA8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=F6ATvkCyhdm78RJz5gLrvtqcwcjkKWFpDIdRXX/fHLNG2QuE6Sq6/j0aCNet5G7OjoCXTiyq90AxCrjn1jcyy0Puh3zDEHrf6XFh+woFevpLvANR0XLMpH3xF3iu3i+uJY+r3iBf/ZUJq6lyC70EC1fxf6bW3BFT9DnqjARAoR8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=l6wMaEo3; 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="l6wMaEo3" Received: by smtp.kernel.org (Postfix) with ESMTPS id 3886BC2BCB1; Tue, 7 Apr 2026 12:04:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775563491; bh=VkpgFkQP9kSm8dY+9afCyPiICs3NYwoC96e7crLfYA8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=l6wMaEo32KUG6A0ABd7g5ETkXEUy3+Yo/M9sZPKNMUKtPPjLx3q1AkLCPmUudMxKo 11qOKqetdlRMkDjPYW0MCud731+IF0J19HYqkepi+H3v+YocOaI1HJsn6O7+ChYcDw ef88Fo0dj5vLFwxmlmq5IwlMvxbsRwT+r5TIfnMRMV0/NTrT4aSMwVWlkHAJkY/NnR PjVa2bVhbG9fS1TAdqENDm0EMTZR92a/6os9hQfVV7Gcv11slm/B4LtHcythWOamzE FbjgY4c0XKh38PycAkSCGMGa/t2uKYfDWfCGpmjEq8Za3dR8FdLDmCzlzbF96uageO VZ7A9xImjAX7g== 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 2C765FEEF2D; Tue, 7 Apr 2026 12:04:51 +0000 (UTC) From: Kairui Song via B4 Relay Date: Tue, 07 Apr 2026 19:57:32 +0800 Subject: [PATCH v4 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: <20260407-mglru-reclaim-v4-3-98cf3dc69519@tencent.com> References: <20260407-mglru-reclaim-v4-0-98cf3dc69519@tencent.com> In-Reply-To: <20260407-mglru-reclaim-v4-0-98cf3dc69519@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=1775563488; l=3260; i=kasong@tencent.com; s=kasong-sign-tencent; h=from:subject:message-id; bh=t1HUAx5d1QFG9Hfnk5BrzG1D63onxNMjgtf1TQ7zmGc=; b=G/LAzVsgXa9uyC3AuUSyPm/Favo6TWapBfVT01cdZ+N2E2hSeUNPHof52gt/swak2Zegh5DwO TfpBpNKQD14CjIXlof4cclpmFDr6LD44KvOENP/dUYvCCYezKnFfds/ 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 Reviewed-by: Chen Ridong --- 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 Wed Apr 8 05:03:20 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 75F76248F64 for ; Tue, 7 Apr 2026 12:04:51 +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=1775563491; cv=none; b=MzLkHstjCsn/As88njVNJLpFfVfg5M8xoljIpVblAGazWPW2p+PEN+IWZAxb/G1ha7jWBp97RRn+SiQvKY+C/tKbGYqmUOEo6KhOxLoPe69CXbq6/zVUNT+LXtWNQeVG4hmgQR7BmGmUAEJmph+ZPxv7n9jRoVxGb7Rb9n/SqAA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775563491; c=relaxed/simple; bh=G4p+2Qn3vED8p23cqEC3WbmJz1xGvcxYhBu7z5p/IF0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=A1ZWJEaml4D1WRVix6YxLM8080kMChIGNnjozsco1g894EslNVIvVNC/4fXg0qAyA8h0E/ECDKc+bEZq49jbD5uqK+5//zIBBOhORX+cblF/5rnwawEqWnQh00oWjL6bCRHiJpeGxGOXLzJblziEGFjIdXv0zSARsyk6sIhO+Ag= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fYam8V+H; 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="fYam8V+H" Received: by smtp.kernel.org (Postfix) with ESMTPS id 4DE90C2BCB8; Tue, 7 Apr 2026 12:04:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775563491; bh=G4p+2Qn3vED8p23cqEC3WbmJz1xGvcxYhBu7z5p/IF0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=fYam8V+H9O/q9DJLSJ6Dun3jzVyPXK6gEOQvGjmPuZr7o4HxGTWP3ReKXxgpnuLY8 i8+4pmSw2NjAa9CJLFEfwoJk38ZZ2e0EDAE26oVjjMZg2HKI97dxqV7zIcGxIKMHlg pYVuHhF8ei9nejunjAJopX3Pwn2hxWwwXr101oyimktOaZA11TGC2TFs1+dlZBfZ/S qz5afypg44hDTtunxoRNdu9bN/2xmNEon2WMjCyVYJi+ZVsjis2uOwloZ+eU8gLrJI wrhspQxhxRtj7kqc5gi9saaj58RvCH0W3w/2OEMarswV5VT1b/GAjMz/F6XaBuDiVy ksS4wskWn6fpQ== 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 4324DFEEF2E; Tue, 7 Apr 2026 12:04:51 +0000 (UTC) From: Kairui Song via B4 Relay Date: Tue, 07 Apr 2026 19:57:33 +0800 Subject: [PATCH v4 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: <20260407-mglru-reclaim-v4-4-98cf3dc69519@tencent.com> References: <20260407-mglru-reclaim-v4-0-98cf3dc69519@tencent.com> In-Reply-To: <20260407-mglru-reclaim-v4-0-98cf3dc69519@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=1775563488; l=6218; i=kasong@tencent.com; s=kasong-sign-tencent; h=from:subject:message-id; bh=CkjP+pSvRYzYYzCckKVe1578yEEC5AkOtvh061Blbmc=; b=f1Tq5V9vysrHnzt6dar2YxzYLJsm6DuzMc92i3FpTbkioxA4dLuwDAHISJ2EVd//Qa+ByQ+0S 2sEeSRK7JaSBKEshGf/dUslkw8IFkeKAv9JkYAFakx5NxwY8Mb9WTJF 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. And while at it, make it clear that unevictable memcg will get rotated so following reclaim will more likely to skip them, as a optimization. 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 | 69 +++++++++++++++++++++++++++++++--------------------------= ---- 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 963362523782..462ca0fa2ba3 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -4913,49 +4913,36 @@ 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); =20 + nr_to_scan =3D lruvec_evictable_size(lruvec, swappiness); /* 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); + nr_to_scan >>=3D sc->priority; =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; - - /* 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 +4972,46 @@ 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); + + nr_to_scan =3D get_nr_to_scan(lruvec, sc, memcg, swappiness); + if (!nr_to_scan) + need_rotate =3D true; =20 - while (true) { + 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 +5037,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 Wed Apr 8 05:03:20 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 8F9DC3A5E85 for ; Tue, 7 Apr 2026 12:04:51 +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=1775563491; cv=none; b=AOKutMr2xfyaf4UNWWhEfQtAK5SQHKEat3cK/txuHNzsRv+RajO1TZa9h0XaPOWSQTSvS04cSLHxZJIiV3HRaCrB4HGsaFc2jTDjqDIBvw3Xn0/kRh4sZr4ysv1mena11eimnZLHmr6ed2Rt/MX2BUalvYJykI2a6acGm8nToNY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775563491; c=relaxed/simple; bh=VeX2URpxMMmGWllvQVRgejcYCV7xVkIbhcuL9oWF31M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qnfTnTUDRAGtRwEkZ2WfCGjhx1BjxZVc9/R3GsTvS5spf3x3I4Cbi+NSwAKE65Gmgu1yzeC9o5iY7YIxj+gKKj7VK7soo2zKbv+vBapTlQF0rSB2Zh7JkWpoXAjcj/8o+v5BrTwl8HzvZUe2+A7X7KsE9c3QPhWpFwHdQzo47HY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=APiuz0Wh; 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="APiuz0Wh" Received: by smtp.kernel.org (Postfix) with ESMTPS id 60EB7C2BCB5; Tue, 7 Apr 2026 12:04:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775563491; bh=VeX2URpxMMmGWllvQVRgejcYCV7xVkIbhcuL9oWF31M=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=APiuz0WhkwozV/Mf+a8ttzoZUscDS/xdAoU01q2HuHT6BUL2f00ZBWwxkuj39aRZs DGLN4N9HVkE8mKSHcjPJ/PfVB74ZpVf272ZPjcXng89YGkkvrDXuOcmnJoiV4ZO4kQ 4LI0I0l1L8ik8SqinBwUIpTXayfVAvDoy5F50NHzradcqOS1Xc1mCYmToAf5t0VDw6 CHUf4RSlHZc5ZWr/kEZuxroGxNItXLa3/2uiYECcIxX+JmsUATUdmanJZBlZPXtQFe A3EGCqJSE+8fEGwMO3DkbtvkZLvYuN5NmrfCOJBvqkWLkZPkaCI1/vg55CeBoym1TA AqEiWpVprSWwg== 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 58080FEEF2F; Tue, 7 Apr 2026 12:04:51 +0000 (UTC) From: Kairui Song via B4 Relay Date: Tue, 07 Apr 2026 19:57:34 +0800 Subject: [PATCH v4 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: <20260407-mglru-reclaim-v4-5-98cf3dc69519@tencent.com> References: <20260407-mglru-reclaim-v4-0-98cf3dc69519@tencent.com> In-Reply-To: <20260407-mglru-reclaim-v4-0-98cf3dc69519@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=1775563488; l=7136; i=kasong@tencent.com; s=kasong-sign-tencent; h=from:subject:message-id; bh=UDYibubK9+mNaaKcoZWIyk0t6953xzxxj2pTQxfJro0=; b=YXO8JjkjkrfocrFlEvhEFxqIX20w/vp8dngiroR6Ax/4g69p7qgqjoMV66o64VM0HNeAbOfWP axontquOEfbA/RPuCELfYqFuqrb4vbyLFZMYtlf6kY8ndpbLOqUln5A 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. Reviewed-by: Axel Rasmussen Signed-off-by: Kairui Song --- mm/vmscan.c | 60 ++++++++++++++++++++++++++++++---------------------------= --- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 462ca0fa2ba3..d3fd5bb56cce 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 Wed Apr 8 05:03:20 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 96E993B27EF for ; Tue, 7 Apr 2026 12:04:51 +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=1775563491; cv=none; b=LlE6uzyY8aCrPsHXNEj2uxIM5JkXCa7wPL28SaKR5pxav2uO0gPzbAaRL2qWHv5giuGTIJFnMG88h975kvZOO0n9kfe6DovixMm/dPLJX5htp391y/WTGPL9YNrfxj7GXZzMEUrPLBg518rrm1tYXUwX5u8ML/j8kvFnuYGEgqo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775563491; c=relaxed/simple; bh=ztVO6NbikqAF1UlcRZLjXHar939TgkRFnRH80QPPGLA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=JrOCbvbqdNzupKiWMPXeNbt6IwfpLZ6H1zAdZt2ZmVCS/9tehOAVC1ybO9U2cNjm+9C+92O7d0O6LGSKpkjhaHXMyJtJ+AruJZMtf9CtgAFw6gBrkY3LXlRfq01phkc169EcgsDBuAoRDUD8YH3TsHgvilKftCHZeqYHCibblZ8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gXZ5Jr+y; 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="gXZ5Jr+y" Received: by smtp.kernel.org (Postfix) with ESMTPS id 74B38C2BCB7; Tue, 7 Apr 2026 12:04:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775563491; bh=ztVO6NbikqAF1UlcRZLjXHar939TgkRFnRH80QPPGLA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=gXZ5Jr+ybcDOrxB0xUP+vcfHXd4uwEXxY6Y1hc9hpS8UWcX3umJG2ULPBWOP+MaRN NIROfoLWcC0gqT1EVQISMdIM31CBABXbhF1hpbOqGVy62/+rTZLwgGlVKH8eJdAYTD N67PBggw5z4v4irWWrZ9AyzeU7bjVrBlcqvZ57XZRjCXda3BwEjuajF+MAu9e59uCo 7YWOreC8FiIy22RIpOFDFoUbQJbGgQSs2gYYy+6UqTLb3dQ+MLZ8EhjVzGiPiLHayJ 944cvF5NlkUjPmkasPqkCXxjhB0bCAAS5HRtz8/zv83haseOCw7gYURlQRR17oFZ7D U1XNYxteHuzsw== 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 6A25CFEEF2D; Tue, 7 Apr 2026 12:04:51 +0000 (UTC) From: Kairui Song via B4 Relay Date: Tue, 07 Apr 2026 19:57:35 +0800 Subject: [PATCH v4 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: <20260407-mglru-reclaim-v4-6-98cf3dc69519@tencent.com> References: <20260407-mglru-reclaim-v4-0-98cf3dc69519@tencent.com> In-Reply-To: <20260407-mglru-reclaim-v4-0-98cf3dc69519@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=1775563488; l=994; i=kasong@tencent.com; s=kasong-sign-tencent; h=from:subject:message-id; bh=X9Gq2uPvlNZqVyS5yzKBjUAw6aqnZAcV2BEvNpvNlls=; b=lyFH3Gn5CA0OabEA/Rt9iUfEdmXNiUxSdscoLOFciogLnVjX6lMOEwOJkWYYMQK9HQ02TbJJC 3FgG3UhlKPaC3WaVymdDnSuUqsq0Xu0+p3ymA2qhmsWNPox0E5UyEGZ 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 d3fd5bb56cce..c673830f4ba8 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -5003,7 +5003,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 Wed Apr 8 05:03:20 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 B1B523B2FCB for ; Tue, 7 Apr 2026 12:04:51 +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=1775563491; cv=none; b=I0IIXnXozqQUmZP9xigt78s3JoKB4RLo32HQ5eb+o/9aIwZCuC9ZjWY874RfSYcFjk6evoIDxmE5878WFK7S9qSushrFj7Ykt/pNsC5FwgmTDRo/XoCaJL7V72FhLCpIT8EMIw/Fyx5Nid2G3rnSklM7ISdj6EI9PWUidPeLbD4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775563491; c=relaxed/simple; bh=PYh84A53nyHTsFjf7EcHQyNYWt2bHhfXejabhh/MBkc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cE+9NPf9R3ub1aUL+TE9r85DYUlHe5K04SvjfC0xtos6e+tKWklinTo4fPMCxW4QlwcSG//R6ThqsK6JNKciqDNhCNuXinDAqDsfdJc+zvkW1fhxE8f03AGlocqhIB8iuW95PlvKasCkA/cQjqnYu8flORj4MAnaBb+uehvbrDA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=vC/66VV/; 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="vC/66VV/" Received: by smtp.kernel.org (Postfix) with ESMTPS id 8FB86C2BCB1; Tue, 7 Apr 2026 12:04:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775563491; bh=PYh84A53nyHTsFjf7EcHQyNYWt2bHhfXejabhh/MBkc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=vC/66VV/jCGyBD8FrM4gXUOCBw4lksD3axClRDq1jvBvJtxSABhe2BcBkfvo4Ng+A xcY/nZwHzrEA++/DBxz2fy0XL3CQi4GnHFj4NWAizsaMMhVkOsrDuFXWgkIA730uHi Qk9FCBRjIZdOnKtUWH5ctQiX2X2Lph8dJoRyzDw8p34FanGP89AaCm3/6m5/EjwFeF ZpjAJ7DVo2UpaCMjN1iyjxwbqEAQIVNNNTUezy8urK+T0Q0Q79p5LPKCPQT4YWLs4E 5fB1ZaCBqphB4ePPr08A2CbAzwXLCUAiI7T8hJHwXLPo1T/PKiZ/RNRjpZcGq8bg4l w7M/X2gGAkbhA== 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 872C2FEEF29; Tue, 7 Apr 2026 12:04:51 +0000 (UTC) From: Kairui Song via B4 Relay Date: Tue, 07 Apr 2026 19:57:36 +0800 Subject: [PATCH v4 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: <20260407-mglru-reclaim-v4-7-98cf3dc69519@tencent.com> References: <20260407-mglru-reclaim-v4-0-98cf3dc69519@tencent.com> In-Reply-To: <20260407-mglru-reclaim-v4-0-98cf3dc69519@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=1775563488; l=3505; i=kasong@tencent.com; s=kasong-sign-tencent; h=from:subject:message-id; bh=GxRE/zl5OeQby4fP7APi2mfKz/sRAK5Lkyko20nnWwE=; b=scutrbRvNg/iILtiYi5oBBbflWKr+fDUWNcVgfnv1UJ//9cI9hiauvRp8iroTbvuVvlmZf1Eu mAG/X+e7sSDBeZnpj7+TEghS63W0Gy3pNGXTdqvCloIAafgo7Gddrsg 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. Reviewed-by: Axel Rasmussen Signed-off-by: Kairui Song --- mm/vmscan.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index c673830f4ba8..354c6fef3c42 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -4979,7 +4979,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); @@ -5000,7 +5000,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); @@ -5011,6 +5011,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 Wed Apr 8 05:03:20 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 C6CC43B2FDF for ; Tue, 7 Apr 2026 12:04:51 +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=1775563491; cv=none; b=Uj+qeJBmVvPZP63JYUJNKjbO+cPKYKRCUnHELH3vD6BxIr7OZEy76VOxHsXoNryTChH8gPUx6owS2axNyAOHMM2C9zlZYi+4clBFUkSOfmQknreLN0NkXl2v3uGKwruhhhtOvLvbDvMERvoGoyNN/RS7cuHuXOKNNGd3YNrp8Xo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775563491; c=relaxed/simple; bh=gNOhspKKafM6N0nXsURc+vN/1RxmMZiW5gmwmDvQBOw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=s6Fvn18jvG37BAInEYPJNUzeLtVQrt0IHmBXk0uNZvVMd0XxorXcDxYMRrwW5Ss1OuitLeI+6TZ6Lf1nLy16+6YduwdWqRpX+XDMCJ0bNpvhVFhuhJxE/FRyHwoijsoj4CcCg0HWGL2QKuN4HzJckAFiK+HLQlilf52VXJX3poE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iiH+fePD; 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="iiH+fePD" Received: by smtp.kernel.org (Postfix) with ESMTPS id A69F3C116C6; Tue, 7 Apr 2026 12:04:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775563491; bh=gNOhspKKafM6N0nXsURc+vN/1RxmMZiW5gmwmDvQBOw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=iiH+fePD64yyIbRKkiRtSPKf7bhZKcpcSn/J/KyJX3HCqU/dR6BYmsbXxkvWML898 l1DcQX8pOJ6d9M321s4jYeGXDa66sWtJ1j84GTGbA1OwfgGaWZoGlwkb+iI6W+BHJT fAN5s7vjxF95PhGCwKP8loRjw2lqtKyYD17BBQtdsnCBlSS/f5QOACKRf/K4+DvMz4 E28yIT0f/bYUw1/Zmm0L+kl8GjsMJVL1dbEjGQG0nRKsHRE1zhLP8WFV9vADnl459C bloKAtm/S/SDvUgRimElySGzXU6Jl4YUtlX7rJfHgV7XMJjo63bJ6bZazscl1ICL8J scuRnGeW5SfLw== 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 9EB51FEEF2E; Tue, 7 Apr 2026 12:04:51 +0000 (UTC) From: Kairui Song via B4 Relay Date: Tue, 07 Apr 2026 19:57:37 +0800 Subject: [PATCH v4 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: <20260407-mglru-reclaim-v4-8-98cf3dc69519@tencent.com> References: <20260407-mglru-reclaim-v4-0-98cf3dc69519@tencent.com> In-Reply-To: <20260407-mglru-reclaim-v4-0-98cf3dc69519@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=1775563488; l=1702; i=kasong@tencent.com; s=kasong-sign-tencent; h=from:subject:message-id; bh=8QqmWYtnuzAwnHJdOy0QH3VxtrTCFfqleHPzwbmrh6I=; b=stnnipVCUvw5BM7Mfht/5ngS1C8fGqnhMtTfZsYkGl8C0WNG+0YMdtA71/LikKDgWLCLJxycr bjc6an7gbItCc7yQxHD4KcETzXtC3O8lTBBkFIwLIik3waNSiVls8jo 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. Reviewed-by: Axel Rasmussen Signed-off-by: Kairui Song --- mm/vmscan.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 354c6fef3c42..b60cb579c15c 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 Wed Apr 8 05:03:20 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 E68F23B2FED for ; Tue, 7 Apr 2026 12:04:51 +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=1775563492; cv=none; b=DuwlX+42upBvPSRrviBQKsZSjCtMXos+GYF6XxS+T2OutsP0G2i0MiU/OYerW+ByLrCVs0D03Tv2KTpse+iEzDPOROp3zHx5WlcyjUYu82Lt34vRlTDwUItF4ut62lmu/sJin/w796pfwzZ1iqpovjxCQmCaoYKXaSYwvyhYaPE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775563492; c=relaxed/simple; bh=fUTYYzcNXoeJphxrjwgg8eyMN86yT/tICs/nPUgAkC4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DMrFwtLYggsrVT/awSaYw/Z1KO7JDxSHZOZMrzZPRG/CDulTujwEMl0Lmdlf1k0uAmfsxAzK7t31/RtNq8kWqiiVwByzS37eMGfIsi+uZqIgG/43FpfOolH0pjulnr1MTkFNRroHs/UMY7gOposAXmjSCv8eOegBjv9OQoHQcJI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qWJ1LMFY; 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="qWJ1LMFY" Received: by smtp.kernel.org (Postfix) with ESMTPS id C78A5C19421; Tue, 7 Apr 2026 12:04:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775563491; bh=fUTYYzcNXoeJphxrjwgg8eyMN86yT/tICs/nPUgAkC4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=qWJ1LMFYZ6n+2nYUGNOi1Uh1fdr/G5AbnDlcMoyL7Htq5FWbeD/PqHKgWvkWRVA5T jv+7H3T1Mf+7Gk8KmnSUFXNOfs7s/0Pdi8y/V2IQWD8RwDXoLgXfGfDDr6hNYuQRym VEl/85SAssFRwwEvu3QY23oKQ6tw6amcH+XeVZxyCF7cjmO675HL3X4oMrZiwop+mI uY7hpRH+AJDlb17xjtfRGj2x4jjBIcK+yk0pLgXcyPzcbUmyBYW8yRq9yaQMXNrZY6 LuGp3XeZMe74kikzHn+twcQk+u+lSHEXNUZw1IF/Ix/FtX5PEdkKEVcWkKNjRtrILH PmnnUmUV0TYrw== 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 BC561FEEF31; Tue, 7 Apr 2026 12:04:51 +0000 (UTC) From: Kairui Song via B4 Relay Date: Tue, 07 Apr 2026 19:57:38 +0800 Subject: [PATCH v4 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: <20260407-mglru-reclaim-v4-9-98cf3dc69519@tencent.com> References: <20260407-mglru-reclaim-v4-0-98cf3dc69519@tencent.com> In-Reply-To: <20260407-mglru-reclaim-v4-0-98cf3dc69519@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=1775563488; l=2942; i=kasong@tencent.com; s=kasong-sign-tencent; h=from:subject:message-id; bh=nPwwx1WfwADmlvFLW7DWeULDk+8fNcH1ArJSvQdlFwE=; b=fmysAzwJH+E/zuRFCACBe/2/eQ+jx4Dmnzi7FbSNE/l5AQUI7sbEVw+fARwBg0RnuNWroLWCx DnIJMDdPyNhBfuETpf/5zmxodAP5SDoKX1SwBM7QGv39CPvhQyxyCXb 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. And using the common routine also keeps the folio's referenced bits, which could improve metrics in the long term. Also no more need to clean reclaim bit as the common routine will make use of it. 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 b60cb579c15c..2a722ebec4d8 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 Wed Apr 8 05:03:20 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 0565E3B388D for ; Tue, 7 Apr 2026 12:04:52 +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=1775563492; cv=none; b=epo/R6JPGZIvX0qfdL0WQFqRk8WeHnuODLRPbN02uHYGjVfqzq6Xlcj/BlyYCtcALEnKkDLHpv58HtRTYWnAuE3CvCP2o6mUXhYYlw6QN/MPVTmYSTv/AT0E92sYGY8qTgQzVDqw4Skg4TInvPl11RWq8/qAvnRZKGrtUnfMUZU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775563492; c=relaxed/simple; bh=6WJ9Z2fsnLq1GjpGSfSI7xNSBoZJyBY9EzWl0am9S4Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ePidQYo86v+9MtVQSLyLXDTPZEaR3LGlnMq8k0EKptjUjFxHttE7gd8peMr2V9SpEFBxoAWSMQEuZ0X5XkdgDJWvEuqLci7hLHN55k6us/SqQrxF2iVKY17b2bkfYy0H0cEt+NhTRptCizqp/tFdGaFlyiqZsWwYl2xcJCb1wMs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mFgYac8W; 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="mFgYac8W" Received: by smtp.kernel.org (Postfix) with ESMTPS id D9FB9C2BCB2; Tue, 7 Apr 2026 12:04:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775563491; bh=6WJ9Z2fsnLq1GjpGSfSI7xNSBoZJyBY9EzWl0am9S4Q=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=mFgYac8WDbT3YK3ybKxEdFULRJJljQATksHlISvgxQMqi8x8XZrRLhON+GNoXYJyZ 3+BG3Isnr8tzCCy8j4FPbc2VKEkQXhsRubue0Jykj6lW6lul9me+pii+A+WdnizbXM XpTsx4FBitIONumr3EF+Lt+c70OaXyfpjw50kiJFFadBbAmqyogLvxSgWZ9MC5mII4 9FG/6wqhPGssEGBypCVpvCJaS9dpfphH34mDqm1NWZ8ZzqBvZ7AnIGAFOxcBGj25Qu xvRJm0n/NaLHWg5CDeCQdElkuhKBQkoxgolW376Nf4zjHTHPHPDnV+qsOGbKSWqAVK zHHrEhP8BMq/A== 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 D1C70FEEF2D; Tue, 7 Apr 2026 12:04:51 +0000 (UTC) From: Kairui Song via B4 Relay Date: Tue, 07 Apr 2026 19:57:39 +0800 Subject: [PATCH v4 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: <20260407-mglru-reclaim-v4-10-98cf3dc69519@tencent.com> References: <20260407-mglru-reclaim-v4-0-98cf3dc69519@tencent.com> In-Reply-To: <20260407-mglru-reclaim-v4-0-98cf3dc69519@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=1775563488; l=4353; i=kasong@tencent.com; s=kasong-sign-tencent; h=from:subject:message-id; bh=juNZ9Ne09rpe7JhI6g449eQEPulp7krd3JvDjYpqUDU=; b=L/XappBjZIy54+yjygXQ67LinB3SJCAvvPc29zafvIYJNA1Tk0die78KC81DRXsYP529ZfCc8 jXhca+EjNZwBVwzg4otuXxeJb4cDhQBfs0puB/5JAoc+Ii0hClajPbb 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 2a722ebec4d8..23ec74d3bf6a 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 @@ -4994,28 +5007,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 Wed Apr 8 05:03:20 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 225F93B38A0 for ; Tue, 7 Apr 2026 12:04:52 +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=1775563492; cv=none; b=cbLLPoOZn7xlvV7CnlgryxJTmCKvUupYNRyiGlfkSOhOEd5V8UEYEhM39bO/S3Pg5pYryPb1qn2A8EBDOOrhHmxWDymz18exGn10qRchgLyQ/7KdlMHoQJNQQ92zvDuQzSwNZTHBuuFdHVOBDfPrGh9+qayKYSQDCk2zmT77m2Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775563492; c=relaxed/simple; bh=F6RMF6i5UclqfTQm+R0d50JEibkYyOaunBwm+v5PBO8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SniLHg6dX7962eMPoDHHXRfq2p02dRT/7SDF0LUg72EUKLapsMGVxd/brnpabUoWdr0jTQX4obiMazc8PMd4BK8DEVM0sdW6yWWnP5Acc9B2Xqx4kh3YIHOVExuNUSsC5/bL7QfDK669/HWnGIjhbiOLvxcmutj2uTgZRy6/RPM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qSYuwWEu; 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="qSYuwWEu" Received: by smtp.kernel.org (Postfix) with ESMTPS id F1337C4AF0B; Tue, 7 Apr 2026 12:04:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775563492; bh=F6RMF6i5UclqfTQm+R0d50JEibkYyOaunBwm+v5PBO8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=qSYuwWEu8T9L6KJt0kJtwoX0rYQPzZHTj93FqkdkENIR9A0IZVRhA7ktU3gwosyie 1SsbT/3eZhdKJZAwUHVwcrUdu8MDKpZ4ZDfAtdsD9AqOPivARB+SFevznanMwy1V/3 WSZOOlhtI5a3lH0NkDgnwF2LuotsqFDJOfJNteYxNwAvsxtR2Md9XXu4ePF/RUXqy8 B1a4e7ARZAiFOHcNpjssucV61ez14BpQ9zHJ/eKfTXsD/VUpBNuf3dNH3ZWp2CSVrz Tt6W2UCNgp5feis4nuHMoWB6X3/9YmS+G3FgBOJLa9X9uk+GY2tu/2e5jVBTG9uwv7 cF7xoHi4n52iA== 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 E858EFEEF31; Tue, 7 Apr 2026 12:04:51 +0000 (UTC) From: Kairui Song via B4 Relay Date: Tue, 07 Apr 2026 19:57:40 +0800 Subject: [PATCH v4 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: <20260407-mglru-reclaim-v4-11-98cf3dc69519@tencent.com> References: <20260407-mglru-reclaim-v4-0-98cf3dc69519@tencent.com> In-Reply-To: <20260407-mglru-reclaim-v4-0-98cf3dc69519@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=1775563488; l=2628; i=kasong@tencent.com; s=kasong-sign-tencent; h=from:subject:message-id; bh=ZXuz5KArlehmdQ1TdnVKon7VrJCqzZhhKUqXRpk3w3E=; b=dBzNBK3Po2LqYeOED4ZvnSqKMvMGSRbTy2890M4Akposl36YW6a5ZgccUHKV0AP350izc07g1 W1hP7NNBrqRBRM/zBoK83ziCAR4nz/PP+XPiVmOZo3++PO/iBL2F+z7 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. Reviewed-by: Axel Rasmussen Signed-off-by: Kairui Song --- mm/vmscan.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 23ec74d3bf6a..73b1aeb6c292 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 Wed Apr 8 05:03:20 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 31D623B38A5 for ; Tue, 7 Apr 2026 12:04:52 +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=1775563492; cv=none; b=PY+bAMKEENDgouaHO97qyJlKx0NBuYIaY3xWZVrWYMRCz7gIkCUDvu3d/s0GNoUFkESQBxA8ot/y49UVDTSSYQevdqGjzN1oeCiEkVJdQ+merX4T85fJKyO4mKlpup7tW2/+qv8tsVtv46IV7bA0tKze57eM1JGpuRhn2vGIFHw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775563492; c=relaxed/simple; bh=BTGG77nQT8TmTG8unDXgY6sdHQV2fBDHN+rdF5bOjg0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AVmDfEaeIZ9NZxoi/tOVFr0hLjQiUiBAvMu6rXnyanwgLT2bVUrX5LXiXmJ8R6oeg7761inKUedJS/4/HMMyqD6czk+VFu68aCi98CbSRcL96tr/1boTqbXnACGJrwFCLym6uoX2eNhFSjjRtEZ+VIasEwoDDNnec3s7FuPjZ08= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Aa1cVZWZ; 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="Aa1cVZWZ" Received: by smtp.kernel.org (Postfix) with ESMTPS id 12800C116C6; Tue, 7 Apr 2026 12:04:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775563492; bh=BTGG77nQT8TmTG8unDXgY6sdHQV2fBDHN+rdF5bOjg0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=Aa1cVZWZowsjBlb1luy7bwn9Gucm7HWBcA7jgDvDIyGBNDaSNdioaf838oymXM9K4 qsTLKlyBJ2Kvx0T5V9dq1zwQLfXG10NJMjSyJtzWptCMoVteMgh8NXcWDmFeEep1be KaoX6ErOixlAOqijh7ivDm06we0P85Y5TBUSejJrS7HODSKOCFBilsU1JzuPQU7KhC EYe0F/N5ZmIs4IG6i0QbkRCNfu/fzlaCFR7tXG7A9Ai+8jy0t+RbJhEoVcRtAJgcvq KI+0eQHoJ5kGo/M7F2Amf0jmH1H6Cx9gLQQWkYodbaDRWNftZ5lhOeEx52/7PRk0R7 ZN7u9F9eHU9KA== 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 096BBFEEF2E; Tue, 7 Apr 2026 12:04:52 +0000 (UTC) From: Kairui Song via B4 Relay Date: Tue, 07 Apr 2026 19:57:41 +0800 Subject: [PATCH v4 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: <20260407-mglru-reclaim-v4-12-98cf3dc69519@tencent.com> References: <20260407-mglru-reclaim-v4-0-98cf3dc69519@tencent.com> In-Reply-To: <20260407-mglru-reclaim-v4-0-98cf3dc69519@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=1775563488; l=963; i=kasong@tencent.com; s=kasong-sign-tencent; h=from:subject:message-id; bh=YGvPokmG7KQWmukudycU/AK+GVC/fttWQF1dztv7kG0=; b=1P3aU29mV5XCLDnjvo0mKBZ+hcU/s17mLd0L4aidsBN7iUJ1+9CVAiATK3e59bQecehiQ9XdN hnlmm1F1OG2B4X2BiJVZdOspefWVhhFIlm8UhrAaVrGk33xXc/BuG+6 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 73b1aeb6c292..79e8a8e6555c 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 Wed Apr 8 05:03:20 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 47F5E3B38AB for ; Tue, 7 Apr 2026 12:04:52 +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=1775563492; cv=none; b=caRCn7XmMcWFqf/PzxCSQjU+cPBW570Zft+ku/PKYEvAtJPb0In/Ku+ZvPynD68WL45lv9RWOKlHrdvLLdGH6feeKowSvaQf5OrQRj0d/rCaPzY70VwFeJYbq7MD4xhRLpCz1uew9Y3Dkid2spYFjixFiiBnedWLrHqoLf6iuRI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775563492; c=relaxed/simple; bh=h3uvopwmL9Qlq/BEScjVbnTEMlwAjzwawTwVaOSJmaM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=VUeDh0Ck9W/uLdZ0jg6HRvjxuCjrUne5wHexf3sfPXAMmKBuv1I5rljbp41325SgDUQ5pkGU1Crxa1EjMx2xSWi/yJQCfBZsuerPr48PqVb6todoaA9pmwBlsjUbISHb5kSQfr0lEkoYTMVI2/WKswxw7LJZ5PFV8lH+jnK3SqI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HA+4Mqqq; 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="HA+4Mqqq" Received: by smtp.kernel.org (Postfix) with ESMTPS id 28AB4C2BCB3; Tue, 7 Apr 2026 12:04:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775563492; bh=h3uvopwmL9Qlq/BEScjVbnTEMlwAjzwawTwVaOSJmaM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=HA+4MqqqW51v1k586Bpo2dmnwn1QeVavBzI3FrwaSYZhFbXHkIDMfZNynxpzBsMG0 8L/4eYTEzJNLQYx8GGzVoupwi+ON8VM2kcT7C5TnIkBjHo8Ixdl3SOFZjrvceo3WJU 8X2DG8u4gJjm2wNSCLBrjunGUUAWsZibazvjLU+T8QuqaXqTF6z6/PIDBFfhAzjYZi erk4K8/jDkGwSun/mt9ky/126Ukfy4hcdEfJioprIvKwh71EVy51O56uRAhLoegRG0 IWc/tW+Pi+Yyh10MFddoa2klcuhQG4cFgnWPgl1nuyknZht5NRysiGJNn7S3/XOLwC R6HjV/dxyzm8g== 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 20028FEEF31; Tue, 7 Apr 2026 12:04:52 +0000 (UTC) From: Kairui Song via B4 Relay Date: Tue, 07 Apr 2026 19:57:42 +0800 Subject: [PATCH v4 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: <20260407-mglru-reclaim-v4-13-98cf3dc69519@tencent.com> References: <20260407-mglru-reclaim-v4-0-98cf3dc69519@tencent.com> In-Reply-To: <20260407-mglru-reclaim-v4-0-98cf3dc69519@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=1775563488; l=992; i=kasong@tencent.com; s=kasong-sign-tencent; h=from:subject:message-id; bh=t+bQPV8ryOa6wU3HDSh3IxJFeyluNIIGXhr4Th0dCWo=; b=aqzmwJTLY2I7PnriB7WIAsUemHYaspYAC1yP/aEKvmzBGOSdWoucf8WWE46goAMxBMbR9FnRc 9nOVTD2uH7gDqcrMRLcfdeOtWdebjdvYyXUN4ygqlQTmySFOCVQkyfE 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 Reviewed-by: Axel Rasmussen Signed-off-by: Kairui Song --- mm/vmscan.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 79e8a8e6555c..cea6df51dcff 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 Wed Apr 8 05:03:20 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 5C2D93B38B0 for ; Tue, 7 Apr 2026 12:04:52 +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=1775563492; cv=none; b=hdIIVF3hiJIIbMpVeQps81AtjvpRQBHj8eOSgih5Pk/5D73D46JWaawexZB4hg9dHhyExOjhSs7diQFfZbwx5PXwL/LfueokYWCD76B0t29NTJEHcLsHtGNfCNMH+q2SNiS4Q2UqW0Ml2RBKNm7jlfFhh5cvaB/oo8Z++tX0PLU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775563492; c=relaxed/simple; bh=ovatNqtznssd/gITN5eCBeKBUZKWvCBBAHjSAQIuwj8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=tvAWfB9NA+a0h9GT2My/Ts6RkbgxSho1RtD6/MCLvdcDu6Ghh9eCIv8qp1KTfIMUVDuoHHe56mAVnBBO4NG4aSiJKdnrjQRS04h9djTysSHe2Kzyq9iM8XagAF+tOAv93l7blHB0PjpAgxFXUGdldjR4yrLfB1C1bFhtwuUYKqQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=s/JX1guG; 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="s/JX1guG" Received: by smtp.kernel.org (Postfix) with ESMTPS id 3CD46C19421; Tue, 7 Apr 2026 12:04:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1775563492; bh=ovatNqtznssd/gITN5eCBeKBUZKWvCBBAHjSAQIuwj8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=s/JX1guGiz4MIPnkH9WWs9QcLNa/45srPIXAOVZgjNb48Fw66ozW6kbdnNOmIYpOn SwTveTLrWBxgDbzfwm3RspZPM+5n6ZsoJCMFdFm/LGQZvB0Qu2q5fi5LNtE4xt7DLA OjCzv3eJjKy10cjmVKXsFXN5i1Wx4UenYGrx5I26OtQF8VQboor5ZaLD0KPDqruVBo n+QszR9xQeAp25i8k/EqMmFD6Qdq3DosVjkApNZ5kp3XEMaIftK1Nk84tUZ3n22AFE CdVbXAOTGhPKsHA9UkVz4RKYUSkBoZ6Gehn69z8gsQi+MOp871PlZbsG7NMrMEySz/ TZV+YH8HCY/4A== 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 34D3BFEEF2D; Tue, 7 Apr 2026 12:04:52 +0000 (UTC) From: Kairui Song via B4 Relay Date: Tue, 07 Apr 2026 19:57:43 +0800 Subject: [PATCH v4 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: <20260407-mglru-reclaim-v4-14-98cf3dc69519@tencent.com> References: <20260407-mglru-reclaim-v4-0-98cf3dc69519@tencent.com> In-Reply-To: <20260407-mglru-reclaim-v4-0-98cf3dc69519@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=1775563489; l=6741; i=kasong@tencent.com; s=kasong-sign-tencent; h=from:subject:message-id; bh=7QHyjr50/quaZhHvOcbUKxflnau3ozYmg6LdN0uZIvA=; b=5Z8fDGv9OJlrUKzC10NZUWtSzDzWTPu7NVnBtOD+zo9hXGm0HDSYsBVq4BpUHAVZjMRyRn3u0 zP+B6GJnYCBCeEevZhnrIEGrodlWr7M6dJawAaylkpM7qj72/PV5f4s 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 Reviewed-by: Axel Rasmussen Reviewed-by: Baolin Wang Signed-off-by: Kairui Song --- mm/vmscan.c | 90 ++++++++++++++++++++++++++++-----------------------------= ---- 1 file changed, 41 insertions(+), 49 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index cea6df51dcff..609cbaf2cd4e 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