DMA Engine development
 help / color / mirror / Atom feed
From: Daniel Byrne <daniel1.byrne@intel.com>
To: Shivank Garg <shivankg@amd.com>,
	Ravi Jonnalagadda <ravis.opensrc@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	David Hildenbrand <david@kernel.org>, Zi Yan <ziy@nvidia.com>,
	Matthew Brost <matthew.brost@intel.com>,
	Joshua Hahn <joshua.hahnjy@gmail.com>,
	Rakie Kim <rakie.kim@sk.com>, Byungchul Park <byungchul@sk.com>,
	Gregory Price <gourry@gourry.net>,
	Ying Huang <ying.huang@linux.alibaba.com>,
	Alistair Popple <apopple@nvidia.com>,
	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>,
	Karim Manaouil <kmanaouil.dev@gmail.com>,
	Frank van der Linden <fvdl@google.com>,
	Teja Vojjala <tejavojjala@google.com>,
	Pravin Tamkhane <pravintamkhane@google.com>,
	Kinsey Ho <kinseyho@google.com>, Wei Xu <weixugc@google.com>,
	Matthew Wilcox <willy@infradead.org>,
	Davidlohr Bueso <dave@stgolabs.net>,
	Vinod Koul <vkoul@kernel.org>, Bharata B Rao <bharata@amd.com>,
	SeongJae Park <sj@kernel.org>,
	David Rientjes <rientjes@google.com>,
	Xuezheng Chu <xuezhengchu@huawei.com>,
	Yiannis Nikolakopoulos <yiannis@zptcorp.com>,
	Dave Hansen <dave.hansen@intel.com>,
	Johannes Weiner <hannes@cmpxchg.org>,
	John Hubbard <jhubbard@nvidia.com>, Peter Xu <peterx@redhat.com>,
	Rik van Riel <riel@surriel.com>,
	Shakeel Butt <shakeel.butt@linux.dev>, Tejun Heo <tj@kernel.org>,
	Fan Ni <nifan.cxl@gmail.com>, Jonathan Cameron <jic23@kernel.org>,
	"Aneesh Kumar K.V" <aneesh.kumar@kernel.org>,
	Nathan Lynch <nathan.lynch@amd.com>, Frank Li <Frank.li@nxp.com>,
	Dan Williams <djbw@kernel.org>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Mike Day <michael.day@amd.com>,
	dmaengine@vger.kernel.org,
	Vinicius Costa Gomes <vinicius.gomes@intel.com>,
	Frank Li <Frank.Li@kernel.org>, Dave Jiang <dave.jiang@intel.com>,
	Daniel Byrne <daniel1.byrne@intel.com>
Subject: [RFC PATCH 00/10] mm/migrate: dcbm for Intel DSA, on top of the batch copy offload RFC v6
Date: Tue,  1 Dec 2026 06:12:49 -0800	[thread overview]
Message-ID: <20261201141259.2124188-1-daniel1.byrne@intel.com> (raw)

This is my implementation of dcbm for Intel DSA, on top of RFC v6 of
"Accelerate page migration with batch copying and hardware offload" [1].
It is for reference and for testing next to Ravi's report on v6 [2]. It
is not meant to be merged as it is. The first four patches are
Shivank's, and the rest is meant to be taken into v7 where it can fit.

What this RFC contains:
 - Patches 1 to 4 are patches 1 to 4 of RFC v6, rebased to v7.4-rc2
   with no other change, so that the series applies. Patch 1 applies as
   posted. Patches 2 to 4 are rebased, and every line they change is as
   in the posting.
 - Patches 5 to 7 are fixes to those four, meant to be folded in:
    5. FOLIO_CONTENT_COPIED is bit 2 of the word in which hugetlb keeps
       HPG_temporary, so a surplus hugetlb destination reads as already
       copied and its copy is skipped. This loses the data, with or
       without an offload driver, see "Testing". The marker gets a bit
       of its own on hugetlb, behind two helpers;
    6. a folio with private data, or with a migrate_folio() callback of
       its own, stays off the batch copy, since a copy made ahead of the
       move phase bypasses what those rely on;
    7. the provider is called with the folios of the batch locked, so it
       runs in a NOFS scope.
 - Patches 8 and 9 add to dmaengine what patch 10 uses: DMA_MEMCPY_SG
   again, and a prep flag for the provider's cache-control hint.
 - Patch 10 makes dcbm work on a provider that is shared and completes
   out of order, as DSA does:
    - every descriptor has its own completion, counted down on a
      pending counter, and an error result sends the folio to the CPU
      copy;
    - the channels are requested once, when offloading is enabled, and
      held. Concurrent batches share them through per-channel trylocks,
      and a batch that finds every channel busy is copied on the CPU;
    - source and destination are mapped per folio and paired by folio,
      without scatterlists that have to merge alike on both sides;
    - a batch keeps a bounded number of descriptors in flight on a
      channel, since a work queue has a fixed pool of them;
    - no timeout and no terminate. terminate_all acts on the whole
      channel and would end the other batches on it;
    - on a provider with DMA_MEMCPY_SG a slice goes out as
      scatter-gather transactions, and the copies ask for the
      cache-control hint unless a module parameter turns it off.

