Skip to content

Add MEMORY_DEVICE_COHERENT for coherent device memory mapping

Alex Sierra amd-gfx dri-devel linux-ext4 linux-mm linux-xfs 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest15 patches 9 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/15mm: add zone device coherent type memory supportinclude/linux/memremap.h mm/memcontrol.c mm/memory-failure.c +3 more+48 -152 replies
2/15mm: add device coherent vma selection for memory migrationinclude/linux/migrate.h mm/migrate_device.c+10 -30 replies
3/15mm: remove the vma check in migrate_vma_setup()mm/migrate_device.c+17 -170 replies
4/15mm: add device coherent checker to remove migration ptemm/migrate.c+2 -13 replies
5/15mm/gup: migrate device coherent pages when pinning instead of failingmm/gup.c mm/internal.h mm/migrate_device.c+96 -50 replies
6/15drm/amdkfd: add SPM support for SVMdrivers/gpu/drm/amd/amdkfd/kfd_migrate.c+17 -110 replies
7/15drm/amdkfd: coherent type as sys mem on migration to ramdrivers/gpu/drm/amd/amdkfd/kfd_migrate.c+4 -10 replies
8/15lib: test_hmm add ioctl to get zone device typelib/test_hmm.c lib/test_hmm_uapi.h+29 -20 replies
9/15lib: test_hmm add module param for zone device typelib/test_hmm.c lib/test_hmm_uapi.h+53 -210 replies
10/15lib: add support for device coherent type in test_hmmlib/test_hmm.c lib/test_hmm_uapi.h+202 -660 replies
11/15tools: update hmm-test to support device coherent typetools/testing/selftests/vm/hmm-tests.c+102 -210 replies
12/15tools: update test_hmm script to support SP configtools/testing/selftests/vm/test_hmm.sh+21 -30 replies
13/15mm: handling Non-LRU pages returned by vm_normal_pagesfs/proc/task_mmu.c include/linux/mm.h mm/gup.c +9 more+30 -173 replies
14/15tools: add hmm gup tests for device coherent typetools/testing/selftests/vm/hmm-tests.c+104 -01 reply
15/15tools: add selftests to hmm for COW in device memorytools/testing/selftests/vm/hmm-tests.c+80 -00 replies

Reviews trailers per patch

14 of 15 patches have a Reviewed-by or Acked-by.

PatchFelix KuehlingAlistair Popple
1/15A-b R-b
2/15A-b R-b
3/15A-b
4/15
5/15A-b
6/15R-b
7/15R-b
8/15A-b R-b
9/15A-b R-b
10/15A-b R-b
11/15A-b R-b
12/15A-b R-b
13/15A-b
14/15R-b
15/15A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH v1 00/15] Add MEMORY_DEVICE_COHERENT for coherent device memory mapping

This is our MEMORY_DEVICE_COHERENT patch series rebased and updated for current 5.18-rc5.

Changes since the last version:
- Fixed problems with migration during long-term pinning in get_user_pages
- Open coded vm_normal_lru_pages as suggested in previous code review
- Update hmm_gup_test with more get_user_pages calls, include hmm_cow_in_device in hmm-test.

This patch series introduces MEMORY_DEVICE_COHERENT, a type of memory owned by a device that can be mapped into CPU page tables like MEMORY_DEVICE_GENERIC and can also be migrated like MEMORY_DEVICE_PRIVATE.

This patch series is mostly self-contained except for a few places where it needs to update other subsystems to handle the new memory type.

System stability and performance are not affected according to our ongoing testing, including xfstests.

How it works: The system BIOS advertises the GPU device memory (aka VRAM) as SPM (special purpose memory) in the UEFI system address map.

The amdgpu driver registers the memory with devmap as MEMORY_DEVICE_COHERENT using devm_memremap_pages. The initial user for this hardware page migration capability is the Frontier supercomputer project. This functionality is not AMD-specific. We expect other GPU vendors to find this functionality useful, and possibly other hardware types in the future.

Our test nodes in the lab are similar to the Frontier configuration, with .5 TB of system memory plus 256 GB of device memory split across 4 GPUs, all in a single coherent address space. Page migration is expected to improve application efficiency significantly. We will report empirical results as they become available.

Coherent device type pages at gup are now migrated back to system memory if they are being pinned long-term (FOLL_LONGTERM). The reason is, that long-term pinning would interfere with the device memory manager owning the device-coherent pages (e.g. evictions in TTM). These series incorporate Alistair Popple patches to do this migration from pin_user_pages() calls. hmm_gup_test has been added to hmm-test to test different get user pages calls.

This series includes handling of device-managed anonymous pages returned by vm_normal_pages. Although they behave like normal pages for purposes of mapping in CPU page tables and for COW, they do not support LRU lists, NUMA migration or THP.

We also introduced a FOLL_LRU flag that adds the same behaviour to follow_page and related APIs, to allow callers to specify that they expect to put pages on an LRU list.

Alex Sierra (13):
mm: add zone device coherent type memory support
mm: add device coherent vma selection for memory migration
mm: add device coherent checker to remove migration pte drm/amdkfd: add SPM support for SVM
drm/amdkfd: coherent type as sys mem on migration to ram
lib: test_hmm add ioctl to get zone device type
lib: test_hmm add module param for zone device type
lib: add support for device coherent type in test_hmm
tools: update hmm-test to support device coherent type
tools: update test_hmm script to support SP config
mm: handling Non-LRU pages returned by vm_normal_pages
tools: add hmm gup tests for device coherent type
tools: add selftests to hmm for COW in device memory

Alistair Popple (2):
mm: remove the vma check in migrate_vma_setup()
mm/gup: migrate device coherent pages when pinning instead of failing

 drivers/gpu/drm/amd/amdkfd/kfd_migrate.c |  33 ++-
 fs/proc/task_mmu.c                       |   2 +-
 include/linux/memremap.h                 |  19 ++
 include/linux/migrate.h                  |   1 +
 include/linux/mm.h                       |   3 +-
 lib/test_hmm.c                           | 349 +++++++++++++++++------
 lib/test_hmm_uapi.h                      |  22 +-
 mm/gup.c                                 |  49 +++-
 mm/huge_memory.c                         |   2 +-
 mm/internal.h                            |   1 +
 mm/khugepaged.c                          |   9 +-
 mm/ksm.c                                 |   6 +-
 mm/madvise.c                             |   4 +-
 mm/memcontrol.c                          |   7 +-
 mm/memory-failure.c                      |   8 +-
 mm/memory.c                              |   9 +-
 mm/mempolicy.c                           |   2 +-
 mm/memremap.c                            |  10 +
 mm/migrate.c                             |   7 +-
 mm/migrate_device.c                      | 115 ++++++--
 mm/mlock.c                               |   2 +-
 mm/mprotect.c                            |   2 +-
 mm/rmap.c                                |   3 +-
 tools/testing/selftests/vm/hmm-tests.c   | 307 ++++++++++++++++++--
 tools/testing/selftests/vm/test_hmm.sh   |  24 +-
 25 files changed, 814 insertions(+), 182 deletions(-)
Signature · 1 line
2.32.0