From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-176.mta1.migadu.com (out-176.mta1.migadu.com [95.215.58.176]) (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 094882F7EFE for ; Wed, 12 Aug 2026 07:00:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786518034; cv=none; b=aEOKbKWqNAKmqxsSNk38DtsPGscwuNJLd/gh7xNQNOXSVwzntAimK99hCVizwBF3o69icJBrYapf22Z9/lf9OV1PmQZqorJx7hPivlvdpP28u1O5wDVEFPQ1gsOwwsZpYx9fo55moTmL2t+SQIhCR93xUmn2oBUHbGFetE4N8zM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786518034; c=relaxed/simple; bh=ql+egaC6QNr4J8786SN0trEq2yv3K3GJc4xPirQiShg=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=ltmalG/kHS8FyvXQRRuPlwC768Ogrr+34SMrZW/Ih1yBQAoW5LnX7metC/m5006ADZmUVhXPUDbw/18eNk7zFHCXlOGLIBcvrS4cEqzJ7bVNlKiagnYSDQ+TbvJg5Ttk7TiHw8+YO1RKdYWoIpwSJxuhC3mXcsnO5Vw32B+Jmjs= 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=L8J0CWWY; arc=none smtp.client-ip=95.215.58.176 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="L8J0CWWY" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1786518029; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=54WVphyLueCZiaN46FTY/NZ/+uFXJ7ELUaT5/RiQtLE=; b=L8J0CWWYuEMMUK59Y0tpYq+M46FrVhvUdtaJtPLDo+KIlhAEWW8vdoLrt7YCdKQQHv6ZSD WeSR1gqK1r0kyVORuJgfxshVPMhLFORDIV5sn78858/5T/PpN5/eE3qBI+jYU7G1iKQJJD OUleuhVK7XM3mbebQsXjXMNAeZYzgOs= From: "Hui Zhu" To: Andrew Morton , Johannes Weiner , David Hildenbrand , Michal Hocko , Qi Zheng , Shakeel Butt , Lorenzo Stoakes , Kairui Song , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Hui Zhu Subject: [PATCH] mm/mglru: Fix young counter undercount for large folios Date: Wed, 12 Aug 2026 14:59:33 +0800 Message-ID: <20260812065933.103627-1-hui.zhu@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT From: Hui Zhu In lru_gen_look_around(), the young counter tracks the number of young PTEs. The original folio's contribution is represented by the initial value of young: test_and_clear_young_ptes_notify() is called on it at function entry, and the function returns early if it is not young. In the subsequent loop, the original folio is skipped (its accessed bits were already cleared), so it is not double-counted. However, young is initialized to 1 regardless of the folio size. When the original folio is a large folio with nr PTEs, its young count is underestimated by nr - 1. This inconsistency can cause suitable_to_scan() to return false, preventing the PMD from being added to the bloom filter and reducing aging accuracy for mTHP workloads. Initialize young to nr so the original folio is accounted the same way as other young folios in the loop (young += nr). Signed-off-by: Hui Zhu --- mm/vmscan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index bc324e37c5f1..264017850a55 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -4192,7 +4192,7 @@ bool lru_gen_look_around(struct page_vma_mapped_walk *pvmw, unsigned int nr) unsigned long end; struct lru_gen_mm_walk *walk; struct folio *last = NULL; - int young = 1; + int young = nr; pte_t *pte = pvmw->pte; unsigned long addr = pvmw->address; struct vm_area_struct *vma = pvmw->vma; -- 2.53.0