From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9F5AB26F28F for ; Thu, 18 Dec 2025 12:08:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766059690; cv=none; b=CTHgokzQQf9gB2s7+RSW+BDROw7G/1pZvTTBklbb8wkilUuvpeF+eISK9FSoghuE00mW5U+wOTCET7172PCpw0y/qYimS7J2G7yaUw6TdPsAGMrIOrT3Kl17TElcT83u2gf2RLWrDbISgp9Y2xY0gZaWLwEYJbKwLwLPwT/jDvw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766059690; c=relaxed/simple; bh=hPUNsvHwjfVH6C/edkxXooKSkGSLYi78ueiJnX1HNM4=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=j/uOH8ffnECCWgbmkNT5EJyEJpROIsf2KkuAPALGHw2zbPtIuIWnWLst+4AbYXyScfAyTiCjUPee1mgkqjmumI+gDMv0hIObrceLq2oGcaujNcN9QADhdk4KhAO7RKusWaDrosa9gGSyBgwwQjHAuHkQii+qA5kyexfn2ncKDx0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id CC3CBFEC; Thu, 18 Dec 2025 04:08:00 -0800 (PST) Received: from [10.1.39.180] (unknown [10.1.39.180]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 418C33F762; Thu, 18 Dec 2025 04:08:05 -0800 (PST) Message-ID: <0caffb55-f242-4b01-b60a-c8749aadf661@arm.com> Date: Thu, 18 Dec 2025 12:08:03 +0000 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 Content-Language: en-GB To: Baolin Wang , 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> From: Ryan Roberts In-Reply-To: <89cdd927-fc88-42cf-b8a1-2fbd736d5f7c@linux.alibaba.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit >>>   +#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)))) 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?