From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out30-112.freemail.mail.aliyun.com (out30-112.freemail.mail.aliyun.com [115.124.30.112]) (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 3B7FC21018A for ; Fri, 19 Dec 2025 00:56:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.112 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766105785; cv=none; b=G/NumzpTtW3FurlW1lTcmQ6YRgcU8PsjYWTWWjWj+bPb67fWvHcDtVLAyxCEz/LCIpnasU4JAaoWqhzbZiHrJKUMkhcVatv4SfPi+6K7e7nWJ2QzUWLF8rO9AFpOl33FkxG8dss5TVXw61r9TLYFgzj4C3OCTYjf8vhYrkCNOQM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766105785; c=relaxed/simple; bh=L3PBaSvxA8Kj5vOSfHWP8UxvFO19uAP2psbvSuIIKDg=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=f7VL+yUSUVQ1y66DbUGn8/vB2jms1phZQxA70oE9ocZki2YoKFs3Urtpw0Kml/LnRvqDVNU4fLIfKRgxmG8n0uuo8hjJpTdZZgDlUk0JmPBHYiq84sDrtrME+41ELorYFJMyZSeqpAYl8jSuXAhGJJx4XUc7cI/xChHl1Z+IWLs= 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=N6+0xoAA; arc=none smtp.client-ip=115.124.30.112 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="N6+0xoAA" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1766105773; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=t2o/Vumy+Nw5btbRIBN01nzQJNm6p8LL2tmTgt6B/0g=; b=N6+0xoAArOybKVK8gEqXsENA4TNJA/LFzH+WXtdSszdh7Xj945F1iG8/3/0Cp4eLbs1SUr+ainvgAm5lseGsGN3KUKiRptos+lOdtFluJ3P7hqMgFpiV+SiSVVq5NTva4R4P2cG6xqN0NXwy9ocanBSm6fI/vA/L9meZBrxBAPM= Received: from 30.74.144.116(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WvASlNx_1766105770 cluster:ay36) by smtp.aliyun-inc.com; Fri, 19 Dec 2025 08:56:11 +0800 Message-ID: <121c8ffb-adff-4766-aae9-8be6d37d546a@linux.alibaba.com> Date: Fri, 19 Dec 2025 08:56:09 +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 2/3] mm: rmap: support batched checks of the references for large folios To: Ryan Roberts , akpm@linux-foundation.org, david@kernel.org, catalin.marinas@arm.com, will@kernel.org Cc: lorenzo.stoakes@oracle.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, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org References: <545dba5e899634bc6c8ca782417d16fef3bd049f.1765439381.git.baolin.wang@linux.alibaba.com> <89cdd927-fc88-42cf-b8a1-2fbd736d5f7c@linux.alibaba.com> <0caffb55-f242-4b01-b60a-c8749aadf661@arm.com> From: Baolin Wang In-Reply-To: <0caffb55-f242-4b01-b60a-c8749aadf661@arm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 2025/12/18 20:08, Ryan Roberts wrote: >>>>   +#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)) >>>> +        return __ptep_clear_flush_young(vma, addr, ptep); >>> >>> Bug: This is broken if core-mm tries to call this for nr=1 on a pte that is part >>> of a contpte mapping. >>> >>> The similar fastpaths are here to prevent regressing the common small folio case. >> >> Thanks for catching this. I had considered this before, but I still missed it. >> >>> I guess here the best approach is (note no leading underscores): >>> >>>     if (likely(nr == 1)) >>>         return ptep_clear_flush_young(vma, addr, ptep); >> >> However, I prefer to use pte_cont() to check it. Later, I plan to clean up the >> ptep_clear_flush_young(). >> >>     if (nr == 1 && !pte_cont(__ptep_get(ptep)) >>         return __ptep_clear_flush_young(vma, addr, ptep); > > Sure. That would follow the pattern in clear_young_dirty_ptes(). Please use the > likely() hint as is done everywhere else: > > if (likely(nr == 1 && !pte_cont(__ptep_get(ptep)))) Sure. > I notice that ptep_test_and_clear_young() and ptep_clear_flush_young() are both > testing aginst pte_valid_cont(). These could probably be relaxed to pte_cont() > since it is implicit the the pte must be valid? Yes, I think so. I can do a cleanup later in a separate patch.