mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Shivank Garg <shivankg@amd.com>
To: Andrew Morton <akpm@linux-foundation.org>,
	David Hildenbrand <david@kernel.org>,
	Lorenzo Stoakes <ljs@kernel.org>,
	"Liam R. Howlett" <liam@infradead.org>,
	Vlastimil Babka <vbabka@kernel.org>,
	Mike Rapoport <rppt@kernel.org>,
	Suren Baghdasaryan <surenb@google.com>,
	Michal Hocko <mhocko@suse.com>, Borislav Petkov <bp@alien8.de>,
	Ankur Arora <ankur.a.arora@oracle.com>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	"Thomas Gleixner" <tglx@kernel.org>,
	Bharata B Rao <bharata@amd.com>,
	"Hrushikesh Salunke" <hsalunke@amd.com>,
	Ingo Molnar <mingo@redhat.com>, "H . Peter Anvin" <hpa@zytor.com>,
	David Laight <david.laight.linux@gmail.com>,
	David Rientjes <rientjes@google.com>,
	Linus Torvalds <torvalds@linuxfoundation.org>,
	"Teja Vojjala" <tejavojjala@google.com>,
	Huan Nguyen <nhuhuan@google.com>,
	"Pedro Falcato" <pfalcato@suse.de>,
	Peter Zijlstra <peterz@infradead.org>, Zi Yan <ziy@nvidia.com>,
	Baolin Wang <baolin.wang@linux.alibaba.com>,
	Nico Pache <nico.pache@linux.dev>,
	Ryan Roberts <ryan.roberts@arm.com>, Dev Jain <dev.jain@arm.com>,
	Barry Song <baohua@kernel.org>, Lance Yang <lance.yang@linux.dev>,
	Usama Arif <usama.arif@linux.dev>,
	Kiryl Shutsemau <kas@kernel.org>,
	Ying Huang <ying.huang@linux.alibaba.com>
Cc: <linux-mm@kvack.org>, <linux-kernel@vger.kernel.org>,
	<x86@kernel.org>, Shivank Garg <shivankg@amd.com>
Subject: [PATCH v4 0/6] mm: copy page ranges with one copy_mc_to_kernel() call
Date: Tue, 1 Dec 2026 08:29:46 +0000	[thread overview]
Message-ID: <20261201-batpagecopy-v4-0-dd82a573e573@amd.com> (raw)

On a Zen 6 system with CXL memory, move_pages() gets ~1.4x faster for
2MB THPs and up to ~2.8x faster for 1GB hugetlb pages, and when demoting
to CXL, kswapd uses ~31% less CPU per GB demoted. Hugetlb copy on write
gets ~1.5x faster for 2MB pages and ~2x faster for 1GB pages, and
MADV_COLLAPSE of a tmpfs file made of large folios gets ~11% faster
(numbers below).

Copying a folio with machine check handling makes one
copy_mc_to_kernel() call per page. This series copies a page range with
a single call where possible (x86-64 and ppc64), for folio migration,
hugetlb copy on write and khugepaged file collapse.

Test setup: AMD EPYC Zen 6, single socket, NPS2 (nodes 0 and 1 are
DRAM, node 2 is CXL), base (mm/core.git for-next) vs the whole series.

move_pages() throughput
-----------------------
A single move_pages() call migrates 1GB of anonymous memory, as 512
2MB THPs or as four 1GB hugetlb pages. Mean ± stddev, GiB/s:

2MB THP:
  direction         base            patched         speedup
  DRAM0 -> DRAM1    19.57 ± 0.17    27.51 ± 0.78    1.41x
  DRAM1 -> DRAM0    19.44 ± 0.12    27.33 ± 0.27    1.41x
  DRAM0 -> CXL      18.66 ± 0.18    26.90 ± 0.51    1.44x
  CXL   -> DRAM0    15.38 ± 0.59    16.60 ± 0.24    1.08x

1GB hugetlb:
  direction         base            patched         speedup
  DRAM0 -> DRAM1    20.34 ± 0.13    53.88 ± 1.48    2.65x
  DRAM1 -> DRAM0    19.10 ± 2.65    53.78 ± 0.55    2.82x
  DRAM0 -> CXL      19.53 ± 0.08    44.10 ± 0.19    2.26x
  CXL   -> DRAM0    16.41 ± 0.07    20.89 ± 0.06    1.27x

kswapd demotion
---------------
Node 0 is limited to 16GB of free memory and demotion is enabled. A
single thread bound to node 0 writes 96GB of anonymous THP memory, so
~80GB has to be demoted to CXL.

                               base        patched
  kswapd CPU time              4.25 s      3.44 s     (-19%)
  kswapd CPU per GB demoted    63.6 ms     44.1 ms    (-31%)
  demoted by direct reclaim    14.1 GB     0.46 GB
  allocstall                   7427        370

With the patch, kswapd keeps up with the writer, so the writer rarely
falls back to direct reclaim.

MADV_COLLAPSE
-------------
The thread runs MADV_COLLAPSE on a 1GB tmpfs file (huge=within_size)
whose page cache is made of folios of one size. Time per 2MB collapse
in microseconds, mean ± stddev of 30 runs over three boots:

  folio size  base           patched
  4KB         234.0 ± 2.7    237.0 ± 2.3    (noise)
  64KB         95.2 ± 1.8     89.0 ± 0.8    (-6%)
  256KB        69.1 ± 1.6     62.7 ± 0.5    (-9%)
  1MB          68.2 ± 1.5     60.6 ± 0.3    (-11%)

