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 529503E8695 for ; Wed, 12 Aug 2026 12:18:32 +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=1786537113; cv=none; b=KbHGpQ/b0CNPYETsWd1iZwX1dlzFAlQuPHTa+vMOVpWTymhFdeoNBdvgZoITnOC8Aa8MF2xjtMAtS6tqkr7v+9lXNhzPewmTSk2C/UQEIAktJaIyWAXTNDvsgIasQ1/QEPnJBghCL/AdnmHa8eo5lZjyacb7ez9EPnl7ffUb650= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786537113; c=relaxed/simple; bh=btWGq5vav8v0MNojsl686lGB1R9KU1D7U8gq75kk7yA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mlCHVHuQz1JfiYsGWcOlN78GLU0eNaeygoMwRxVeDxzUoxB/QB2ieA67qJ8IoBHkfCqNC67dnDl5eAlQAzCE8+WgPKo2CCL9wEbFmPZA0nOCANhT+OBiINI825h7b4hd0IjwzgreDllmtWvyGYxMJvB7GbRSPmYfa9B3z+wWwCI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=enrNi23S; 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="enrNi23S" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 91F591F00A3A; Wed, 12 Aug 2026 12:18:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1786537112; bh=sjn66HBL5BcMiFsq1jE87/70ep2gVw0orOdl941ZWGU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=enrNi23SNkmgjfzNIYWqLPhi43g/P7K8nbDsnMcP+6+uxoBixq/bV9gVYeWsuyguJ ppEnvFW69IqTOvOvfr1omUrs8ZeVdrDQFUzGNtX1JEdD11iCbix4vid3E5446+lStn nMlgghr4dI694h/VFrm26NTY1WdEkPAwF96QzLq41P+KSnUZSWymwWa7ylOM8sGEEM E2OKPZstuIotUFg8CmJgeGVVU7VFD6AFnjdktFo6Mpm6r3JtD7rSrBY8H7wFigegAp vbA9TNxxTriMqfC3Io7VCrSUgCT2v2Yreq+8oXqlRgOaNsJ+Ji/HLuO1JjWWCSpWd8 uNt/QOqywdcHA== From: "Barry Song (Xiaomi)" To: akpm@linux-foundation.org, linux-mm@kvack.org Cc: axelrasmussen@google.com, 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, baolin.wang@linux.alibaba.com, baoquan.he@linux.dev, "Barry Song (Xiaomi)" Subject: [RFC PATCH v4 07/16] mm/mglru: enhance cold/hot inversion handling in inc_min_seq() Date: Wed, 12 Aug 2026 20:16:49 +0800 Message-Id: <20260812121658.69965-8-baohua@kernel.org> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20260812121658.69965-1-baohua@kernel.org> References: <20260812121658.69965-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 10f690389f5d..e0625e6ec919 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -3945,9 +3945,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