From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2583FC3ABBF for ; Tue, 6 May 2025 09:11:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E3BEE6B0082; Tue, 6 May 2025 05:11:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DEAC86B0088; Tue, 6 May 2025 05:11:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CFF316B0089; Tue, 6 May 2025 05:11:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id B2DA86B0082 for ; Tue, 6 May 2025 05:11:00 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 1954C1405ED for ; Tue, 6 May 2025 09:11:02 +0000 (UTC) X-FDA: 83411913564.03.0FEF72B Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf30.hostedemail.com (Postfix) with ESMTP id 5BE6E80003 for ; Tue, 6 May 2025 09:11:00 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf30.hostedemail.com: domain of anshuman.khandual@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=anshuman.khandual@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1746522660; a=rsa-sha256; cv=none; b=NvyIoFNofjoWHaExlAsbg4J9fY71CQZcpJxoxTq+3hso9puQF9Ztgha5Gjx/E4rf/mxRSH 9CjSHVsOy1Y8TGlFwxOiorQo3N9i/10IEQS/R5bm7RijFOu1SOmC0emajJcRkaEd8F48Hf 51Ga0tCEk2HOTIJToaPDQ4TycIBt5Ig= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf30.hostedemail.com: domain of anshuman.khandual@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=anshuman.khandual@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1746522660; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6r8P/I7fhFss/RTdWFyvPbC//CuRRkSUfWdcQaBYDqc=; b=l9NUh8pQUld8XDbQJt165KosmaWuXbVyzYyXPWEkz6cuNZ2CqGShnbiQvP8K0dSAayRHGf tKDiBQpUFX0M0JxgDEIG8oysRhil4Jn4UDv9on+1OuDwcG0xu7npo1hK9AQj7NUQ33J1dN YjL0gz7SZ/vwwWgWtOueNKFo2bS+7cc= 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 D13B6113E; Tue, 6 May 2025 02:10:49 -0700 (PDT) Received: from [10.163.54.208] (unknown [10.163.54.208]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A5C7F3F5A1; Tue, 6 May 2025 02:10:50 -0700 (PDT) Message-ID: Date: Tue, 6 May 2025 14:40:44 +0530 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/3] mm: Add generic helper to hint a large folio To: Dev Jain , akpm@linux-foundation.org Cc: Liam.Howlett@oracle.com, lorenzo.stoakes@oracle.com, vbabka@suse.cz, jannh@google.com, pfalcato@suse.de, linux-mm@kvack.org, linux-kernel@vger.kernel.org, david@redhat.com, peterx@redhat.com, ryan.roberts@arm.com, mingo@kernel.org, libang.li@antgroup.com, maobibo@loongson.cn, zhengqi.arch@bytedance.com, baohua@kernel.org, willy@infradead.org, ioworker0@gmail.com, yang@os.amperecomputing.com References: <20250506050056.59250-1-dev.jain@arm.com> <20250506050056.59250-3-dev.jain@arm.com> Content-Language: en-US From: Anshuman Khandual In-Reply-To: <20250506050056.59250-3-dev.jain@arm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspam-User: X-Rspamd-Queue-Id: 5BE6E80003 X-Rspamd-Server: rspam04 X-Stat-Signature: 574nfz8f56m8fpszgj9ug9tt98q86prn X-HE-Tag: 1746522660-536343 X-HE-Meta: U2FsdGVkX19kUHEM6UDaA6qHSBrzkZROwI8aBY7F+7Id2qDCW+oQL8vBJEgVKZ52MnNBblI5psfW7jhFPjpTc5PUg/wpG14C5nFPAdgNd8xwmPckoSO0yk3WdfGhgx5/SphI2VpcgydB3rLnjXkuZM/rmhRvg33kmOzTVuJS3XrL+FilGldRzt/BryKsRDCdUo0kzmyMMWWTiC0T7do7wFI/x4FkHrRFy8qF0sAX6it8CXI6Mr+OuDe8NpouQX+Q9lXHLgQl3HQTquEb4ZMY9vkAwIgj8iAsXW6irXUaCORPx91YKMv/ytHYDhaKyPkBRbgTRb1h0AYmtQdwS8f+OXDvn87IEOI5s1N2j2J/r3Byb6qHFt4CgfN2kO6jwZXebjLbaVtAwmVPghTQGKplI8Uy6pIMcoqGM0JdAPdriWDUoDFprsC+2GGaS52xspkkT6fUMwxFcGjuKrc6P583apMmNjNz2D03CE1wvb5KE1bsV38o4bWEmKfuTjfw+hv1/nfwCZ8AW1PNs0XmjV/zeKZfzym1nOdwUBAV1YVKSiquR+jcvwljtx1dYqdBw33S3uCzBLvpFESWAd0xm0T0GavC1uYcNdTDImnTy4amf7dmFTyudgH5OUT1DY+++wsHgmKhJy4riFaLsR7g/Xjx/n+FRgy34JECDMTi+rOvO/S0WLZIyc3cbZiCC5LJ8QlC0r5JOLUzMlbsyGXdjZvsS3WZCKuu9sYcZUSXaYoiShtqjMqbZdfyRqgy6NkDow1/SWtDyl7tKorBrUpoeDgUop2dP+YbE0lsQitsGXPUQDPf07PEzn9588chHR0suen8UtQ5Jru42B5lmcJ3aF6wBFcwE7MadXwG/9rhSCjd12MqiM8Bab3NcOJBBTe37ecpaPFx9fvQxgsgzcTAMdRJtNY4lm6qaAXkuDr9ElknpKqIy8+ATlIqx12zE5XTccgfIUsOkU7MhAdLXOl5Q5O wuvX/Itd eEIBa6wuIcCIQ62pzuLXQhc1jMCbMrc/pwPgmDBzrWF3TDRuM50YcpE7eKRTlRyUTQDC/uMdF3BVA/IHXlxttlQtQMYlhbXNxm05GL7QNLneLSlNMvPYzHItxmiMvjSdBuM1BwpNl23PiINR+SIFsZf6+B6QOK2KskehasTY8ierNp+yS2U16olzR/hQD76+mytfmFeS964R73f4= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On 5/6/25 10:30, Dev Jain wrote: > To use PTE batching, we want to determine whether the folio mapped by > the PTE is large, thus requiring the use of vm_normal_folio(). We want > to avoid the cost of vm_normal_folio() if the code path doesn't already > require the folio. For arm64, pte_batch_hint() does the job. To generalize > this hint, add a helper which will determine whether two consecutive PTEs > point to consecutive PFNs, in which case there is a high probability that > the underlying folio is large. > > Signed-off-by: Dev Jain > --- > include/linux/pgtable.h | 16 ++++++++++++++++ > 1 file changed, 16 insertions(+) > > diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h > index b50447ef1c92..28e21fcc7837 100644 > --- a/include/linux/pgtable.h > +++ b/include/linux/pgtable.h > @@ -369,6 +369,22 @@ static inline pgd_t pgdp_get(pgd_t *pgdp) > } > #endif > > +/* Caller must ensure that ptep + 1 exists */ > +static inline bool maybe_contiguous_pte_pfns(pte_t *ptep, pte_t pte) > +{ > + pte_t *next_ptep, next_pte; > + > + if (pte_batch_hint(ptep, pte) != 1) > + return true; > + > + next_ptep = ptep + 1; > + next_pte = ptep_get(next_ptep); > + if (!pte_present(next_pte)) > + return false; > + > + return unlikely(pte_pfn(next_pte) - pte_pfn(pte) == PAGE_SIZE); > +} > + > #ifndef __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG > static inline int ptep_test_and_clear_young(struct vm_area_struct *vma, > unsigned long address, As mentioned earlier, this new helper maybe_contiguous_pte_pfns() does not have a proposed caller. Hence please do consider folding this forward with the next patch where move_ptes() starts using the helper. Besides, it is also difficult to review this patch without a proper caller context.