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 4AE40C3ABC0 for ; Thu, 8 May 2025 01:37:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ABC946B0085; Wed, 7 May 2025 21:37:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A91A36B0088; Wed, 7 May 2025 21:37:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 981946B0089; Wed, 7 May 2025 21:37:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 7B0B16B0085 for ; Wed, 7 May 2025 21:37:08 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id E3B2E161AEC for ; Thu, 8 May 2025 01:37:08 +0000 (UTC) X-FDA: 83418027336.16.C82014D Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf03.hostedemail.com (Postfix) with ESMTP id 25F7920003 for ; Thu, 8 May 2025 01:37:06 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=dnycdlAc; spf=pass (imf03.hostedemail.com: domain of akpm@linux-foundation.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1746668227; 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:dkim-signature; bh=KqLTtHXM4zIH08txDNsQFrxyChWvAoaGoQiCJnuhJCQ=; b=6VrAwIO4cNFO67+749mhHW3CadoxEDsqOVspdzpamkQdhvYqLLigoUBEqNnFJ5Vt2mz02w Gl3zolYlTkGsmP02ZbsttL66bIYrzVq/V5jf4lvsCDheCHSoVSzfUQyLp+BoBc4GTKRTDX hr8kIh0RL3aETARd0+hdV1vvThO7wGo= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=dnycdlAc; spf=pass (imf03.hostedemail.com: domain of akpm@linux-foundation.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1746668227; a=rsa-sha256; cv=none; b=ZrPWtBEB5DJlx12M7N+kubyv/B+/H3UGwS0cvaID/LYNgHRTA/ZCtscDEsfhl+/sQRvCRa P9B52oY6Zn1xItAWFsrPORwhLi8TmWKm8BXeM4eEDCd8r7iPDn3VKXw9X/ns+CVPSA1NiV Uez+EXrgddoRKJXLpT14uRtTZcPAo00= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 090F2A4B58F; Thu, 8 May 2025 01:37:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 776B6C4CEE2; Thu, 8 May 2025 01:37:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1746668225; bh=pRYTX2VLsUqyiCzLvT/3wIsdfY9m1XZvdCfmiQ9A7oc=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=dnycdlAcQBEsRwACIHbVv+OpVbHm9G/xV/5/2F/Mc0n9IBSODnj0B4rG+NP+wp5TT DlAPZzhuYe4sK5vDAY3opv0Ad5ebj/E/Od/2+4xOMXQMx825p1qIxbOuzZs9ElVsrX 998bwUASzpodCI6zLanlhPUcjHnFaOPerALKFgME= Date: Wed, 7 May 2025 18:37:03 -0700 From: Andrew Morton To: Dev Jain 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, anshuman.khandual@arm.com, willy@infradead.org, ioworker0@gmail.com, yang@os.amperecomputing.com, baolin.wang@linux.alibaba.com, ziy@nvidia.com, hughd@google.com Subject: Re: [PATCH v2 2/2] mm: Optimize mremap() by PTE batching Message-Id: <20250507183703.43d7b53d5e2e263566cfe80a@linux-foundation.org> In-Reply-To: <20250507060256.78278-3-dev.jain@arm.com> References: <20250507060256.78278-1-dev.jain@arm.com> <20250507060256.78278-3-dev.jain@arm.com> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Stat-Signature: kmcg9z6q3p7okf4y1khbmimxxf1fxtg4 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 25F7920003 X-Rspam-User: X-HE-Tag: 1746668226-740539 X-HE-Meta: U2FsdGVkX19nRWs6vetObyhfUnjJqsGc3AQj+GtMrbGobtEXRFEjYKC6zBi3krs5Z6g+4yRyDiZ2D5+ynG0uwqC232hiP6Ew7QGstDlXxjVjujLRm4XhSdNBlhYtqshSQDo7KIY5hLHV8fsxsF2F5nosP8xmXyfw8ulJsyD+d0jr9avtQUP4aXMuxnfZXpolIOwUQ8NzwIJK29dEON0VXWeOoJiCcAnh6ytQwLbsJp3JbDg2t7g5NG1iuFlre5fm8YzOdhsIUnwNdoeLmUJaje4Gu1y1Y9FKl7sAMraTQRQQ3nikW1eU5as2dGKEnXGF+kBFSa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o@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Wed, 7 May 2025 11:32:56 +0530 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. > Next, use folio_pte_batch() to optimize move_ptes(). On arm64, if the ptes > are painted with the contig bit, then ptep_get() will iterate through all 16 > entries to collect a/d bits. Hence this optimization will result in a 16x > reduction in the number of ptep_get() calls. Next, ptep_get_and_clear() > will eventually call contpte_try_unfold() on every contig block, thus > flushing the TLB for the complete large folio range. Instead, use > get_and_clear_full_ptes() so as to elide TLBIs on each contig block, and only > do them on the starting and ending contig block. > > ... > > --- a/include/linux/pgtable.h > +++ b/include/linux/pgtable.h > @@ -369,6 +369,35 @@ static inline pgd_t pgdp_get(pgd_t *pgdp) > } > #endif > > +/** > + * maybe_contiguous_pte_pfns - Hint whether the page mapped by the pte belongs > + * to a large folio. > + * @ptep: Pointer to the page table entry. > + * @pte: The page table entry. > + * > + * This helper is invoked when the caller wants to batch over a set of ptes > + * mapping a large folio, but the concerned code path does not already have > + * the folio. We want to avoid the cost of vm_normal_folio() only to find that > + * the underlying folio was small; i.e keep the small folio case as fast as > + * possible. > + * > + * The caller must ensure that ptep + 1 exists. > + */ Gee, that isn't the prettiest interface we've ever invented. Is there any prospect that this function will get another caller? If not then it's probably better to just open-code all this in the caller and fill it up with comments. Anyway, review of this series is scanty. I'd normally enter wait-and-see mode, but this: > the average execution time reduces from 1.9 to > 1.2 seconds, giving a 37% performance optimization, on Apple M3 (arm64). prompts me into push-it-along mode.