From: Xiaogang.Chen <xiaogang.chen@amd.com>
To: <amd-gfx@lists.freedesktop.org>
Cc: Xiaogang Chen <xiaogang.chen@amd.com>
Subject: [PATCH v5 0/3] drm/amdkfd: Enable device private memory THP support in kfd svm driver
Date: Sun, 22 Nov 2026 14:26:50 -0600 [thread overview]
Message-ID: <20261122202653.274580-1-xiaogang.chen@amd.com> (raw)
From: Xiaogang Chen <xiaogang.chen@amd.com>
Add device private THP support to migration in kfd driver by using following
work [1]. The implementation enables efficient migration of large folios
between system memory and device-private memory.
A benchmark test shows the migration speed got improved more than 5 times
comparing to current kfd/svm driver.
[1]https://lore.kernel.org/linux-mm/20251001065707.920170-1-balbirs@nvidia.com/
v2:
- Reset is_large each 4K page iteration
- Unmap the THP DMA mapping once as DMA mapping, at its real size
- Leave migrate->dst[i] zero when the source is not migrating
- Count THP migrations as HPAGE_PMD_NR pages in prange->vram_pages
- Implement folio_split and hold one svm_bo ref per subpage
v3:
- Do not migrate partial THP memory at CPU/GPU page fault handler
- re-configure compound device folio after it is release from core HMM.
So, it can be reused by ttm as 4K pages.
- Remove SDMA page entry FLAG(9) setting at GART page table since
not see noticelbe perofmance change.
v4: fix multiples issues from Claude code review
- Fill every dst slot when a device THP falls back to 4K RAM pages, and handle an out-of-range compound entry
If no THP destination could be allocated, only the head slot got a 4K page. migrate_vma_pages() then splits the source and dereferences every tail dst slot without a NULL check.
This happened on any failed THP allocation, and on every VMA with THP disabled. The new svm_migrate_compound_to_4k_ram()/svm_migrate_compound_to_4k_vram fills all 512 slots and
copies them with one GART copy.
Out-of-range entry in both copy directions, a compound entry that runs past npages now triggers WARN_ON_ONCE() and fails the window.
- Build with THP disabled: HPAGE_PMD_* expand to BUILD_BUG() without CONFIG_TRANSPARENT_HUGEPAGE. Define SVM_THP_ENABLED and SVM_HPAGE_PMD_* to control the build.
- Don't dereference the folio in svm_range_cpu_huge_folio_order()
The PMD was read without locks, and the code then called folio_order() on its folio with no reference. MADV_DONTNEED, deferred split or migration could free or
reuse that folio, which could make the migration window larger than intended.
Fix: a huge PMD always maps a PMD-order folio, so return SVM_HPAGE_PMD_ORDER without touching the folio.
- Get svm_bo from the folio head in svm_migrate_to_ram()(cpu page fault)
When a device THP's PMD has been split but the folio hasn't (partial munmap/mprotect/madvise, or a failed split_folio in migrate_vma_setup()), the CPU fault passes a tail page.
Only the head page has zone_device_data set, so on a tail page svm_bo was garbage and svm_bo->mm could oops.
Read it from page_folio(vmf->page), which is safe because the caller holds the folio lock and a reference
- Respect THP policy and check NULL in svm_migrate_get_sys_page()
Problem: the result of vma_alloc_folio() went into folio_page() with no NULL check. The order-9 allocation used GFP_HIGHUSER,
which means direct reclaim and compaction on every VRAM→RAM migration (fault, prefetch, eviction). It also ignored MADV_NOHUGEPAGE and PR_SET_THP_DISABLE.
Fix: check for NULL; skip THP when vma_thp_disabled() says so; allocate with GFP_TRANSHUGE_LIGHT, adding direct reclaim only for MADV_HUGEPAGE VMAs; Compile the THP path only with THP enabled.
- Reset device THP pages before dropping the svm_bo reference(race issue)
Problem: svm_migrate_folio_free() dropped the svm_bo reference first, then reset the 512 struct pages with svm_migrate_clear_compound_pages().
If that was the last reference, the VRAM could be freed and given to another range. A new zone_device_folio_init() on those pfns could then race
with the reset, which could wipe the tails of a newly created THP.
Fix: reset the pages first, while the folio still holds the BO alive.
v5:
- Rebase code on tip of amd-staging-drm-next branch which is based on kernel 7.2.0
Xiaogang Chen (3):
drm/amdkfd: Add awareness of THP of device and system RAM in kfd svm
driver
drm/amdkfd: Do not migrate partial THP memory at CPU/GPU page fault
handler
drm/amdkfd: Enable HMM device-private THP migration in KFD SVM driver
drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 642 +++++++++++++++++++++--
drivers/gpu/drm/amd/amdkfd/kfd_svm.c | 125 ++++-
drivers/gpu/drm/amd/amdkfd/kfd_svm.h | 30 ++
3 files changed, 732 insertions(+), 65 deletions(-)
--
2.34.1
next reply other threads:[~2026-11-22 20:26 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-22 20:26 Xiaogang.Chen [this message]
2026-11-22 20:26 ` [PATCH v5 1/3] drm/amdkfd: Add awareness of THP of device and system RAM in kfd svm driver Xiaogang.Chen
2026-11-22 20:49 ` sashiko-bot
2026-11-24 20:32 ` Philip Yang
2026-11-30 7:31 ` Chen, Xiaogang
2026-11-27 21:34 ` Philip Yang
2026-11-30 7:36 ` Chen, Xiaogang
2026-11-30 22:06 ` Philip Yang
2026-11-22 20:26 ` [PATCH v5 2/3] drm/amdkfd: Do not migrate partial THP memory at CPU/GPU page fault handler Xiaogang.Chen
2026-11-22 20:42 ` sashiko-bot
2026-11-22 20:26 ` [PATCH v5 3/3] drm/amdkfd: Enable HMM device-private THP migration in KFD SVM driver Xiaogang.Chen
2026-11-22 20:51 ` sashiko-bot
2026-11-27 23:23 ` Philip Yang
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=20261122202653.274580-1-xiaogang.chen@amd.com \
--to=xiaogang.chen@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.