From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out30-110.freemail.mail.aliyun.com (out30-110.freemail.mail.aliyun.com [115.124.30.110]) (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 1F7AD30C62D for ; Mon, 9 Feb 2026 09:37:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.110 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770629826; cv=none; b=IAvEPYHWdN6YkuKvVq4t4kfSsOmUX3eTF808S9NbbpZYvQQgDz0kgrpQEHdfyR6TbtWEMRqsPl8kdAIO6ooisVylHawsRMUXwBuF3PzQYtruIjRzDSuMZ4Aqc7CwFEneoZhVYqp8mZpRLw/u5V5NNAiIvQnkzoixjjL7thTN4Fs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770629826; c=relaxed/simple; bh=ADw59I4WFZFWR+8XkeaJjuBbwsQzZXvNPaoslGd/3Bs=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=qE9TRLFrw7tPDCk9ptt1UCPo43CUOOZr/XpuBMBCoOewPxwOz2wvi8HbcjDhRJAQS+hifMyk3vqcLZAgooFz4p/rGaAD1R9FR+muzRzZlQW6MpeY4va+rG0svQX1ic5oqXc870fEBgiASeFn9VQiemJYQsLBHQ9fxtVShfl8PZo= 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=HIuHVpM6; arc=none smtp.client-ip=115.124.30.110 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="HIuHVpM6" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1770629818; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=cMfba3FsPq67LjQUu31a/lCSuc8jZcI3oJ1xSlSxWtI=; b=HIuHVpM6NI8EA2vIuDA37cc13dmGofkbU0F9hxSG0UAEER6pm9E6t67MmFjL/0o+XqdoMp1PoGx/fQkpoatobLlfAZKigiNnmirYUfngARkA2qHnVGW01O28vcWnQBh29huvoGPO5IDTroYVCYXr5X1h7MC0B7ChCt5QToNrxgg= Received: from 30.74.144.127(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WyqQrzH_1770629815 cluster:ay36) by smtp.aliyun-inc.com; Mon, 09 Feb 2026 17:36:56 +0800 Message-ID: <280ae63e-d66e-438f-8045-6c870420fe76@linux.alibaba.com> Date: Mon, 9 Feb 2026 17:36:55 +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 v5 4/5] arm64: mm: implement the architecture-specific clear_flush_young_ptes() To: "David Hildenbrand (Arm)" , Chris Mason Cc: akpm@linux-foundation.org, 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, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org References: <9d866a2644051e13a41ef4d6ca3909c6e1f9e229.1766631066.git.baolin.wang@linux.alibaba.com> <20260128114936.72280-1-clm@meta.com> <07d55759-a50a-457a-badd-85697174116f@kernel.org> From: Baolin Wang In-Reply-To: <07d55759-a50a-457a-badd-85697174116f@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 2/9/26 5:09 PM, David Hildenbrand (Arm) wrote: > On 1/29/26 02:42, Baolin Wang wrote: >> >> >> On 1/28/26 7:47 PM, Chris Mason wrote: >>> Baolin Wang wrote: >>>> Implement the Arm64 architecture-specific clear_flush_young_ptes() >>>> to enable >>>> batched checking of young flags and TLB flushing, improving >>>> performance during >>>> large folio reclamation. >>>> >>>> Performance testing: >>>> Allocate 10G clean file-backed folios by mmap() in a memory cgroup, >>>> and try to >>>> reclaim 8G file-backed folios via the memory.reclaim interface. I >>>> can observe >>>> 33% performance improvement on my Arm64 32-core server (and 10%+ >>>> improvement >>>> on my X86 machine). Meanwhile, the hotspot folio_check_references() >>>> dropped >>>> from approximately 35% to around 5%. >>> >>> Hi everyone, I ran mm-new through my AI review prompts and this one was >>> flagged.  AI review below: >>> >>>> diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/ >>>> asm/pgtable.h >>>> --- a/arch/arm64/include/asm/pgtable.h >>>> +++ b/arch/arm64/include/asm/pgtable.h >>>> @@ -1838,6 +1838,17 @@ static inline int >>>> ptep_clear_flush_young(struct vm_area_struct *vma, >>>>       return contpte_clear_flush_young_ptes(vma, addr, ptep, 1); >>>>   } >>>> >>>> +#define clear_flush_young_ptes clear_flush_young_ptes >>>> +static inline int clear_flush_young_ptes(struct vm_area_struct *vma, >>>> +                     unsigned long addr, pte_t *ptep, >>>> +                     unsigned int nr) >>>> +{ >>>> +    if (likely(nr == 1 && !pte_cont(__ptep_get(ptep)))) >>>> +        return __ptep_clear_flush_young(vma, addr, ptep); >>> >>> Should this be checking !pte_valid_cont() instead of !pte_cont()? >>> >>> The existing ptep_clear_flush_young() above uses !pte_valid_cont() to >>> determine when to take the fast path. The new function only checks >>> !pte_cont(), which differs when handling non-present PTEs. >>> >>> Non-present PTEs (device-private, device-exclusive) can reach >>> clear_flush_young_ptes() through folio_referenced_one()-> >>> clear_flush_young_ptes_notify(). These entries may have bit 52 set as >>> part of their encoding, but they aren't valid contiguous mappings. >>> >>> With the current check, wouldn't such entries incorrectly trigger the >>> contpte path and potentially cause contpte_clear_flush_young_ptes() to >>> process additional unrelated PTEs beyond the intended single entry? >> >> Indeed. I previously discussed with Ryan whether using pte_cont() was >> enough, and we believed that invalid PTEs wouldn’t have the PTE_CONT >> bit set. But we clearly missed the device-folio cases. Thanks for >> reporting. >> >> Andrew, could you please squash the following fix into this patch? If >> you prefer a new version, please let me know. Thanks. > > Isn't the real problem that we should never ever ever ever, try clearing > the young bit on a non-present pte? > > See damon_ptep_mkold() how that is handled with the flushing/notify. > > There needs to be a pte_present() check in the caller. The handling of ZONE_DEVICE memory in check_pte() makes me me doubt my earlier understanding. And I think you are right. } else if (pte_present(ptent)) { pfn = pte_pfn(ptent); } else { const softleaf_t entry = softleaf_from_pte(ptent); /* Handle un-addressable ZONE_DEVICE memory */ if (!softleaf_is_device_private(entry) && !softleaf_is_device_exclusive(entry)) return false; pfn = softleaf_to_pfn(entry); } > BUT > > I recall that folio_referenced() should never apply to ZONE_DEVICE > folios. folio_referenced() is only called from memory reclaim code, and > ZONE_DEVICE pages never get reclaimed through vmscan.c Thanks for clarifying. So I can drop the pte valid check.