From nobody Sun Apr 5 21:16:29 2026 Received: from out199-16.us.a.mail.aliyun.com (out199-16.us.a.mail.aliyun.com [47.90.199.16]) (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 E00792417DE for ; Tue, 24 Feb 2026 01:56:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=47.90.199.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771898205; cv=none; b=o0IPX83uq1FLaJ57gzldLwTI846zBhJabYIHlh6IFKInPnlO39jS8ocYZCY6jRjI7e2Hxi1wGMcKiZBkXN0tOJ9nnJhFG4fdJ6G/pX+jNAv8G7I8eSRseAHpIDQC/EMJH7HJ/FQ1PMaHMFkks+mqLvRR527yVrIkoCP5yQfWKHo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771898205; c=relaxed/simple; bh=cgdz821iTmxl8haD7IUj2Vub2A4teSmrEuqday4mGE4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qvP6pRUuySPqzzam4BCP9q28I7AFn/Mc4UWS/UxEddz4oH1x94qC4HPKyAc/UYRhxnYzDjaBLhzkDugkLnCxSogY1Trxihw1N/axsONNNIZe7h3hmb4SjJ6eSDrjD1LbwKMILVRzYYoapPsCg0i4oP+QqXam5/r1ZEcU5drByDI= 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=K4WcqISW; arc=none smtp.client-ip=47.90.199.16 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="K4WcqISW" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1771898193; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=l/n42tr+9IlpOp5hFur4DBL69XJ1P8BtXGTtcSlF0LE=; b=K4WcqISW1qVJlDyB4fuMzBzEZhg9kSKoUaULhoFo38Dt3FWY+Sa3H+FLfvVotouGeRm9otDJfz5iVg1O821QjtxzVPCXaHatHyXxW3lZoKBsfTvNNAunILBubGHwVDAjXiERmrd9xXeRx3hXY/P0H2IQiidOmTfFgDDUsCXzhnk= Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WzhpS5._1771898189 cluster:ay36) by smtp.aliyun-inc.com; Tue, 24 Feb 2026 09:56:30 +0800 From: Baolin Wang To: akpm@linux-foundation.org, david@kernel.org Cc: catalin.marinas@arm.com, will@kernel.org, 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, axelrasmussen@google.com, yuanchu@google.com, weixugc@google.com, hannes@cmpxchg.org, zhengqi.arch@bytedance.com, shakeel.butt@linux.dev, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/5] arm64: mm: implement the architecture-specific test_and_clear_young_ptes() Date: Tue, 24 Feb 2026 09:56:08 +0800 Message-ID: <5933ff4d7124cf972bb2474666b4699580fbc334.1771897150.git.baolin.wang@linux.alibaba.com> 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" Implement the Arm64 architecture-specific test_and_clear_young_ptes() to en= able batched checking of young flags, improving performance during large folio reclamation when MGLRU is enabled. While we're at it, simplify ptep_test_and_clear_young() by calling test_and_clear_young_ptes(). Since callers guarantee that PTEs are present before calling these functions, we can use pte_cont() to check the CONT_PTE flag instead of pte_valid_cont(). Performance testing: Enable MGLRU, then allocate 10G clean file-backed folios by mmap() in a mem= ory cgroup, and try to reclaim 8G file-backed folios via the memory.reclaim int= erface. I can observe 60%+ performance improvement on my Arm64 32-core server (and = about 15% improvement on my X86 machine). W/o patchset: real 0m0.470s user 0m0.000s sys 0m0.470s W/ patchset: real 0m0.180s user 0m0.001s sys 0m0.179s Signed-off-by: Baolin Wang Reviewed-by: Rik van Riel --- arch/arm64/include/asm/pgtable.h | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgta= ble.h index aa4b13da6371..ab451d20e4c5 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -1812,16 +1812,22 @@ static inline pte_t ptep_get_and_clear(struct mm_st= ruct *mm, return __ptep_get_and_clear(mm, addr, ptep); } =20 +#define test_and_clear_young_ptes test_and_clear_young_ptes +static inline int test_and_clear_young_ptes(struct vm_area_struct *vma, + unsigned long addr, pte_t *ptep, + unsigned int nr) +{ + if (likely(nr =3D=3D 1 && !pte_cont(__ptep_get(ptep)))) + return __ptep_test_and_clear_young(vma, addr, ptep); + + return contpte_test_and_clear_young_ptes(vma, addr, ptep, nr); +} + #define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG static inline int ptep_test_and_clear_young(struct vm_area_struct *vma, unsigned long addr, pte_t *ptep) { - pte_t orig_pte =3D __ptep_get(ptep); - - if (likely(!pte_valid_cont(orig_pte))) - return __ptep_test_and_clear_young(vma, addr, ptep); - - return contpte_test_and_clear_young_ptes(vma, addr, ptep, 1); + return test_and_clear_young_ptes(vma, addr, ptep, 1); } =20 #define __HAVE_ARCH_PTEP_CLEAR_YOUNG_FLUSH --=20 2.47.3