The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Ravi Jonnalagadda <ravis.opensrc@gmail.com>
To: Shivank Garg <shivankg@amd.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>
Subject: Re: [PATCH RFC v6 4/5] drivers/migrate_offload: add DMA batch copy driver (dcbm)
Date: Sat, 28 Nov 2026 14:59:43 -0800	[thread overview]
Message-ID: <20261128225943.66318-1-ravis.opensrc@gmail.com> (raw)
In-Reply-To: <20260630-shivank-batch-migrate-offload-v6-4-da95d7e8b8a2@amd.com>

On Tue, 30 Jun 2026 07:28:40 +0000, Shivank Garg wrote:
> Add a simple DMAEngine-based migrator that plugs into the page
> migration copy-offload infrastructure and batch-copies folios via
> DMA memcpy channels. It is intended for testing the offload plumbing
> and as a template for future migrators (SDXI, multi-threaded CPU copy,
> etc.).

Hi Shivank,

Following my test report in reply to the cover letter [1], below are
the code-level findings on dcbm.c. They cover completion ordering,
channel lifetime and fault recovery, each with a design question.

The setup, the configurations compared and all results are in [1].
Each section below names the result it explains and refers to [1]
for the numbers.

1. Completion ordering on out-of-order channels (Intel DSA)
-----------------------------------------------------------
> + if (i == work->src_sgt->nents - 1) {
> + tx->callback = dma_completion_callback;
> + tx->callback_param = work;
> + }

What I saw ([1], section 2):
- On DSA, the last descriptor's callback ran while earlier copies in
  the same channel list were still in flight.
- On a 4 KiB demotion run, the DSA work queue filled up and migration
  blocked.
- Counting completion on every descriptor (the diff below) removed
  both.

Where it comes from:
- submit_dma_transfers() sets DMA_PREP_INTERRUPT and
  dma_completion_callback only on the last descriptor of each
  channel's scatter-gather list.
- On ordered engines such as SDXI v4, that is enough. The driver
  appends a fenced interrupt descriptor when DMA_PREP_INTERRUPT is
  set, so the last callback implies the earlier descriptors are done.