Against the three topics of Ravi's report [2]:

1. Channel lifetime. Patch 10 holds the channels. A provider that goes
   away under them is not handled in this series. That needs the
   dmaengine side first. I have a series for it that is not posted yet:
   the core marks a channel that its provider removes under clients as
   detached, the channel takes no new work, and the client releases it
   when it sees dma_chan_detached(). It builds on the two helpers of
   [3]. The dcbm side that releases such a channel follows with it.

2. Completion order. Patch 10 counts every descriptor on every
   provider and does not test DMA_COMPLETION_NO_ORDER. That capability
   goes away in my polled-status series [4], whose v2 is in
   preparation. With it a client can also wait for a descriptor by its
   cookie, and a descriptor without DMA_PREP_INTERRUPT no longer stays
   allocated on DSA.

3. Timeouts and failed channels. Patch 10 only waits. What I am working
   on beyond it is not in this series: a device whose completions are
   overdue takes no new work until everything out on it has landed, and
   the CPU copies meanwhile. NUMA hinting faults stay out of the offload
   by default there.

Also not in this RFC - the idxd side of patches 8 and 9, which turns a
scatter-gather transaction into one DSA batch descriptor and supports the
cache-control flag. It needs my idxd fixes, of which the third part is
not posted yet. Without it patch 10 uses one descriptor per folio on
DSA.

Testing:

The series ran on an Intel CPU with DSA and two NUMA nodes, on v7.4-rc2
with the idxd driver as it is there. Four DSA devices of one node had
four shared work queues each, which gives 16 dmaengine channels. The
load was move_pages() between the two nodes, and every run compared the
data with its pattern afterwards. The comparisons below are between
the rates of the move_pages() calls:
 - 2 MiB folios, one thread: dcbm is 5-6 times as fast as the CPU
   copy, on 1, 4 and 16 channels alike
 - 4 KiB folios, one thread: dcbm is about 1/3 slower than the CPU
   copy. Small folios are better left to the CPU, as in Ravi's report
 - batches of 2 MiB and 4 KiB folios together, on 4 channels and on 1
 - 2 MiB folios with 8 and 32 threads on 16 channels: about 4 and 5
   times the rate of one thread. With 32 threads about a fifth of the
   folios found every channel busy and were copied on the CPU. With 8
   threads on one channel about half of them were
 - offloading switched off and on ten times under four threads of load,
   with another channel count each time, and the module unloaded and
   loaded again
 - anonymous and shared hugetlb folios, to surplus destinations and to
   pool pages (patch 5)
 - the page cache of an ext4 file, clean and dirtied through the
   mapping. None of its folios went through dcbm (patch 6)

No page was left behind, no data differed, and the kernel log stayed
clean. The same patches were tested on a kernel with KASAN, lockdep,
DMA-API debugging and DEBUG_ATOMIC_SLEEP, with the same result and no
report.

For patch 5 a kernel with patches 1 to 4 only ran the hugetlb part, with
the dcbm module not loaded. It moved 1 GiB of anonymous hugetlb pages to
surplus destinations about 40 times faster than a move that copies them,
and every word of it differed afterwards. With patch 5 the data remains
the same.

I did not run a provider that goes away under the held channels, and a
channel that fails or times out. The series handles neither.

[1] https://lore.kernel.org/all/20260630-shivank-batch-migrate-offload-v6-0-da95d7e8b8a2@amd.com/
[2] https://lore.kernel.org/all/20261128224616.66122-1-ravis.opensrc@gmail.com/
[3] https://lore.kernel.org/r/20261130195203.1901143-1-daniel1.byrne@intel.com
[4] https://lore.kernel.org/dmaengine/20261019150632.4026424-1-daniel1.byrne@intel.com/

Tools:

I used Claude Opus/Fable model to review (sashiko and local reviews)
the code, suggest fixes, and edit the changelogs. I also used it to
run the builds and the test rounds described above. I reviewed the
results and fixes it suggested and I am responsible for them.

Daniel Byrne (6):
  mm/migrate: give hugetlb its own bit for the content-copied marker
  mm/migrate: keep folios with private data off the batch copy
  mm/migrate: no filesystem reclaim under the batch's folio locks
  dmaengine: reintroduce DMA_MEMCPY_SG
  dmaengine: add DMA_PREP_CACHE_CONTROL
  drivers/migrate_offload: make dcbm correct on shared, out-of-order
    engines

