From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out30-118.freemail.mail.aliyun.com (out30-118.freemail.mail.aliyun.com [115.124.30.118]) (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 9CB5F194098 for ; Thu, 29 Jan 2026 01:42:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.118 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769650940; cv=none; b=trZfyAPsbnxZLbOMv+1ukOzLq9GKlAxaemLUopJGI9c1H+1M/BMnP09V69X9zb+sLW4l0NZRlkPefop/bQDXtnMOuB7ZpTI5uUD6qR3+a3HCEystl+lJNjE9k80LNPD8OgYGeQIh6pMAJ2hEMhBboMCVsxNX8NYQsG9+In0f8c0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769650940; c=relaxed/simple; bh=MfqmsKH6YzR3f4cAUCmkbc65QL+6+TpKi4TqMaqbP4k=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=EcF/wErV5ixIpM03EwHfq+DsxzZWSSFNlqailCnK2NrwCkv15lZtJoUC63kHrEX24Fg+rJyGAn+TVZ4YrHGlv8OF66ZNXd2Wqh3j3PI0zknfNB29Xg9RieL7JYZ7Ys8C7kLIHN0APoRnAnwe754EWv1gYHddTv7lZojGd1UKxac= 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=Br8Pn4NO; arc=none smtp.client-ip=115.124.30.118 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="Br8Pn4NO" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1769650935; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=1mooo+VFrXzT3ho52+vyVC3gkAOeJGRzvzapS1lW0iw=; b=Br8Pn4NODrrLXM+Vcbw6tFOpFFqlJF2RPyEIvne3KBfw/VNcK6M+eH5Bu0z2PDdTuFl3nVXvhDVwjudI4PBPXR6Hb2a9Cw0YGvEGjLRlncsQKQJw3/Kc23ws48DRuUFck/j00f5iD32aEMD4M5kQQqvYYTwcyWDbv6OJ06NitdU= Received: from 30.74.144.124(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0Wy5TwiT_1769650933 cluster:ay36) by smtp.aliyun-inc.com; Thu, 29 Jan 2026 09:42:14 +0800 Message-ID: Date: Thu, 29 Jan 2026 09:42:12 +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: Chris Mason Cc: akpm@linux-foundation.org, david@kernel.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> From: Baolin Wang In-Reply-To: <20260128114936.72280-1-clm@meta.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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. diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h index a17eb8a76788..dc16591c4241 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -1843,7 +1843,7 @@ 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)))) + if (likely(nr == 1 && !pte_valid_cont(__ptep_get(ptep)))) return __ptep_clear_flush_young(vma, addr, ptep); return contpte_clear_flush_young_ptes(vma, addr, ptep, nr);