From nobody Sat Feb 7 08:44:03 2026 Received: from out30-119.freemail.mail.aliyun.com (out30-119.freemail.mail.aliyun.com [115.124.30.119]) (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 528AB2874F1 for ; Fri, 26 Dec 2025 06:08:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.119 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766729302; cv=none; b=ic/QVkZw5q1+8lJUJpPwa9MVQx7aSCII3lsbP4POd1CCQbusXqJuO8wyNgfQdEm5xBwxj1YXfQa654pAxIsqqX9lFx6cgfNhalyzIIHH71eETE2baA/ePgu48gSf4Ooka9PCzy9uRA5AR5apLY1cjB8m4mAfLH5Pg2j71mMCo20= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766729302; c=relaxed/simple; bh=wb/vmwZ8OqNUJSnCfeFr+JLuhkcDOf2u0hAfn0Hyvzw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=t9a10+WztXTfc0N4dddEDclojpFK1Ir+2U7d/iOVEXTGI7zS4l9o1iX/czIlyLvELAaS/6vHwVcULL5SbzZBiRp6eL4AmI3SL7VzSMLRX4On7ztHf10HKewpf8bHg8IVZDKvb/p8Z8aOJvlMN+rsbi/GlMPNVpb2p8yKtuLyFV4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=fnSEJEkW; arc=none smtp.client-ip=115.124.30.119 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="fnSEJEkW" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1766729292; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=BRmmCFNmICp36tUrVWzeWlSSPOKZXfw//kjlU0BodFE=; b=fnSEJEkWw5h+f66pC57ngHNPxxGquejHeF7ooGZzTvIgJbLMYr1hr66/jBH3hFrXbOdtv6+84Ix36+UbmgA6JeNCb0LZHl4NYqn7tCDTTDoznBMRBRA4IGaDrDmJQgHFtU1/yXiaRWPB9Wo9yw0y5RK6FHTJikYmpfZ5LXhJF88= Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0Wvgbcyw_1766729289 cluster:ay36) by smtp.aliyun-inc.com; Fri, 26 Dec 2025 14:08:10 +0800 From: Baolin Wang To: akpm@linux-foundation.org, david@kernel.org, catalin.marinas@arm.com, will@kernel.org Cc: lorenzo.stoakes@oracle.com, ryan.roberts@arm.com, Liam.Howlett@oracle.com, vbabka@suse.cz, rppt@kernel.org, surenb@google.com, mhocko@suse.com, riel@surriel.com, harry.yoo@oracle.com, jannh@google.com, willy@infradead.org, baohua@kernel.org, dev.jain@arm.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 3/5] arm64: mm: support batch clearing of the young flag for large folios Date: Fri, 26 Dec 2025 14:07:57 +0800 Message-ID: X-Mailer: git-send-email 2.47.3 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently, contpte_ptep_test_and_clear_young() and contpte_ptep_clear_flush= _young() only clear the young flag and flush TLBs for PTEs within the contiguous ran= ge. To support batch PTE operations for other sized large folios in the followi= ng patches, adding a new parameter to specify the number of PTEs that map cons= ecutive pages of the same large folio in a single VMA and a single page table. While we are at it, rename the functions to maintain consistency with other contpte_*() functions. Signed-off-by: Baolin Wang Reviewed-by: Ryan Roberts --- arch/arm64/include/asm/pgtable.h | 12 ++++++------ arch/arm64/mm/contpte.c | 33 ++++++++++++++++++-------------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgta= ble.h index 445e18e92221..5e9ff16146c3 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -1648,10 +1648,10 @@ extern void contpte_clear_full_ptes(struct mm_struc= t *mm, unsigned long addr, extern pte_t contpte_get_and_clear_full_ptes(struct mm_struct *mm, unsigned long addr, pte_t *ptep, unsigned int nr, int full); -extern int contpte_ptep_test_and_clear_young(struct vm_area_struct *vma, - unsigned long addr, pte_t *ptep); -extern int contpte_ptep_clear_flush_young(struct vm_area_struct *vma, - unsigned long addr, pte_t *ptep); +int contpte_test_and_clear_young_ptes(struct vm_area_struct *vma, + unsigned long addr, pte_t *ptep, unsigned int nr); +int contpte_clear_flush_young_ptes(struct vm_area_struct *vma, + unsigned long addr, pte_t *ptep, unsigned int nr); extern void contpte_wrprotect_ptes(struct mm_struct *mm, unsigned long add= r, pte_t *ptep, unsigned int nr); extern int contpte_ptep_set_access_flags(struct vm_area_struct *vma, @@ -1823,7 +1823,7 @@ static inline int ptep_test_and_clear_young(struct vm= _area_struct *vma, if (likely(!pte_valid_cont(orig_pte))) return __ptep_test_and_clear_young(vma, addr, ptep); =20 - return contpte_ptep_test_and_clear_young(vma, addr, ptep); + return contpte_test_and_clear_young_ptes(vma, addr, ptep, 1); } =20 #define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH @@ -1835,7 +1835,7 @@ static inline int ptep_clear_flush_young(struct vm_ar= ea_struct *vma, if (likely(!pte_valid_cont(orig_pte))) return __ptep_clear_flush_young(vma, addr, ptep); =20 - return contpte_ptep_clear_flush_young(vma, addr, ptep); + return contpte_clear_flush_young_ptes(vma, addr, ptep, 1); } =20 #define wrprotect_ptes wrprotect_ptes diff --git a/arch/arm64/mm/contpte.c b/arch/arm64/mm/contpte.c index e4ddeb46f25d..b929a455103f 100644 --- a/arch/arm64/mm/contpte.c +++ b/arch/arm64/mm/contpte.c @@ -508,8 +508,9 @@ pte_t contpte_get_and_clear_full_ptes(struct mm_struct = *mm, } EXPORT_SYMBOL_GPL(contpte_get_and_clear_full_ptes); =20 -int contpte_ptep_test_and_clear_young(struct vm_area_struct *vma, - unsigned long addr, pte_t *ptep) +int contpte_test_and_clear_young_ptes(struct vm_area_struct *vma, + unsigned long addr, pte_t *ptep, + unsigned int nr) { /* * ptep_clear_flush_young() technically requires us to clear the access @@ -518,41 +519,45 @@ int contpte_ptep_test_and_clear_young(struct vm_area_= struct *vma, * contig range when the range is covered by a single folio, we can get * away with clearing young for the whole contig range here, so we avoid * having to unfold. + * + * The 'nr' means consecutive (present) PTEs that map consecutive pages + * of the same large folio in a single VMA and a single page table. */ =20 + unsigned long end =3D addr + nr * PAGE_SIZE; int young =3D 0; - int i; =20 - ptep =3D contpte_align_down(ptep); - addr =3D ALIGN_DOWN(addr, CONT_PTE_SIZE); - - for (i =3D 0; i < CONT_PTES; i++, ptep++, addr +=3D PAGE_SIZE) + ptep =3D contpte_align_addr_ptep(&addr, &end, ptep, nr); + for (; addr !=3D end; ptep++, addr +=3D PAGE_SIZE) young |=3D __ptep_test_and_clear_young(vma, addr, ptep); =20 return young; } -EXPORT_SYMBOL_GPL(contpte_ptep_test_and_clear_young); +EXPORT_SYMBOL_GPL(contpte_test_and_clear_young_ptes); =20 -int contpte_ptep_clear_flush_young(struct vm_area_struct *vma, - unsigned long addr, pte_t *ptep) +int contpte_clear_flush_young_ptes(struct vm_area_struct *vma, + unsigned long addr, pte_t *ptep, + unsigned int nr) { int young; =20 - young =3D contpte_ptep_test_and_clear_young(vma, addr, ptep); + young =3D contpte_test_and_clear_young_ptes(vma, addr, ptep, nr); =20 if (young) { + unsigned long end =3D addr + nr * PAGE_SIZE; + + contpte_align_addr_ptep(&addr, &end, ptep, nr); /* * See comment in __ptep_clear_flush_young(); same rationale for * eliding the trailing DSB applies here. */ - addr =3D ALIGN_DOWN(addr, CONT_PTE_SIZE); - __flush_tlb_range_nosync(vma->vm_mm, addr, addr + CONT_PTE_SIZE, + __flush_tlb_range_nosync(vma->vm_mm, addr, end, PAGE_SIZE, true, 3); } =20 return young; } -EXPORT_SYMBOL_GPL(contpte_ptep_clear_flush_young); +EXPORT_SYMBOL_GPL(contpte_clear_flush_young_ptes); =20 void contpte_wrprotect_ptes(struct mm_struct *mm, unsigned long addr, pte_t *ptep, unsigned int nr) --=20 2.47.3