linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Dev Jain <dev.jain@arm.com>
To: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: akpm@linux-foundation.org, Liam.Howlett@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 0/2] Optimize mremap() for large folios
Date: Fri, 9 May 2025 10:57:05 +0530	[thread overview]
Message-ID: <e258ac09-2338-49cd-a9d7-8e3be8045d8a@arm.com> (raw)
In-Reply-To: <3fe90c96-da4d-4240-bd58-0bed5fe7cf5f@lucifer.local>



On 09/05/25 12:05 am, Lorenzo Stoakes wrote:
> Dev - a general comment here - but let's slow things down a little please
> :)
> 
> The mprotect() version of this is still outstanding fixes and likely will
> need quite a bit of checking before we can ensure it's stabilised.
> 
> And now we have this mremap() series as well which also has had quite a few
> quite significant issues that have needed addressing.
> 
> So can we try to focus on one at a time, and really try to nail down the
> series before moving on to the next?
> 
> We also have outstanding review on the v1, which has now been split, which
> does happen sometimes but perhaps suggests that it'd work better if you
> waited a couple days or such to ensure things are settled before sending a
> new version when there's quite a bit of feedback?

Sure, I should have waited my bad, I usually do, this time I was in a 
haste with both series for no reason :( thanks for your detailed replies 
btw!

> 
> This isn't a criticism really, sorry I don't mean to sound negative or such
> - but this is more a process thing so we reviewers can keep up with things,
> keep things rolling, and ensure you get your changes merged asap :)
> 
> Thanks, Lorenzo
> 
> On Wed, May 07, 2025 at 11:32:54AM +0530, Dev Jain wrote:
>> Currently move_ptes() iterates through ptes one by one. If the underlying
>> folio mapped by the ptes is large, we can process those ptes in a batch
>> using folio_pte_batch(), thus clearing and setting the PTEs in one go.
>> For arm64 specifically, this results in a 16x reduction in the number of
>> ptep_get() calls (since on a contig block, ptep_get() on arm64 will iterate
>> through all 16 entries to collect a/d bits), and we also elide extra TLBIs
>> through get_and_clear_full_ptes, replacing ptep_get_and_clear.
>>
>> Mapping 512K of memory, memsetting it, remapping it to src + 512K, and
>> munmapping it 10,000 times, the average execution time reduces from 1.9 to
>> 1.2 seconds, giving a 37% performance optimization, on Apple M3 (arm64).
>>
>> Test program for reference:
>>
>> #define _GNU_SOURCE
>> #include <stdio.h>
>> #include <stdlib.h>
>> #include <unistd.h>
>> #include <sys/mman.h>
>> #include <string.h>
>> #include <errno.h>
>>
>> #define SIZE (1UL << 20) // 512 KB
>>
>> int main(void) {
>>      void *new_addr, *addr;
>>
>>      for (int i = 0; i < 10000; ++i) {
>>          addr = mmap((void *)(1UL << 30), SIZE, PROT_READ | PROT_WRITE,
>>                      MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
>>          if (addr == MAP_FAILED) {
>>                  perror("mmap");
>>                  return 1;
>>          }
>>          memset(addr, 0xAA, SIZE);
>>
>>          new_addr = mremap(addr, SIZE, SIZE, MREMAP_MAYMOVE | MREMAP_FIXED, addr + SIZE);
>>          if (new_addr != (addr + SIZE)) {
>>                  perror("mremap");
>>                  return 1;
>>          }
>>          munmap(new_addr, SIZE);
>>      }
>>
>> }
>>
>> v1->v2:
>>   - Expand patch descriptions, move pte declarations to a new line,
>>     reduce indentation in patch 2 by introducing mremap_folio_pte_batch(),
>>     fix loop iteration (Lorenzo)
>>   - Merge patch 2 and 3 (Anshuman, Lorenzo)
>>   - Fix maybe_contiguous_pte_pfns (Willy)
>>
>> Dev Jain (2):
>>    mm: Call pointers to ptes as ptep
>>    mm: Optimize mremap() by PTE batching
>>
>>   include/linux/pgtable.h | 29 ++++++++++++++++++++++
>>   mm/mremap.c             | 54 +++++++++++++++++++++++++++++------------
>>   2 files changed, 68 insertions(+), 15 deletions(-)
>>
>> --
>> 2.30.2
>>



  reply	other threads:[~2025-05-09  5:27 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-07  6:02 [PATCH v2 0/2] Optimize mremap() for large folios Dev Jain
2025-05-07  6:02 ` [PATCH v2 1/2] mm: Call pointers to ptes as ptep Dev Jain
2025-05-08  1:05   ` Barry Song
2025-05-08  6:21   ` Anshuman Khandual
2025-05-08  9:21   ` Lorenzo Stoakes
2025-05-07  6:02 ` [PATCH v2 2/2] mm: Optimize mremap() by PTE batching Dev Jain
2025-05-08  1:37   ` Andrew Morton
2025-05-08  4:53     ` Lorenzo Stoakes
2025-05-08  2:00   ` Zi Yan
2025-05-08  4:01     ` Dev Jain
2025-05-08  6:31     ` Anshuman Khandual
2025-05-08  7:16   ` Anshuman Khandual
2025-05-08  8:05     ` Dev Jain
2025-05-08  9:40     ` Lorenzo Stoakes
2025-05-08 10:04   ` Lorenzo Stoakes
2025-05-08 18:01     ` David Hildenbrand
2025-05-18  8:17     ` Dev Jain
2025-05-19  9:04       ` Lorenzo Stoakes
2025-05-20  9:21         ` Dev Jain
2025-05-08 18:35 ` [PATCH v2 0/2] Optimize mremap() for large folios Lorenzo Stoakes
2025-05-09  5:27   ` Dev Jain [this message]
2025-05-09  8:44     ` Lorenzo Stoakes
2025-05-09  9:26       ` David Hildenbrand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e258ac09-2338-49cd-a9d7-8e3be8045d8a@arm.com \
    --to=dev.jain@arm.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=anshuman.khandual@arm.com \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=david@redhat.com \
    --cc=hughd@google.com \
    --cc=ioworker0@gmail.com \
    --cc=jannh@google.com \
    --cc=libang.li@antgroup.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=maobibo@loongson.cn \
    --cc=mingo@kernel.org \
    --cc=peterx@redhat.com \
    --cc=pfalcato@suse.de \
    --cc=ryan.roberts@arm.com \
    --cc=vbabka@suse.cz \
    --cc=willy@infradead.org \
    --cc=yang@os.amperecomputing.com \
    --cc=zhengqi.arch@bytedance.com \
    --cc=ziy@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).