hugetlb copy on write
---------------------
The thread writes to each hugetlb page of a MAP_PRIVATE mapping of a
populated hugetlb memfd, so each write takes a copy on write fault, at
the first or at the middle page of the folio. Copy throughput (GB/s,
mean ± stddev):

  page size  fault at  base           patched        speedup
  2MB        first     22.40 ± 0.23   33.46 ± 0.65   1.49x
  2MB        middle    22.76 ± 0.31   33.37 ± 0.64   1.47x
  1GB        first     27.10 ± 0.03   53.25 ± 0.59   1.96x
  1GB        middle    27.10 ± 0.03   53.35 ± 0.57   1.97x

The new copy order alone gives ~15% for 2MB pages and nothing for 1GB
pages; the rest comes from the single-call copy.

Changes in v4:
- Convert copy_user_large_folio() to copy page ranges with the new
  copy_mc_user_highpages(), and drop process_huge_page() and
  copy_user_gigantic_page() (David).
- Copy each folio with copy_mc_highpages() in collapse_file().
- Move the batching check and the single-call copy into
  copy_mc_can_batch() and __copy_mc_pages() (for copy_mc_user_highpages
  cleanups).
- Link to v3: https://lore.kernel.org/r/20261113-batpagecopy-v3-1-297f5b2fd28e@amd.com

Changes in v3:
- Copy the whole range with one copy_mc_to_kernel() call only when
  CONFIG_PREEMPTION is set, otherwise copy page by page with
  cond_resched(), following clear_contig_highpages() [1] (Pedro, David).
- Handle the machine check first in copy_mc_highpages() (Pedro).
- Rebase onto mm/core.git for-next.
- Link to v2: https://lore.kernel.org/r/20261019-batpagecopy-v2-1-d75e7d0dfaae@amd.com

[1] https://lore.kernel.org/r/20261109-clear-pages-batch-v3-1-6693efe18dff@amd.com

Changes in v2:
- Drop the folio_copy() changes as there is little to gain here.
  On architectures without copy_mc_to_kernel(), copy_mc_highpages()
  falls back to the per-page copy_mc_highpage(), which ends up in
  copy_highpage(). A batched copy_highpages() could help there too,
  but I haven't tested it on those architectures, so that is left for
  a follow-up.
- Add COPY_MC_PAGES_NON_PREEMPT_BATCH to limit how much is copied
  between cond_resched() calls on non-preemptible kernels.
- Rebase onto mm-new (2887e63d2e8e).
- v1: https://lore.kernel.org/all/20260427142036.111940-2-shivankg@amd.com

---
Shivank Garg (6):
      mm/highmem: introduce copy_mc_can_batch() and __copy_mc_pages()
      mm: introduce copy_mc_highpages() and batch copy in folio_mc_copy()
      mm/khugepaged: copy each folio with copy_mc_highpages() in collapse_file()
      mm/highmem: introduce copy_mc_user_highpages()
      mm: factor out the locality range computation from folio_zero_user()
      mm: copy_user_large_folio(): copy page ranges

 include/linux/highmem.h | 105 +++++++++++++++++++++++++++
 mm/khugepaged.c         |  14 ++--
 mm/memory.c             | 183 +++++++++++++++++-------------------------------
 mm/util.c               |  14 +---
 4 files changed, 176 insertions(+), 140 deletions(-)
---
base-commit: 89b4b2b15b2063e1bf593e609c3c63313b7ff160
base-tree: git://git.kernel.org/pub/scm/linux/kernel/git/mm/core.git for-next
change-id: 20260714-batpagecopy-5a2b45910e5d

Best regards,
--  
Shivank Garg <shivankg@amd.com>


             reply	other threads:[~2026-12-01  8:30 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  8:29 Shivank Garg [this message]
2026-12-01  8:29 ` [PATCH v4 1/6] mm/highmem: introduce copy_mc_can_batch() and __copy_mc_pages() Shivank Garg
2026-12-01  8:29 ` [PATCH v4 2/6] mm: introduce copy_mc_highpages() and batch copy in folio_mc_copy() Shivank Garg
2026-12-01  8:29 ` [PATCH v4 3/6] mm/khugepaged: copy each folio with copy_mc_highpages() in collapse_file() Shivank Garg
2026-12-01  8:29 ` [PATCH v4 4/6] mm/highmem: introduce copy_mc_user_highpages() Shivank Garg
2026-12-01  8:29 ` [PATCH v4 5/6] mm: factor out the locality range computation from folio_zero_user() Shivank Garg
2026-12-01  8:29 ` [PATCH v4 6/6] mm: copy_user_large_folio(): copy page ranges Shivank Garg

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=20261201-batpagecopy-v4-0-dd82a573e573@amd.com \
    --to=shivankg@amd.com \
    --cc=akpm@linux-foundation.org \
    --cc=ankur.a.arora@oracle.com \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=bharata@amd.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=david.laight.linux@gmail.com \
    --cc=david@kernel.org \
    --cc=dev.jain@arm.com \
    --cc=hpa@zytor.com \
    --cc=hsalunke@amd.com \
    --cc=kas@kernel.org \
    --cc=lance.yang@linux.dev \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=mhocko@suse.com \
    --cc=mingo@redhat.com \
    --cc=nhuhuan@google.com \
    --cc=nico.pache@linux.dev \
    --cc=peterz@infradead.org \
    --cc=pfalcato@suse.de \
    --cc=rientjes@google.com \
    --cc=rppt@kernel.org \
    --cc=ryan.roberts@arm.com \
    --cc=surenb@google.com \
    --cc=tejavojjala@google.com \
    --cc=tglx@kernel.org \
    --cc=torvalds@linuxfoundation.org \
    --cc=usama.arif@linux.dev \
    --cc=vbabka@kernel.org \
    --cc=x86@kernel.org \
    --cc=ying.huang@linux.alibaba.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

all inboxes | Powered by JetHome®