From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mta0.migadu.com (out-14.mta0.migadu.com [91.218.175.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9E1914582F9 for ; Thu, 13 Aug 2026 11:02:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.14 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786618979; cv=none; b=k8VQQq3Zb1IhuCtBPQoJ+aTfxTR45gzlJij/dkN1LApAn7u7gZJhNdw7yKH40GRY/9QydxGyw/CBIfCH29S6UkQNpwYQ+koVB8tnWqp3CmamUGGGoR9HeQ5OQSqKlX91NibB9PTzIKztew0NBdPbmmU/fl+pQyJjqeay8pm4ZkI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786618979; c=relaxed/simple; bh=BAQ2x49WKK6m/l7686oxL8J3T4FsLdlNjSgHTbGooA0=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=X43IeWQ95S2kuka9XHoUmifUUDZ6LCz16aGFg/z61YmUzUXpHUBcTgbBUa7mZJ2NA/svmUfMmnb767fEzwSB46ZsEDVYrxLKFWi0cS/0X4jgc9i+CuGcDs9FW4r0dxAJQRVllSZKEWTRbES10YYUtosL7G/JYuTwTJJbM9v272k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=ZZWvXL8N; arc=none smtp.client-ip=91.218.175.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="ZZWvXL8N" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=BAQ2x49WKK6m/l7686oxL8J3T4FsLdlNjSgHTbGooA0=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1786618971; v=1; x=1787223771; b=ZZWvXL8NvtQVzxmqZM57NS/JptxFUTQ/lPT2iT58d/Q4EMashGNdWszDLMFGKV6pVmPuGV83 znoFAA7LAOs70zz4mszdeeOzfxxF8oshvyDR9NTgI+jHqo95eikvuMXuE48pUa+OAv/oWkuAjo3 4zGW9EO+7K25l3jBKA6ytXwE= X-Envelope-To: linux-kernel@vger.kernel.org Received: from mi-ThinkCentre-M760t.mioffice.cn (14.29.108.92) by smtp.migadu.com with ESMTPS id 9316e55c22f732f8; Thu, 13 Aug 2026 11:02:51 +0000 X-Migadu-Flow: FLOW_OUT From: Ridong Chen To: Andrew Morton , Johannes Weiner Cc: David Hildenbrand , Michal Hocko , Qi Zheng , Shakeel Butt , Lorenzo Stoakes , Kairui Song , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Brian Geffon , "Jan Alexander Steffens (heftig)" , Steven Barrett , Yu Zhao , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Ridong Chen , Ridong Chen Subject: [RFC PATCH] mm/mglru: preserve inactive placement when enabling MGLRU Date: Thu, 13 Aug 2026 19:02:30 +0800 Message-Id: <20260813110230.2124785-1-ridong.chen@linux.dev> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Ridong Chen When the LRU is switched to MGLRU (echo y > /sys/kernel/mm/lru_gen/ enabled), fill_evictable() re-inserts every folio via lru_gen_add_folio(..., false). With reclaiming hardcoded to false, an inactive anonymous folio (no PG_active, not in the swapcache) takes the "gen = MIN_NR_GENS" branch in lru_gen_folio_seq() and is seeded at seq = max_seq - 1, which lru_gen_is_active() treats as active. Its inactive placement is lost and NR_INACTIVE_ANON is folded into NR_ACTIVE_ANON. Pass reclaiming=!active so a folio from an inactive list is seeded into an older generation. Folios from the active list carry PG_active and hit the first branch either way, so they are unchanged. Tested on x86_64, next-20260812, 2G VM + 1G swap, ~1.5G anon pushed onto the inactive list before enabling MGLRU: Active(anon) Inactive(anon) before switch (legacy) 2952 1548792 kB after `echo y`, unpatched 1552052 0 kB after `echo y`, patched 15144 1536636 kB Inactive file folios stay inactive either way (NR_INACTIVE_FILE is preserved). Fixes: 354ed5974429 ("mm: multi-gen LRU: kill switch") Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Ridong Chen --- mm/vmscan.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 94fc4f25e99f..2befc8d7dd3f 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -5319,7 +5319,12 @@ static bool fill_evictable(struct lruvec *lruvec) VM_WARN_ON_ONCE_FOLIO(folio_lru_gen(folio) != -1, folio); lruvec_del_folio(lruvec, folio); - success = lru_gen_add_folio(lruvec, folio, false); + /* + * Keep a folio from the inactive list inactive: + * pass reclaiming=!active so it is not seeded as + * active. See lru_gen_folio_seq(). + */ + success = lru_gen_add_folio(lruvec, folio, !active); VM_WARN_ON_ONCE(!success); if (!--remaining) -- 2.34.1