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 708A51E3DFE for ; Sat, 13 Sep 2025 18:59:15 +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=1757789955; cv=none; b=ZimiVz6ru0SU1OPSAoT8eNmkrBVthSMs3CvltzTj+CByo9oSKDzdD0FX8qKlJudiBRcBNERa3JO7rtUFdLWGTmnLvRyc+QH3QEa0UpzElUf5FJaO4lJP/7fYjPGD/PZOMszc9HAJtRE0b85DAJSteaq/r4GpHRXx7vuny287k5Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757789955; c=relaxed/simple; bh=GoNbj/YRMK954xHzo03UXCeqaV2O7noarkYGCQA6mX0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Or777acT9d2Jki9bk1j44Ur1nsP0ssfJZiNne3ECDAjkbUJ00RUOxL4dC3KkV5Muob2tirwj68DDCCnJmymXiXLWXvsNHdEJUOUbpWk9MiD1cE5E59mLALO3P7wyVqU1wMK0Kij7u/KySM7FnnKPGdUY2HUOJGWR3/XIhPD4dsw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BpuVayd2; 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="BpuVayd2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 13D3EC4CEEB; Sat, 13 Sep 2025 18:59:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1757789955; bh=GoNbj/YRMK954xHzo03UXCeqaV2O7noarkYGCQA6mX0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BpuVayd23ry9qtmk3QE1s5SXvjJncNxjxvLZ7b0uR+d/4egAUYUCo/Y+knCBbrOKm 0OP+6EsJJozC4jnGFdWpDaHiNxnd9XtQB4AA+Psm1GI1AUAbOmEndkkT1Gpuly3A8g Lih2SK1+3SCZ+RpmCVW6ZdrDppHJqCwHcW4F6SdV2AJfGyki6NxyQjMa3rQRbMGmls If0hazWCh0J7JOE5q5KOAZePofYwpBZCZnTQMlEuj5/Mfo52mL98Uc11DS+KEABNcP kJk80Tvwvv2IhIjLEZ1TNUgnu0nPUzBmE5ppiEo70hU7tbBs0bsqfNclqum0m8Ecwz B8EK1l/IenIGg== From: Sasha Levin To: stable@vger.kernel.org Cc: "Vishal Moola (Oracle)" , Rik van Riel , Yang Shi , Kefeng Wang , "Matthew Wilcox (Oracle)" , Andrew Morton , Sasha Levin Subject: [PATCH 6.6.y 1/2] mm/khugepaged: convert hpage_collapse_scan_pmd() to use folios Date: Sat, 13 Sep 2025 14:59:11 -0400 Message-ID: <20250913185912.1514325-1-sashal@kernel.org> X-Mailer: git-send-email 2.51.0 In-Reply-To: <2025091344-purist-tattle-13ba@gregkh> References: <2025091344-purist-tattle-13ba@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: "Vishal Moola (Oracle)" [ Upstream commit 5c07ebb372d66423e508ecfb8e00324f8797f072 ] Replaces 5 calls to compound_head(), and removes 1385 bytes of kernel text. Link: https://lkml.kernel.org/r/20231020183331.10770-3-vishal.moola@gmail.com Signed-off-by: Vishal Moola (Oracle) Reviewed-by: Rik van Riel Reviewed-by: Yang Shi Cc: Kefeng Wang Cc: Matthew Wilcox (Oracle) Signed-off-by: Andrew Morton Stable-dep-of: 394bfac1c7f7 ("mm/khugepaged: fix the address passed to notifier on testing young") Signed-off-by: Sasha Levin --- mm/khugepaged.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index f227b39ae4cf7..63e268c61e827 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1240,6 +1240,7 @@ static int hpage_collapse_scan_pmd(struct mm_struct *mm, int result = SCAN_FAIL, referenced = 0; int none_or_zero = 0, shared = 0; struct page *page = NULL; + struct folio *folio = NULL; unsigned long _address; spinlock_t *ptl; int node = NUMA_NO_NODE, unmapped = 0; @@ -1326,29 +1327,28 @@ static int hpage_collapse_scan_pmd(struct mm_struct *mm, } } - page = compound_head(page); - + folio = page_folio(page); /* * Record which node the original page is from and save this * information to cc->node_load[]. * Khugepaged will allocate hugepage from the node has the max * hit record. */ - node = page_to_nid(page); + node = folio_nid(folio); if (hpage_collapse_scan_abort(node, cc)) { result = SCAN_SCAN_ABORT; goto out_unmap; } cc->node_load[node]++; - if (!PageLRU(page)) { + if (!folio_test_lru(folio)) { result = SCAN_PAGE_LRU; goto out_unmap; } - if (PageLocked(page)) { + if (folio_test_locked(folio)) { result = SCAN_PAGE_LOCK; goto out_unmap; } - if (!PageAnon(page)) { + if (!folio_test_anon(folio)) { result = SCAN_PAGE_ANON; goto out_unmap; } @@ -1363,7 +1363,7 @@ static int hpage_collapse_scan_pmd(struct mm_struct *mm, * has excessive GUP pins (i.e. 512). Anyway the same check * will be done again later the risk seems low. */ - if (!is_refcount_suitable(page)) { + if (!is_refcount_suitable(&folio->page)) { result = SCAN_PAGE_COUNT; goto out_unmap; } @@ -1373,8 +1373,8 @@ static int hpage_collapse_scan_pmd(struct mm_struct *mm, * enough young pte to justify collapsing the page */ if (cc->is_khugepaged && - (pte_young(pteval) || page_is_young(page) || - PageReferenced(page) || mmu_notifier_test_young(vma->vm_mm, + (pte_young(pteval) || folio_test_young(folio) || + folio_test_referenced(folio) || mmu_notifier_test_young(vma->vm_mm, address))) referenced++; } @@ -1396,7 +1396,7 @@ static int hpage_collapse_scan_pmd(struct mm_struct *mm, *mmap_locked = false; } out: - trace_mm_khugepaged_scan_pmd(mm, page, writable, referenced, + trace_mm_khugepaged_scan_pmd(mm, &folio->page, writable, referenced, none_or_zero, result, unmapped); return result; } -- 2.51.0