From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mta1.migadu.com (out-120.mta1.migadu.com [95.215.58.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ED0B445FFD9 for ; Mon, 24 Aug 2026 16:27:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.120 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787588850; cv=none; b=MAWE9SS8QjYCqpw/VL+K9N4qKxGDDx/o+caFu4bYeI3uenMyzyxlI78E6fL22L3cUCbGDXxJ+OItke+3MNOPFUIzIn0R10+N6Kw49O09rW5PqmTCsHt4Q3Cz8Vp+Q3SBTeqyEoy8SDxB8yndmyVTMiq0ECRIRJb5pJdfjFEPSjU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787588850; c=relaxed/simple; bh=sprgsfzrs/7IhK9Lar1M59wV3GF+sASkTuKp0ItDHos=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=KLZlcVkHS+grkNjDtponlUIVsqwgalr3OTERQUF61OaYnccbE0ppZ62yDv9S89yEwcaE3m9etMlIXwQxHHskHlXkS5y/K+2sO6eOuG/L8rh5uz9WgrM52uL+yN3Mo2ovBAU7bDVovFLqJCqe21h9l9X7g+om1Cj+Ueme4s7xEfs= 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=dOsKaojr; arc=none smtp.client-ip=95.215.58.120 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="dOsKaojr" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=sprgsfzrs/7IhK9Lar1M59wV3GF+sASkTuKp0ItDHos=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1787588845; v=1; x=1788193645; b=dOsKaojrklmYM9mbcjvaMl5yKgdNfIHXL3ALW/3JyCeMyNU83YJOZ3VtkRLOWkwI3v2WvEP+ /1sRNGP9DSKKMvu4BedGUFEd+5z+FCLapRUBQNg0eVqyz+87pHhnW5inQYpAR+k6z2Jwk81CSOw M52gVHrLTvnYOwy3k0uwebdk= X-Envelope-To: linux-kernel@vger.kernel.org Received: from [IPV6:2601:282:1e00:c920::a061] (2601:282:1e00:c920::a061) by smtp.migadu.com with ESMTPS id ba7b8166db5dd483; Mon, 24 Aug 2026 16:27:25 +0000 X-Mizu-Trace-ID: ba7b8166db5dd483 X-Migadu-Flow: FLOW_OUT Message-ID: <9038f552-926b-4c4c-b023-69271f45e3d5@linux.dev> Date: Mon, 24 Aug 2026 10:27:20 -0600 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 2/7] mm/khugepaged: extract reference check into folio_pte_referenced() helper To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Andrew Morton Cc: David Hildenbrand , Lorenzo Stoakes , Zi Yan , Baolin Wang , "Liam R. Howlett" , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Usama Arif , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Jonathan Corbet , Shuah Khan References: <20260811-khugepaged_pte_refactor-v4-0-ddac39d61c4a@linux.dev> <20260811-khugepaged_pte_refactor-v4-2-ddac39d61c4a@linux.dev> Content-Language: en-US, en-ZM From: "Nico Pache (Red Hat)" In-Reply-To: <20260811-khugepaged_pte_refactor-v4-2-ddac39d61c4a@linux.dev> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 8/11/26 6:48 AM, Nico Pache (Red Hat) wrote: > This change deduplicates the "is this PTE/folio referenced enough to be > considered for a collapse" condition that was repeated in both > __collapse_huge_page_isolate() and collapse_scan_pmd(), extracting it into > a single inline helper function. > > Also move the comment and use it as the function header. While we are at > it, updated the comment to clarify that a young pte is a recently accessed > one. > > Acked-by: Usama Arif > Signed-off-by: Nico Pache (Red Hat) > --- Hi Andrew, Can you please append the following fixup! Thank you :) commit 20fa354b27d9be91e12c3c3144f6b3d8d38542f3 Author: Nico Pache (Red Hat) Date: Fri Aug 21 04:27:18 2026 -0600 fixup! mm/khugepaged: extract reference check into folio_pte_referenced() helper Drop the trivial helper kerneldoc and inline marker per review. Signed-off-by: Nico Pache (Red Hat) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 8babd4c97db6..34654d1c1259 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -672,13 +672,7 @@ static void release_pte_pages(pte_t *pte, pte_t *_pte, } } -/* - * folio_pte_referenced() - Check if a folio or its PTE mapping was recently used - * - * Return: true if recent access was observed through either the folio state - * or the current PTE mapping. - */ -static inline bool folio_pte_referenced(struct folio *folio, +static bool folio_pte_referenced(struct folio *folio, struct vm_area_struct *vma, unsigned long addr, pte_t pteval) { /* The folio was referenced previously ... */ > mm/khugepaged.c | 32 ++++++++++++++++++-------------- > 1 file changed, 18 insertions(+), 14 deletions(-) > > diff --git a/mm/khugepaged.c b/mm/khugepaged.c > index 1e26ea97381a..8babd4c97db6 100644 > --- a/mm/khugepaged.c > +++ b/mm/khugepaged.c > @@ -672,6 +672,22 @@ static void release_pte_pages(pte_t *pte, pte_t *_pte, > } > } > > +/* > + * folio_pte_referenced() - Check if a folio or its PTE mapping was recently used > + * > + * Return: true if recent access was observed through either the folio state > + * or the current PTE mapping. > + */ > +static inline 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)) > + return true; > + /* ... or the PTE mapping was recently used */ > + return pte_young(pteval) || mmu_notifier_test_young(vma->vm_mm, addr); > +} > + > static enum scan_result __collapse_huge_page_isolate(struct vm_area_struct *vma, > unsigned long start_addr, pte_t *pte, struct collapse_control *cc, > unsigned int order, struct list_head *compound_pagelist) > @@ -810,14 +826,8 @@ static enum scan_result __collapse_huge_page_isolate(struct vm_area_struct *vma, > if (folio_test_large(folio)) > list_add_tail(&folio->lru, compound_pagelist); > next: > - /* > - * If collapse was initiated by khugepaged, check that there is > - * enough young pte to justify collapsing the page > - */ > if (cc->is_khugepaged && > - (pte_young(pteval) || folio_test_young(folio) || > - folio_test_referenced(folio) || > - mmu_notifier_test_young(vma->vm_mm, addr))) > + folio_pte_referenced(folio, vma, addr, pteval)) > referenced++; > } > > @@ -1766,14 +1776,8 @@ static enum scan_result collapse_scan_pmd(struct mm_struct *mm, > goto out_unmap; > } > > - /* > - * If collapse was initiated by khugepaged, check that there is > - * enough young pte to justify collapsing the page > - */ > if (cc->is_khugepaged && > - (pte_young(pteval) || folio_test_young(folio) || > - folio_test_referenced(folio) || > - mmu_notifier_test_young(vma->vm_mm, addr))) > + folio_pte_referenced(folio, vma, addr, pteval)) > referenced++; > } > if (cc->is_khugepaged && >