From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795963107; b=UR/NU59pZyJALYpBcy9I9FOkuDBuV+VN1nlGNWxIYijyeHTQTK+Z8/pacoHYtFaZZBBc oWdCTnms01YEDMIFPBLtdO/5MFkBHd2Myz2++EbE4/76aXHpKGi9ArtsJPsNFoZ6+EIQ4 qI0JS4277wTpVG1eNWKb6gSnYaml8nIK1mke469pUaX29yvykCTisAqJhx4WLVny1ld9N Z1lgnAd++btTFzA7bPgdCH2gRwAg26ou7UaVpnQ+ijWIXD5Fxxug4g9rpPB/row+OuQvx FjLzdTRdQ0mODsv3TQGC8JD9GCJAmSSiX5pjwYsKnW662Gxhnz2cSlm0i/32WcUzQAg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795963107; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-Id:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=N1X6VrhZ1a53SxwK/SvulcuMxwx5l8tT4riurO22ats=; b=Gc+xDfLM2xxJEA1exe8oGsaxxFzgjanhzuObmb/M8Itj6CRYTwtx9oXb+mgoSE/5cNmQ UA1PR4Yh6WOoLWS6lHlHRkammle6ZIhHcH1r9UT8GjU4D6JSw72Lib3RUucdkIk4arQGv GKQyF/jMYkcYGqW7TE4KONv8uJhE7GGejCEh5SBhIbTyxoeoS6mBTphUlkTe9e/7dlY+5 TSxc9r4ZC9pmXnO8reZwoTFiBTtb3HiwznBNZEGZRMKpInJigw4tw3J2vAQBK6AKoNwCB UnHHFa+QIIFosxXujGnoSmVjRt7uVryal88q9jTvn+MbC8u5CTGdKHmDsCdDBTL1AzQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=klDBowhS; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1EC72606A323 for ; Sun, 29 Nov 2026 14:38:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=klDBowhS Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8128A1F00898; Sun, 29 Nov 2026 14:38:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795963106; bh=N1X6VrhZ1a53SxwK/SvulcuMxwx5l8tT4riurO22ats=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=klDBowhSdXe5s1gWG+QnRNzI+9TOpiwR7cpnGt8eTz5kcpsfd3FcmqanXv2lzksxp K+8dStRezybFj8IujnAOazFI+ALZlM/ylFsrogFdj+PGTf2hLTTV6L2TNPVJrsXV8O B0sSqwGOaN3diFDaTrhI9aeVpjEgZG2M6CMSV8iYpPkVLH4mb8jAUOCjcvhhNzy2bB XoL2QdVWtiQwh0qTA2Fc7SCvrsk3hKBmxtaepoQ1KuumMIFeIuxurtYdgm0ej2xt69 pEvbGrizo6zsNp+ZdU93Xlb2PyzOKmxrgkrbo19tLYm6zIjl0S4T/ZXIjY1TidkOHF Kh+xuVlOuiNdA== From: "Barry Song (Xiaomi)" To: akpm@linux-foundation.org Cc: hannes@cmpxchg.org, mhocko@kernel.org, qi.zheng@linux.dev, shakeel.butt@linux.dev, kasong@tencent.com, axelrasmussen@google.com, yuanchu@google.com, weixugc@google.com, baoquan.he@linux.dev, baolin.wang@linux.alibaba.com, mason@kernel.org, david@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, ridong.chen@linux.dev, yuzhao@google.com, Barry Song Subject: [PATCH 1/3] mm/mglru: count all generations as evictable Date: Sun, 29 Nov 2026 22:37:57 +0800 Message-Id: <20261129143759.96221-2-baohua@kernel.org> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20261129143759.96221-1-baohua@kernel.org> References: <20261129143759.96221-1-baohua@kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Chris Mason With MGLRU enabled, clean page cache that was reparented from a removed memory cgroup can stay unreclaimable for as long as the parent has no other evictable folios on the same node. try_to_shrink_lruvec() derives its scan count from lruvec_evictable_size(), and with a count of 0 it runs neither eviction nor aging. lruvec_evictable_size() adds up nr_pages[] only for the generations from min_seq to max_seq. That sum is complete only if the count of a generation is 0 by the time min_seq advances past it. But try_to_inc_min_seq() ignores the counts: it advances min_seq past a generation as soon as the lists of that generation are empty. A folio that folio_update_gen() promoted is counted in its new generation, but stays on the list of the generation that it came from. Normally min_seq stops at that list, before it reaches the new generation. Reparenting moves each list and each count to the same index in the parent, where that index can stand for a different age: index (seq % MAX_NR_GENS) 0 1 2 3 seq in the child 0 1 2 3 seq in the parent 4 5 6 3 folio F: on folios[0], counted in nr_pages[3] child: folios[0] holds min_seq at 0 parent: folios[3] is empty, so min_seq goes from 3 to 4 sum: nr_pages[0] + nr_pages[1] + nr_pages[2] = 0, without F The fix used here is to add up nr_pages[] of all MAX_NR_GENS generations in lruvec_evictable_size(). Fixes: 163bc3d68c9f ("mm/mglru: restructure the reclaim loop") Signed-off-by: Chris Mason Signed-off-by: David Hildenbrand (Arm) [Barry: Rebased onto mm-new and added comments] Signed-off-by: Barry Song (Xiaomi) --- mm/vmscan.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index cbed395955d4..60c416819c57 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -4272,8 +4272,6 @@ static void lruvec_evictable_size(struct lruvec *lruvec, struct scan_control *sc struct lru_gen_folio *lrugen = &lruvec->lrugen; struct mem_cgroup *memcg = lruvec_memcg(lruvec); int nid = lruvec_pgdat(lruvec)->node_id; - DEFINE_MAX_SEQ(lruvec); - DEFINE_MIN_SEQ(lruvec); nr[LRU_GEN_ANON] = 0; nr[LRU_GEN_FILE] = 0; @@ -4281,7 +4279,12 @@ static void lruvec_evictable_size(struct lruvec *lruvec, struct scan_control *sc for_each_evictable_type(type, swappiness) { if (type == LRU_GEN_ANON && !can_reclaim_anon_pages(memcg, nid, sc)) continue; - for (seq = min_seq[type]; seq <= max_seq; seq++) + /* + * Reparenting can leave folios accounted for in + * generations outside [min_seq, max_seq]. Count + * them as well to ensure reclaim makes progress. + */ + for (seq = 0; seq < MAX_NR_GENS; seq++) nr[type] += lruvec_gen_size(lrugen, type, seq, max_zone); } } -- 2.39.3 (Apple Git-146)