From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 5DBC247ACF5 for ; Fri, 21 Aug 2026 10:26:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787308003; cv=none; b=khj04yGbRI5LELkw4UPcfvBl8iu4Hx+OX2a6AGbmF2GdxXs+RBq+adDsdo8K0yK/CZ3g2il7wch5eu7U7hywBfhaWnP1rs/Odwcu78F2YH4czB0d9q12YVNEQ22F2dI7Qefc1kkZniD9+bvNVzMn0w/kxEIiDEM6Q2tsbbyGpOQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787308003; c=relaxed/simple; bh=p/ohgA6OKdZ3L9ESB2t92Vdoor9GmobZwSb6/RnlTjI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=n4bow4oxhXzFe5LkEgcL8ZXJV38MId/yFX3FCBNJHUhvsChyhuEVyPtxSHp7SSI2J0YOTGHO7MFhHVuDYUQVmUQVYLTJuOc7pRqTprpBspGcLJpEZeaMSa/lVgS6r+MT38bG4oFGoWN9CHGazkfrtmexmNQfnFiiFx8vdQtw89Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nDycVO7I; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="nDycVO7I" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A7F6D1F000E9; Fri, 21 Aug 2026 10:26:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1787307990; bh=Sbrxf+PZdylQ4e8d9YhboPwelpbW3kiqOe9jSbLC3Yk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=nDycVO7Itn7ToZ1y7L33bMcoxz+OF5wNBXiEGMXhkR76hWR+pKRjmDM0iU7wa86b4 +GKnyADWlZ7KUaMSVIlHVhN0aQzb7icUPIrqfTI+tPmfZxzeKt3h5veI0og0/zLI7T K2ablnl4jxHm9M6ioeVn6xWugVgamr7FA2qSURfM5S+ORIXa8dLF/ll9Cw1/zD1N7L AeFZ+fmRcC/VXCpTBQGlbp7T0LT1tlccbdV1P8bN/Z7hLe6BSW/U/F4wD9JTjlOZyR vTYPyZVbKuZMFcb966DQydno5oE9RgHF5Iz0bndfIjG2Z11XY1uQKAv0O+BmzSohsV U8rQmdW1++isw== From: "Barry Song (Xiaomi)" To: akpm@linux-foundation.org, linux-mm@kvack.org Cc: axelrasmussen@google.com, baolin.wang@linux.alibaba.com, baoquan.he@linux.dev, chenridong@xiaomi.com, david@kernel.org, hannes@cmpxchg.org, kasong@tencent.com, lianux.mm@gmail.com, linux-kernel@vger.kernel.org, ljs@kernel.org, lyugaofei@xiaomi.com, mhocko@kernel.org, qi.zheng@linux.dev, shakeel.butt@linux.dev, stevensd@chromium.org, wangzicheng@honor.com, weixugc@google.com, yuanchu@google.com, zhangbo56@xiaomi.com, "Barry Song (Xiaomi)" Subject: [PATCH 3/6] mm/mglru: enhance cold/hot inversion handling in inc_min_seq() Date: Fri, 21 Aug 2026 18:25:35 +0800 Message-Id: <20260821102538.22642-4-baohua@kernel.org> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20260821102538.22642-1-baohua@kernel.org> References: <20260821102538.22642-1-baohua@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit During aging, a folio's generation may already have been updated by folio_update_gen(), even though it has not yet been moved to the corresponding generation list. Such folios are hotter than those already in that generation. It makes sense for inc_min_seq() to increment the generation of folios that were never promoted during aging and move them to the tail of the new oldest generation. However, folios that were already promoted should instead be moved to the head of their updated generation, just as sort_folio() does in scan_folios(). Otherwise, promoted folios could end up behind folios that were never promoted, effectively inverting their hot/cold ordering. Signed-off-by: Barry Song (Xiaomi) --- mm/vmscan.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 99ee3c833d54..3b618a51cde2 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -3946,9 +3946,12 @@ static bool inc_min_seq(struct lruvec *lruvec, int type, int swappiness) VM_WARN_ON_ONCE_FOLIO(folio_zonenum(folio) != zone, folio); new_gen = __folio_inc_gen(folio, old_gen, &gen_increased); - list_move_tail(&folio->lru, &lrugen->folios[new_gen][type][zone]); - if (gen_increased) + if (gen_increased) { delta += nr_pages; + list_move_tail(&folio->lru, &lrugen->folios[new_gen][type][zone]); + } else { + list_move(&folio->lru, &lrugen->folios[new_gen][type][zone]); + } /* don't count the workingset being lazily promoted */ if (refs + workingset != BIT(LRU_REFS_WIDTH) + 1) { int tier = lru_tier_from_refs(refs, workingset); -- 2.34.1