From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out30-113.freemail.mail.aliyun.com (out30-113.freemail.mail.aliyun.com [115.124.30.113]) (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 11C2C29D29F for ; Tue, 3 Mar 2026 02:36:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.113 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772505404; cv=none; b=s9AwLdXG5SPWMAheJIsNE1XzyvspBnw+PQAgDy7o+njJdQqJ7UBgE6fTo/dJgCDZj7KY6GxRlzZgFz2BIdPnzIEa5X3ub/7tVs/L+2qSMmqFweJeeHK+1GXzRBMUhsTbI1IAX5fO8F4JIZfbUePBGSgALBr/hWuW349b9V1gPDo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772505404; c=relaxed/simple; bh=QjixLyD+em+y1F8UsxruTKZw5v/AL+4DM4h8+gKqKDw=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=B3ZEgSySTzaCmK9f69f2jIEnMpx2gml6e437l1yi04OuLfM2Di77JUKku7QFCOeO+BsD//oTFqVmgubK1SUcwmnrKzey7/KS9PRRXFcNbHjcccNa1pVk65aZcHReZUeSz6ZGiDOzAmLJzXpf9eYrdIdbey3Ptfa52ah2d9rSwi8= 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=Q/WN3Bnz; arc=none smtp.client-ip=115.124.30.113 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="Q/WN3Bnz" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1772505400; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=+2mEdKwaynOPWZlFY7lYmhYDunrC0D6Hhh7ZFnGQH84=; b=Q/WN3Bnz7U6yeOX9UQiIgORRgqM/1B+h7cXaZG5yTUX9/wANnJZpgjnhMhBqUSK/eJryNFW1LEvitksGiyIZHNlrKM5CkegTZSn8msbgHs14pzB9h29RJO/MSWjKjhLk06+jdlVsCVdc80+Ez+ktVTdl7RS++DVnhrcf+rKZ6kA= Received: from 30.74.144.119(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0X-89.pD_1772505397 cluster:ay36) by smtp.aliyun-inc.com; Tue, 03 Mar 2026 10:36:38 +0800 Message-ID: <7b4266c8-f885-44fb-b39b-aee38625980c@linux.alibaba.com> Date: Tue, 3 Mar 2026 10:36:37 +0800 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 v2 4/6] mm: add a batched helper to clear the young flag for large folios To: "David Hildenbrand (Arm)" , akpm@linux-foundation.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, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org References: <589d743f4e048dc749002a7e1a1aec5d511c406b.1772185080.git.baolin.wang@linux.alibaba.com> From: Baolin Wang In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 3/2/26 5:07 PM, David Hildenbrand (Arm) wrote: > On 2/27/26 10:44, Baolin Wang wrote: >> Currently, MGLRU will call ptep_test_and_clear_young_notify() to check and >> clear the young flag for each PTE sequentially, which is inefficient for >> large folios reclamation. >> >> Moreover, on Arm64 architecture, which supports contiguous PTEs, the Arm64- >> specific ptep_test_and_clear_young() already implements an optimization to >> clear the young flags for PTEs within a contiguous range. However, this is not >> sufficient. Similar to the Arm64 specific clear_flush_young_ptes(), we can >> extend this to perform batched operations for the entire large folio (which >> might exceed the contiguous range: CONT_PTE_SIZE). >> >> Thus, we can introduce a new batched helper: test_and_clear_young_ptes() and >> its wrapper test_and_clear_young_ptes_notify() which are consistent with the >> existing functions, to perform batched checking of the young flags for large >> folios, which can help improve performance during large folio reclamation when >> MGLRU is enabled. And it will be overridden by the architecture that implements >> a more efficient batch operation in the following patches. >> >> Signed-off-by: Baolin Wang >> --- >> include/linux/pgtable.h | 38 ++++++++++++++++++++++++++++++++++++++ >> mm/internal.h | 16 +++++++++++----- >> 2 files changed, 49 insertions(+), 5 deletions(-) >> >> diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h >> index 776993d4567b..29bd9fd04e1e 100644 >> --- a/include/linux/pgtable.h >> +++ b/include/linux/pgtable.h >> @@ -1103,6 +1103,44 @@ static inline int clear_flush_young_ptes(struct vm_area_struct *vma, >> } >> #endif >> >> +#ifndef test_and_clear_young_ptes >> +/** >> + * test_and_clear_young_ptes - Mark PTEs that map consecutive pages of the same >> + * folio as old >> + * @vma: The virtual memory area the pages are mapped into. >> + * @addr: Address the first page is mapped at. >> + * @ptep: Page table pointer for the first entry. >> + * @nr: Number of entries to clear access bit. >> + * >> + * May be overridden by the architecture; otherwise, implemented as a simple >> + * loop over ptep_test_and_clear_young(). >> + * >> + * Note that PTE bits in the PTE range besides the PFN can differ. For example, >> + * some PTEs might be write-protected. >> + * >> + * Context: The caller holds the page table lock. The PTEs map consecutive >> + * pages that belong to the same folio. The PTEs are all in the same PMD. >> + * >> + * Returns: whether any PTE was young. >> + */ >> +static inline int test_and_clear_young_ptes(struct vm_area_struct *vma, >> + unsigned long addr, pte_t *ptep, >> + unsigned int nr) > > Two tabs ... Ah, yes, not sure why I missed this one :( > What happened to using a boolen as return type and for "int young"? As I replied to you previously [1], I’d like to do this in a follow-up patchset that converts all functions that check the young flag. Does that sound OK to you? [1] https://lore.kernel.org/all/32c538ce-6af8-48a8-86fc-d26ee253af54@linux.alibaba.com/