From mboxrd@z Thu Jan 1 00:00:00 1970 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 BAB0B432BFE; Sat, 3 Oct 2026 12:55:18 +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=1791032118; cv=none; b=kl7z8RkupaqQp+WVXWFiXS6uSODxWIixkpjRK6sPNHcKJRAQ0VNSCiSnpE6qW6vKjrNJ27sdrIe26KixRDdjObMVSZ7s7Io9egA803pywZASB9Y4SoyCFhf6AN1de3JRLM/E6Jh83H5wnvn06wtwyWPWcXViOcoxxK07gPm4bD8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791032118; c=relaxed/simple; bh=rHvF9nUiy0njARXgH/Cp/T1z5jM2U29y/ktedodrPE0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=VHkBPWRvXZmXSS+yEha7Lb8qLWVJK4IMKqZV9aXCiFww4KS3KUr8Q8t6DUKYVgTdsGE9kbGfBsQHhti5uvFHHV1TXaCfcz5UyVjncPN75B/ifjd5Cs5MMP6IUyrFX8AkZob6gPxqiorwMpt9TDJ67K8QsicN91zxXLlfxdOmrq0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Yxg6pmAB; 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="Yxg6pmAB" Received: by smtp.kernel.org (Postfix) with ESMTPS id 95F16C4AF13; Sat, 3 Oct 2026 12:55:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1791032118; bh=rHvF9nUiy0njARXgH/Cp/T1z5jM2U29y/ktedodrPE0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=Yxg6pmABxZJerVBwzDLhodUC1Hn0wRwiS+kh8skxZIezZ51kHsBh3JZ74O72WCVgF Xf0tV6VHmN1Wnqy0+HR+q8Ori7LD3MG8nM+zltPfr6ILRtwkqBLj1bvYFLGJSb7ExX ODQj/kk1AQylcNkeNbWPCLEaZaJYy7nVL7UCN0Z3jyJrIwmRCjoPw3s47j5xR9QAlf lWTcEv3zs9tUyQYFIGERMe1UPz9x32lvIJL2i3JcTN3rD9BKgBIenzX5kwkbC4XzR2 8Mau1dIXGoE4SGG6ag9ZhYjMaQCMn14leyFzxPath5tLSEFz+b0A1uknSKKpvtzEo/ PW6owksbR+vXw== 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 7F9E5CA5FDD; Sat, 3 Oct 2026 12:55:18 +0000 (UTC) From: Kairui Song via B4 Relay Date: Sat, 03 Oct 2026 20:55:26 +0800 Subject: [PATCH RFC v3 15/17] mm/khugepaged: check folio referenced state via LRU refs under MGLRU 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: 7bit Message-Id: <20261003-mglru-fg-v3-15-cbd4546a5bd9@tencent.com> References: <20261003-mglru-fg-v3-0-cbd4546a5bd9@tencent.com> In-Reply-To: <20261003-mglru-fg-v3-0-cbd4546a5bd9@tencent.com> To: linux-mm@kvack.org Cc: Andrew Morton , Johannes Weiner , Muchun Song , Qi Zheng , Ying Huang , Chris Li , Baoquan He , Nico Pache , Usama Arif , Michal Hocko , Roman Gushchin , Shakeel Butt , David Hildenbrand , Lorenzo Stoakes , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Vlastimil Babka , Suren Baghdasaryan , Kemeng Shi , Nhat Pham , Youngjun Park , Zi Yan , Gregory Price , "Matthew Wilcox (Oracle)" , Baolin Wang , Ryan Roberts , Dev Jain , Lance Yang , Hugh Dickins , SeongJae Park , David Rientjes , Yu Zhao , Vernon Yang , Zicheng Wang , Chen Ridong , Tal Zussman , Kairui Song , Xiang Liu , Ehab Ababneh , zhaozhengzhuo , Lian Wang , Kunwu Chan , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, Kairui Song X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1791032114; l=1294; i=kasong@tencent.com; s=kasong-sign-tencent; h=from:subject:message-id; bh=34PwfKs9OBNdti/LpG7ACAK3kbx7iRvKh8mLMU2xWsQ=; b=V+2o5HJsg+eqUnnEKRTFJ8z0QmeRB4cs9huLBv4bXJmW+rvOy4ITmRSAP24ty5RlHuLxsf6rS Ixh0ujwFDAsAhI/P/mDhVvz0fCOCZPS9A6O3HAmJmWynqnNdRQEoK6r 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 For MGLRU, PG_referenced is only the lowest bit of the folio LRU refs count, so folios with a higher refs count no longer have the bit set. folio_pte_referenced() testing the raw bit misses hot folios at refs >= 2, under-counting the referenced folios of a candidate range and aborting otherwise good collapses with SCAN_LACK_REFERENCED_PAGE. Test the refs count directly when MGLRU is enabled, mirroring the smaps conversion. The classical LRU keeps the plain bit test. Signed-off-by: Kairui Song --- mm/khugepaged.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 913086eaf17b..be18381c6efd 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -586,7 +586,9 @@ static bool folio_pte_referenced(struct folio *folio, struct vm_area_struct *vma, unsigned long addr, pte_t pteval) { /* The folio was referenced previously ... */ - if (folio_test_young(folio) || folio_test_referenced(folio)) + if (folio_test_young(folio)) + return true; + if (lru_gen_enabled() ? folio_lru_refs(folio) : folio_test_referenced(folio)) return true; /* ... or the PTE mapping was recently used */ return pte_young(pteval) || mmu_notifier_test_young(vma->vm_mm, addr); -- 2.55.0