From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796156392; b=3xNfNqzxt8xe6kvWpIudsuq7bkxBcwUJc4oPqoSBzdZqC+lOmUDFMeuCT3FvH3ewVETF Mmm6i5UQ91MRGi4yc+AvVloiiYHZ3tNTKESl9gTD3y2eqtTcY+QuS1AupGtqxYRELkPbS VmgrITlVWNWNENVm7KrxMBUsH4OIp/bF8OnsJ5kJD1ApyAuilaWhfojQNtqHK9KO5PM+8 3+3FHaMqN5YlYL1fgjwncgkkVeaJKyAYAEMAM/UDLcKPiDa5Ir9AfkGQjZfsga0wuMCX9 ifzC2aThOUF//BE+Faqmg1MeJ5yI2Ayas9qKOLlCc21g1G2FPtcC36S0oJ8yZWwH1hA== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796156392; h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=8QMm67cj3sP5JDq6M6x8zQ2a1XbA3Fi0yuEQ1niugII=; b=h7QZTh/kU0ane0pvswcOCp+zpnJs6ceSuHJPO7QzGlJWNFBMxNGlBqsEiYultW16fQ6O sxN0/RDc7LPTMMjnyQKiWxNrLyQiG3psBEVmsNzmF25L6iFx6b8saNb5e5xw8L2QOksW8 ceZmvXCvbef/+Ei0vzFyMr7dc4TISG6zyCdWxXkrKsTmfPYtLa4e1TGE1TiW8cKikCnc2 0QUl4WH2GXhJEqrVhqRgTmq5uNk6mSsOiDZ4+sd+Mn7KOJLUWzUm8PjqLBalUbsQ5D1m2 ZC8YNiYeo8/s5tJeL3UB0N28C+0BAcFu8eAIn7uGHmZWi8G7XXnwumf68P2455dyHng== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=oeInUM10; arc=pass header.oldest-pass=0 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 98BD6606A68E; Tue, 1 Dec 2026 20:19:52 +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=oeInUM10 Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1796156392; b=qxOkE5pYSY/wF7lGpdpUQwmrlY6kMFglgsuKC9dscvlsn5jTiA3xOpfKfBzuqaotlZhu w31Qq0pswnUGSpNRwHlk3Iky0O6/OcLWcU+pEEh5W5SbGeqWPYJQlVsbiCZiQKhiWV6bT DyriOq0jkonr07+NusZK2b6afPTJTVZx1wLohUVb/iocXb3sr8w5KSpWwk8yHB7DqOy2u BBZMGMiG3Zgrhv3uliq+rxtqPredNNkgHomVe0nwphEDiEqvfUDo6cuAHuqLc0jR8JZw9 u9ojyNpNg5WIyqft1iB8+MMHOii3KCrNd9P/tTlrepCRPJvZ7yLra9NFyfG3c49GXwg== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796156392; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=8QMm67cj3sP5JDq6M6x8zQ2a1XbA3Fi0yuEQ1niugII=; b=3vMQUENfsXdxBPCXQ44hP7B3ONyzzVycssBHTcaTO0jcXo0wLCNCLzPMnAOBSSU1fwIg 5btFzxTucJqVeo7ReQOR5O6zu2YHNS4opjjDUhUtIWWu1zKM4yeFAKX5LKqLacu3jegG8 B5H44fOZ3RLB0NeoQLKU3fVsGzCbNtNtgfKxHk3Nf8HB2AjqZwRZgnsB7ygkTsbVuGt31 9HlFd3mNIk3pGv7uytnwu6Mrz9k1ImH4gGXCIZcZ3+mJUwGiUQi+M9fq6c4rYL9Pc/QRe pvfgL4tyRzmUEKJtC/eSuGwqJhTfUbSE9/jRdY0bNfqyq7jxyBNtaZFxRNuOcXU7RAQ== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id CE1981F00893; Tue, 1 Dec 2026 20:19:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796156392; bh=8QMm67cj3sP5JDq6M6x8zQ2a1XbA3Fi0yuEQ1niugII=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To; b=oeInUM10mW6pfYnyHyt1WT/CCoMFeC+hNFQzWR63gACi4GFaVYmDiOgjj13QPsvoA XTmb6bMtB9VU4vUcI8DiLfKGU4o9SfDgtKUCbFAyAoOdfsJJRsYoaasDuSMLMS8eDZ XejiqA7vAYAyunikpm7BOgIIAkFQMZxYjo9OJjXaGSr3RdquvD+/jie/AJYqFX625U 8ErfZhMNR7vOYfObjxHVA3uzickZ5mBbLz3fte9hJQQB0wQsDkMpC8plFcrTitl/EK 0rHWkSwnmqsM9cDE4heTdH2pqvdmkByoZHIrqS6tW4ZvBdrw8KqtzbxMwipvIhHE8s a5i6IN5LUoJuA== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id 476B94F0C7; Tue, 1 Dec 2026 20:19:22 +0000 (UTC) From: Kairui Song via B4 Relay Date: Wed, 02 Dec 2026 04:18:53 +0800 Subject: [PATCH v7 13/19] mm/khugepaged: convert to LRU refs based operations for MGLRU 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-Type: text/plain; charset="utf-8" Message-Id: <20261202-mglru-fg-v7-13-5965a96d86d0@tencent.com> References: <20261202-mglru-fg-v7-0-5965a96d86d0@tencent.com> In-Reply-To: <20261202-mglru-fg-v7-0-5965a96d86d0@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 , "Liam R. Howlett" , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Vlastimil Babka , Suren Baghdasaryan , Nhat Pham , Youngjun Park , Zi Yan , Gregory Price , "Matthew Wilcox (Oracle)" , Baolin Wang , Ryan Roberts , Dev Jain , Lance Yang , Hugh Dickins , SJ Park , David Rientjes , Yu Zhao , Vernon Yang , Zicheng Wang , Tal Zussman , Kairui Song , Xiang Liu , Ehab Ababneh , Zhao Zhenzhuo , Lian Wang , Joanne Koong , Kunwu Chan , Hui Zhu , Maxim Muzafarov , Tianyi Chen , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, damon@lists.linux.dev, linux-doc@vger.kernel.org, Kairui Song , Ridong Chen X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796156357; l=1412; i=kasong@tencent.com; s=kasong-sign-tencent; h=from:subject:message-id; bh=gU/D6GGKgw0HJudinBxMjKx8b2iv1hFOPQdV7odkssE=; b=D8GPC/hEIsdb1GX9+1OtQs0W217wjVdLQBOWDd3Xh/Oxxktrinu04l/Y2iCO3RjUSyWY3nXIc mEBdM/7KMpKD06qPJ34TTMozKgUh5/xxm1j+I94WZ8kOwyBx3Rd5aKM 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 Content-Transfer-Encoding: 7bit From: Kairui Song For MGLRU, PG_referenced is only the lowest bit of the folio LRU refs count, so folios with nonzero even refs no longer have the bit set. folio_pte_referenced() testing the raw bit misses hot folios at refs 2, 4 or 6, 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 with folio_test_lru_refs(), which also covers PG_young. The classical LRU keeps the plain bit test. Tested-by: Zhao Zhenzhuo Reviewed-by: Kunwu Chan Tested-by: Andrew Morton Signed-off-by: Kairui Song --- mm/khugepaged.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index c27c967d3b66..9fdbf2f148e2 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -579,7 +579,7 @@ 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_lru_refs(folio)) return true; /* ... or the PTE mapping was recently used */ return pte_young(pteval) || mmu_notifier_test_young(vma->vm_mm, addr); -- 2.56.1