- Intel DSA advertises DMA_COMPLETION_NO_ORDER (Karim's v5 point [2]).
  Trailing 4 KiB copies can finish, and run the callback, while an
  earlier 2 MiB THP copy is still in flight.
- The DSA driver also frees a software descriptor on normal completion
  only when it was prepared with DMA_PREP_INTERRUPT. Without it, the
  work queue fills up.
- The diff below requests an interrupt and counts every descriptor on
  DMA_COMPLETION_NO_ORDER channels:
  * work->pending reserves one count for the last descriptor;
  * it is incremented before each earlier descriptor is submitted;
  * ordered engines still get a single interrupt per channel list.

  @@ -173,14 +173,19 @@ static int submit_dma_transfers(struct dma_work *work)
    struct dma_async_tx_descriptor *tx;
    unsigned long flags = DMA_CTRL_ACK;
    dma_cookie_t cookie;
  + bool no_order, last;
    int i;

  + /* Last-descriptor callback covers earlier ones only on ordered channels. */
  + no_order = dma_has_cap(DMA_COMPLETION_NO_ORDER,
  +       work->chan->device->cap_mask);
    atomic_set(&work->pending, 1);

    sg_src = work->src_sgt->sgl;
    sg_dst = work->dst_sgt->sgl;
    for_each_sgtable_dma_sg(work->src_sgt, sg_src, i) {
  - if (i == work->src_sgt->nents - 1)
  + last = i == work->src_sgt->nents - 1;
  + if (last || no_order)
    flags |= DMA_PREP_INTERRUPT;

    tx = dmaengine_prep_dma_memcpy(work->chan,
  @@ -192,7 +197,9 @@ static int submit_dma_transfers(struct dma_work *work)
    return -EIO;
    }

  - if (i == work->src_sgt->nents - 1) {
  + if (last || no_order) {
  + if (!last)
  + atomic_inc(&work->pending);
    tx->callback = dma_completion_callback;
    tx->callback_param = work;
    }

Question: would you include this check in v7 to handle unordered
providers (Intel DSA) until device_prep_dma_memcpy_sg() lands, while
keeping a single interrupt per channel list on ordered providers?

2. Per-batch channel allocation vs. holding channels across batches
-------------------------------------------------------------------
> + max_channels = min3(READ_ONCE(nr_dma_channels), nr_folios,
> +    (unsigned int)MAX_DMA_CHANNELS);

[...]

> + for (i = 0; i < max_channels; i++) {
> + works[actual_channels].chan = dma_request_chan_by_mask(&mask);
> + if (IS_ERR(works[actual_channels].chan))

[...]

> + dma_release_channel(works[i].chan);

What I saw ([1], section 1):
- On SDXI, v6 is slower than CPU copy for move_pages() of THPs, and
  slower on 8 channels than on 1 for DAMON migrate_cold.
- On SDXI NUMA hint faults, v6 makes each promoting fault slower than
  CPU copy.
- On SDXI unbind under load, v6 warned in every run.
- Holding channels while offloading is enabled removed all three.

Where it comes from:
- Each batch requests and releases up to nr_dma_chan channels. The
  count is capped by the number of folios (min3() above), and the
  folios are split across the channels.
- On SDXI v4, each request and release starts and stops a hardware
  context.
- move_pages() and hint faults pass one folio per batch. So they pay
  a context start and stop for every folio.
- On 8 channels, dma_request_chan_by_mask() plus dma_release_channel()
  take 23-25 % of the time inside migrate_pages() on DAMON batches
  (4 % on 1 channel). That accounts for the whole 1 -> 8 drop.
- Requesting channels per batch does not avoid provider removal. The
  v6 unbind runs showed two kinds of WARN:
  * dma_request_chan_by_mask() in the loop above reached
    sdxi_dma_alloc_chan_resources() while the provider was being torn
    down, and its unwind hit an ida_free WARN;
  * a batch still held its channel when the provider unregistered it
    ("__dma_async_device_channel_unregister called while 1 clients
    hold a reference").
- So with either channel model, the client has to stop using a
  provider's channels before the provider unbinds (or, on DSA, before
  an idxd work queue is disabled). The DMAengine core has no removal
  callback that tells it to.
- My prototype handles this on the client side:
  * it acquires channels at enable time with a provider filter;
  * it registers BUS_NOTIFY_UNBIND_DRIVER notifiers on the provider
    and child buses;
  * the notifier drops a provider's channels after in-flight batches
    finish (with your dma_chan_put() fixes [3]).

  chan = dma_request_channel(mask, dcbm_chan_filter, NULL);

  case BUS_NOTIFY_UNBIND_DRIVER:
  dcbm_drop_dev(dev, true);
  break;

Question: since dcbm needs to handle provider removal with either
channel model, would you and Vinod prefer a DMAengine core callback
that notifies channel holders before channel unregister / work-queue
disable, or client-side bus notifiers in dcbm as above?

3. Timeouts, faulted channel recovery and CPU fallback policy
-------------------------------------------------------------
> + if (works[i].mapped)
> + dmaengine_terminate_sync(works[i].chan);

What I saw ([1], section 3):
- On SDXI, a faulted descriptor makes every later batch on its
  channel wait out the timeout.
- With several failed channels, v6's one-by-one cleanup adds a drain
  per channel and led to hung-task reports.
- Replacing failed channels and draining them in parallel kept rounds
  near 20 s.
- On the NUMA hint-fault path, one faulted descriptor still stalls
  every faulting task for about 20 s.

Where it comes from:
- After an SDXI address fault, the context stops before the trailing
  interrupt descriptor, so the callback never runs.
- tx_status() reports DMA_ERROR 0.1-0.2 ms after submission. dcbm does
  not poll it, and waits for wait_for_completion_timeout() to expire
  (10 s).
- A faulted channel kept in the pool repeats that wait for every
  batch sent to it. A 1 GiB move_pages() call is 512 single-THP
  batches, round-robin over 16 channels, so 32 of them land on the
  dead channel. The first waits 10 s; each later one waits 10 s plus a
  10 s drain: about 645 s per call.
- In v6, cleanup_dma_work() then calls dmaengine_terminate_sync() on
  each affected channel in turn:
  * each waits up to 10 s in sdxi_dma_synchronize();
  * 16 failed channels cost 130 s;
  * when the whole function has stopped, the channel releases that
    follow also run one by one, about 2.4 s each.
- Calling dmaengine_terminate_async() on all failed channels, and
  running their dmaengine_synchronize() in parallel, overlaps the
  drains into one 10 s window. The work runs on a WQ_MEM_RECLAIM
  workqueue, so it is safe when dcbm is called from kswapd on
  demotion.
- dma_release_channel() is deferred to a background work item. The
  same work item re-requests replacement channels (the refill).
- When the refill gets back fewer channels than it released, offloading
  is marked degraded and batches use CPU copy:

  /* Fewer channels re-acquired than failed channels just released. */
  if (dcbm_nr_chans - nr < replaced) {
  dcbm_degraded = true;

- A refill shortfall has two possible causes:
  * the provider function is in an error state;
  * another DMAengine client took the freed channels during the
    refill.
- I forced the refill to fail on a healthy function (3 runs each):
  * Without the degraded mode: dcbm carried on with 15 of 16
    channels at the same rate.
  * With the degraded mode: dcbm went to CPU copy until offloading
    was re-enabled.
- On the hint-fault path, the faulted channel stays in the round-robin
  until its first timeout. Each faulting task's next single-folio
  batch lands on it, and waits the 10 s timeout plus a 10 s drain.

Question: when failed channels cannot be replaced after a timeout,
which should dcbm do?
- Stay on CPU fallback until offloading is re-enabled.
- Carry on with the channels it still holds, and retry with a backoff.
- Rely on error reporting from the provider, so it can tell a failed
  function from a busy one without waiting out the 10 s timeout.

And should MR_NUMA_MISPLACED stay out of offload until failures are
detected sooner, for example through a copy-engine choice carried in
migrate_control, as your migration refactor RFC suggested?

Thanks,
Ravi

[1] https://lore.kernel.org/all/20261128224616.66122-1-ravis.opensrc@gmail.com/
[2] https://lore.kernel.org/all/20260619160725.lfcxrbj5go67qy6u@wrangler/
[3] https://lore.kernel.org/all/20260822-dmaengine-kref-fix-v5-0-d4a4ee47d927@amd.com/

  reply	other threads:[~2026-11-28 22:59 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-30  7:28 [PATCH RFC v6 0/5] Accelerate page migration with batch copying and hardware offload Shivank Garg
2026-06-30  7:28 ` [PATCH RFC v6 1/5] mm/migrate: skip data copy for already-copied folios Shivank Garg
2026-06-30  7:28 ` [PATCH RFC v6 2/5] mm/migrate: add batch-copy path in migrate_pages_batch Shivank Garg
2026-06-30  7:28 ` [PATCH RFC v6 3/5] mm/migrate: add copy offload registration infrastructure Shivank Garg
2026-07-20 11:19   ` Huang, Ying
2026-07-20 14:44     ` Zi Yan
2026-07-20 15:32       ` Garg, Shivank
2026-07-20 15:45         ` Zi Yan
2026-07-21 11:32       ` Huang, Ying
2026-06-30  7:28 ` [PATCH RFC v6 4/5] drivers/migrate_offload: add DMA batch copy driver (dcbm) Shivank Garg
2026-11-28 22:59   ` Ravi Jonnalagadda [this message]
2026-11-28 23:12     ` Ravi Jonnalagadda
2026-06-30  7:28 ` [PATCH RFC v6 5/5] mm/migrate: adjust NR_MAX_BATCHED_MIGRATION for testing Shivank Garg
2026-07-14 11:29 ` [PATCH RFC v6 0/5] Accelerate page migration with batch copying and hardware offload Huang, Ying
2026-11-28 22:46 ` Ravi Jonnalagadda

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=20261128225943.66318-1-ravis.opensrc@gmail.com \
    --to=ravis.opensrc@gmail.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@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=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