Shivank Garg (4):
  mm/migrate: skip data copy for already-copied folios
  mm/migrate: add batch-copy path in migrate_pages_batch
  mm/migrate: add copy offload registration infrastructure
  drivers/migrate_offload: add DMA batch copy driver (dcbm)

 .../driver-api/dmaengine/provider.rst         |  10 +
 MAINTAINERS                                   |   2 +
 drivers/Kconfig                               |   2 +
 drivers/Makefile                              |   2 +
 drivers/dma/dmaengine.c                       |   1 +
 drivers/migrate_offload/Kconfig               |   9 +
 drivers/migrate_offload/Makefile              |   1 +
 drivers/migrate_offload/dcbm/Makefile         |   1 +
 drivers/migrate_offload/dcbm/dcbm.c           | 785 ++++++++++++++++++
 include/linux/dmaengine.h                     |  24 +
 include/linux/migrate.h                       |  84 ++
 include/linux/migrate_copy_offload.h          |  69 ++
 mm/Kconfig                                    |   6 +
 mm/Makefile                                   |   1 +
 mm/migrate.c                                  | 160 +++-
 mm/migrate_copy_offload.c                     | 258 ++++++
 16 files changed, 1383 insertions(+), 32 deletions(-)
 create mode 100644 drivers/migrate_offload/Kconfig
 create mode 100644 drivers/migrate_offload/Makefile
 create mode 100644 drivers/migrate_offload/dcbm/Makefile
 create mode 100644 drivers/migrate_offload/dcbm/dcbm.c
 create mode 100644 include/linux/migrate_copy_offload.h
 create mode 100644 mm/migrate_copy_offload.c


base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
-- 
2.43.0


             reply	other threads:[~2026-12-01 14:19 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 14:12 Daniel Byrne [this message]
2026-12-01 14:12 ` [RFC PATCH 01/10] mm/migrate: skip data copy for already-copied folios Daniel Byrne
2026-12-01 14:12 ` [RFC PATCH 02/10] mm/migrate: add batch-copy path in migrate_pages_batch Daniel Byrne
2026-12-01 14:12 ` [RFC PATCH 03/10] mm/migrate: add copy offload registration infrastructure Daniel Byrne
2026-12-01 14:12 ` [RFC PATCH 04/10] drivers/migrate_offload: add DMA batch copy driver (dcbm) Daniel Byrne
2026-12-01 14:12 ` [RFC PATCH 05/10] mm/migrate: give hugetlb its own bit for the content-copied marker Daniel Byrne
2026-12-01 14:12 ` [RFC PATCH 06/10] mm/migrate: keep folios with private data off the batch copy Daniel Byrne
2026-12-01 14:12 ` [RFC PATCH 07/10] mm/migrate: no filesystem reclaim under the batch's folio locks Daniel Byrne
2026-12-01 14:12 ` [RFC PATCH 08/10] dmaengine: reintroduce DMA_MEMCPY_SG Daniel Byrne
2026-12-01 14:12 ` [RFC PATCH 09/10] dmaengine: add DMA_PREP_CACHE_CONTROL Daniel Byrne
2026-12-01 14:12 ` [RFC PATCH 10/10] drivers/migrate_offload: make dcbm correct on shared, out-of-order engines Daniel Byrne

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=20261201141259.2124188-1-daniel1.byrne@intel.com \
    --to=daniel1.byrne@intel.com \
    --cc=Frank.Li@kernel.org \
    --cc=Frank.li@nxp.com \
    --cc=akpm@linux-foundation.org \
    --cc=aneesh.kumar@kernel.org \
    --cc=apopple@nvidia.com \
    --cc=bharata@amd.com \
    --cc=byungchul@sk.com \
    --cc=dave.hansen@intel.com \
    --cc=dave.jiang@intel.com \
    --cc=dave@stgolabs.net \
    --cc=david@kernel.org \
    --cc=djbw@kernel.org \
    --cc=dmaengine@vger.kernel.org \
    --cc=fvdl@google.com \
    --cc=gourry@gourry.net \
    --cc=hannes@cmpxchg.org \
    --cc=jhubbard@nvidia.com \
    --cc=jic23@kernel.org \
    --cc=joshua.hahnjy@gmail.com \
    --cc=kinseyho@google.com \
    --cc=kmanaouil.dev@gmail.com \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=matthew.brost@intel.com \
    --cc=mhocko@suse.com \
    --cc=michael.day@amd.com \
    --cc=nathan.lynch@amd.com \
    --cc=nifan.cxl@gmail.com \
    --cc=peterx@redhat.com \
    --cc=pravintamkhane@google.com \
    --cc=rakie.kim@sk.com \
    --cc=ravis.opensrc@gmail.com \
    --cc=riel@surriel.com \
    --cc=rientjes@google.com \
    --cc=rppt@kernel.org \
    --cc=shakeel.butt@linux.dev \
    --cc=shivankg@amd.com \
    --cc=sj@kernel.org \
    --cc=surenb@google.com \
    --cc=tejavojjala@google.com \
    --cc=tj@kernel.org \
    --cc=vbabka@kernel.org \
    --cc=vinicius.gomes@intel.com \
    --cc=vkoul@kernel.org \
    --cc=weixugc@google.com \
    --cc=willy@infradead.org \
    --cc=xuezhengchu@huawei.com \
    --cc=yiannis@zptcorp.com \
    --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