← Documents Documentation/gpu/rfc/gpusvm.rst GitHub 원문 ↗

Linux 6.18.37 · GPU·DRM·RFC

GPU SVM Section

GPU SVM migration·eviction·fault locking 원칙과 미래 확장을 설명합니다.

Source pathDocumentation/gpu/rfc/gpusvm.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약·해설

gpusvm.rst:1-118

GPU SVM migration·eviction·fault locking 원칙과 미래 확장을 설명합니다.

문서 위치
항목
SourceDocumentation/gpu/rfc/gpusvm.rst
분량118 source lines
관련drm_gpusvm.c · drm_pagemap.c · migrate_to_ram

Source와 관련 개념입니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

원문 전체 펼치기
1 .. SPDX-License-Identifier: (GPL-2.0+ OR MIT)
2
3 ===============
4 GPU SVM Section
5 ===============
6
7 Agreed upon design principles
8 =============================
9
10 * migrate_to_ram path
11 * Rely only on core MM concepts (migration PTEs, page references, and
12 page locking).
13 * No driver specific locks other than locks for hardware interaction in
14 this path. These are not required and generally a bad idea to
15 invent driver defined locks to seal core MM races.
16 * An example of a driver-specific lock causing issues occurred before
17 fixing do_swap_page to lock the faulting page. A driver-exclusive lock
18 in migrate_to_ram produced a stable livelock if enough threads read
19 the faulting page.
20 * Partial migration is supported (i.e., a subset of pages attempting to
21 migrate can actually migrate, with only the faulting page guaranteed
22 to migrate).
23 * Driver handles mixed migrations via retry loops rather than locking.
24 * Eviction
25 * Eviction is defined as migrating data from the GPU back to the
26 CPU without a virtual address to free up GPU memory.
27 * Only looking at physical memory data structures and locks as opposed to
28 looking at virtual memory data structures and locks.
29 * No looking at mm/vma structs or relying on those being locked.
30 * The rationale for the above two points is that CPU virtual addresses
31 can change at any moment, while the physical pages remain stable.
32 * GPU page table invalidation, which requires a GPU virtual address, is
33 handled via the notifier that has access to the GPU virtual address.
34 * GPU fault side
35 * mmap_read only used around core MM functions which require this lock
36 and should strive to take mmap_read lock only in GPU SVM layer.
37 * Big retry loop to handle all races with the mmu notifier under the gpu
38 pagetable locks/mmu notifier range lock/whatever we end up calling
39 those.
40 * Races (especially against concurrent eviction or migrate_to_ram)
41 should not be handled on the fault side by trying to hold locks;
42 rather, they should be handled using retry loops. One possible
43 exception is holding a BO's dma-resv lock during the initial migration
44 to VRAM, as this is a well-defined lock that can be taken underneath
45 the mmap_read lock.
46 * One possible issue with the above approach is if a driver has a strict
47 migration policy requiring GPU access to occur in GPU memory.
48 Concurrent CPU access could cause a livelock due to endless retries.
49 While no current user (Xe) of GPU SVM has such a policy, it is likely
50 to be added in the future. Ideally, this should be resolved on the
51 core-MM side rather than through a driver-side lock.
52 * Physical memory to virtual backpointer
53 * This does not work, as no pointers from physical memory to virtual
54 memory should exist. mremap() is an example of the core MM updating
55 the virtual address without notifying the driver of address
56 change rather the driver only receiving the invalidation notifier.
57 * The physical memory backpointer (page->zone_device_data) should remain
58 stable from allocation to page free. Safely updating this against a
59 concurrent user would be very difficult unless the page is free.
60 * GPU pagetable locking
61 * Notifier lock only protects range tree, pages valid state for a range
62 (rather than seqno due to wider notifiers), pagetable entries, and
63 mmu notifier seqno tracking, it is not a global lock to protect
64 against races.
65 * All races handled with big retry as mentioned above.
66
67 Overview of baseline design
68 ===========================
69
70 .. kernel-doc:: drivers/gpu/drm/drm_gpusvm.c
71 :doc: Overview
72
73 .. kernel-doc:: drivers/gpu/drm/drm_gpusvm.c
74 :doc: Locking
75
76 .. kernel-doc:: drivers/gpu/drm/drm_gpusvm.c
77 :doc: Partial Unmapping of Ranges
78
79 .. kernel-doc:: drivers/gpu/drm/drm_gpusvm.c
80 :doc: Examples
81
82 Overview of drm_pagemap design
83 ==============================
84
85 .. kernel-doc:: drivers/gpu/drm/drm_pagemap.c
86 :doc: Overview
87
88 .. kernel-doc:: drivers/gpu/drm/drm_pagemap.c
89 :doc: Migration
90
91 Possible future design features
92 ===============================
93
94 * Concurrent GPU faults
95 * CPU faults are concurrent so makes sense to have concurrent GPU
96 faults.
97 * Should be possible with fined grained locking in the driver GPU
98 fault handler.
99 * No expected GPU SVM changes required.
100 * Ranges with mixed system and device pages
101 * Can be added if required to drm_gpusvm_get_pages fairly easily.
102 * Multi-GPU support
103 * Work in progress and patches expected after initially landing on GPU
104 SVM.
105 * Ideally can be done with little to no changes to GPU SVM.
106 * Drop ranges in favor of radix tree
107 * May be desirable for faster notifiers.
108 * Compound device pages
109 * Nvidia, AMD, and Intel all have agreed expensive core MM functions in
110 migrate device layer are a performance bottleneck, having compound
111 device pages should help increase performance by reducing the number
112 of these expensive calls.
113 * Higher order dma mapping for migration
114 * 4k dma mapping adversely affects migration performance on Intel
115 hardware, higher order (2M) dma mapping should help here.
116 * Build common userptr implementation on top of GPU SVM
117 * Driver side madvise implementation and migration policies
118 * Pull in pending dma-mapping API changes from Leon / Nvidia when these land
119

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

GPU SVM 합의 설계 원칙

1-77

`migrate_to_ram` 경로는 migration PTE, page reference, page locking 같은 core MM 개념에만 의존합니다. Hardware interaction용 lock 외에 driver-specific lock을 두지 않습니다. Core MM race를 막기 위해 driver lock을 새로 만드는 것은 불필요하고 대체로 잘못된 접근입니다.

과거 `do_swap_page`가 faulting page를 lock하도록 고치기 전, `migrate_to_ram`의 driver-exclusive lock은 충분한 thread가 faulting page를 읽을 때 안정적인 livelock을 만들었습니다. Migration은 일부 page만 성공하는 partial migration을 허용하며 faulting page만 migration이 보장됩니다. Mixed migration은 lock이 아니라 retry loop로 처리합니다.

Eviction은 GPU memory를 비우기 위해 virtual address 없이 GPU의 data를 CPU 쪽으로 migration하는 작업입니다. Virtual memory structure·lock이 아니라 physical memory structure·lock만 봅니다. CPU virtual address는 언제든 바뀌지만 physical page는 안정적이기 때문입니다. GPU virtual address가 필요한 GPU page-table invalidation은 그 주소를 가진 notifier가 처리합니다.

GPU fault 쪽에서는 `mmap_read`를 요구하는 core MM function 주변에서만 이 lock을 사용하고 가능하면 GPU SVM layer에서만 획득합니다. GPU page-table lock과 MMU notifier range lock 아래의 race는 큰 retry loop로 처리합니다.

Concurrent eviction이나 `migrate_to_ram` race를 fault handler가 추가 lock으로 막지 않습니다. 가능한 예외는 최초 VRAM migration 동안 BO의 `dma-resv` lock을 잡는 경우입니다. 이 lock은 잘 정의되어 있고 `mmap_read` 아래에서 획득할 수 있습니다.

GPU access는 반드시 GPU memory에서 일어나야 한다는 엄격한 migration policy가 있으면 concurrent CPU access 때문에 endless retry livelock이 생길 수 있습니다. 현재 GPU SVM user인 Xe에는 이런 policy가 없지만 미래에는 추가될 수 있습니다. 해결은 driver lock보다 core MM에서 이루어지는 편이 이상적입니다.

Physical memory에서 virtual memory로 가는 backpointer는 두지 않습니다. `mremap()`은 address 변경을 driver에 알리지 않고 invalidation notifier만 보내므로 이런 pointer는 유효하지 않습니다. Physical backpointer인 `page->zone_device_data`는 allocation부터 page free까지 안정적으로 유지해야 하며 concurrent user와 안전하게 갱신하기는 page free 전에는 매우 어렵습니다.

GPU page-table notifier lock은 range tree, range의 page-valid state, page-table entry, MMU notifier seqno tracking만 보호합니다. Wider notifier 때문에 단순 seqno 대신 valid state를 다룹니다. 이 lock은 모든 race를 막는 global lock이 아니며 나머지 race는 큰 retry로 처리합니다.

GPU SVM 핵심 원칙
경로기준
migrate_to_ramCore MM primitive만 사용, partial migration·retry
EvictionPhysical page·lock만 보고 virtual address에 의존하지 않음
GPU faultmmap_read 최소화, notifier race는 retry
BackpointerPhysical→virtual pointer 금지, zone_device_data 안정 유지
Page-table lockRange·PTE·seqno만 보호, global race lock 아님

각 경로에서 허용하는 state와 race 처리 방식입니다.

Fault와 migration race
GPU fault에서 mmap_read 획득Core MM helper 호출Notifier range·page-table state 확인Concurrent eviction/migration race면 상태 폐기Lock을 풀고 큰 retry loop 재시작

Driver-specific lock 대신 재검증 loop를 사용합니다.

Lock 사용 경계
Lock정책
Core page lockMigration PTE·page reference와 함께 사용
Hardware interaction lock필요한 범위에서 허용
BO dma-resv초기 VRAM migration의 가능한 예외
Driver-exclusive MM lockCore MM race sealing 목적으로 금지
Notifier lockRange tree·valid state·PTE·seqno만 보호

허용되는 lock과 피해야 할 lock입니다.

.. SPDX-License-Identifier: (GPL-2.0+ OR MIT)

===============
GPU SVM Section
===============

Agreed upon design principles
=============================

* migrate_to_ram path
        * Rely only on core MM concepts (migration PTEs, page references, and
          page locking).
        * No driver specific locks other than locks for hardware interaction in
          this path. These are not required and generally a bad idea to
          invent driver defined locks to seal core MM races.
        * An example of a driver-specific lock causing issues occurred before
          fixing do_swap_page to lock the faulting page. A driver-exclusive lock
          in migrate_to_ram produced a stable livelock if enough threads read
          the faulting page.
        * Partial migration is supported (i.e., a subset of pages attempting to
          migrate can actually migrate, with only the faulting page guaranteed
          to migrate).
        * Driver handles mixed migrations via retry loops rather than locking.
* Eviction
        * Eviction is defined as migrating data from the GPU back to the
          CPU without a virtual address to free up GPU memory.
        * Only looking at physical memory data structures and locks as opposed to
          looking at virtual memory data structures and locks.
        * No looking at mm/vma structs or relying on those being locked.
        * The rationale for the above two points is that CPU virtual addresses
          can change at any moment, while the physical pages remain stable.
        * GPU page table invalidation, which requires a GPU virtual address, is
          handled via the notifier that has access to the GPU virtual address.
* GPU fault side
        * mmap_read only used around core MM functions which require this lock
          and should strive to take mmap_read lock only in GPU SVM layer.
        * Big retry loop to handle all races with the mmu notifier under the gpu
          pagetable locks/mmu notifier range lock/whatever we end up calling
          those.
        * Races (especially against concurrent eviction or migrate_to_ram)
          should not be handled on the fault side by trying to hold locks;
          rather, they should be handled using retry loops. One possible
          exception is holding a BO's dma-resv lock during the initial migration
          to VRAM, as this is a well-defined lock that can be taken underneath
          the mmap_read lock.
        * One possible issue with the above approach is if a driver has a strict
          migration policy requiring GPU access to occur in GPU memory.
          Concurrent CPU access could cause a livelock due to endless retries.
          While no current user (Xe) of GPU SVM has such a policy, it is likely
          to be added in the future. Ideally, this should be resolved on the
          core-MM side rather than through a driver-side lock.
* Physical memory to virtual backpointer
        * This does not work, as no pointers from physical memory to virtual
          memory should exist. mremap() is an example of the core MM updating
          the virtual address without notifying the driver of address
          change rather the driver only receiving the invalidation notifier.
        * The physical memory backpointer (page->zone_device_data) should remain
          stable from allocation to page free. Safely updating this against a
          concurrent user would be very difficult unless the page is free.
* GPU pagetable locking
        * Notifier lock only protects range tree, pages valid state for a range
          (rather than seqno due to wider notifiers), pagetable entries, and
          mmu notifier seqno tracking, it is not a global lock to protect
          against races.
        * All races handled with big retry as mentioned above.

Overview of baseline design
===========================

.. kernel-doc:: drivers/gpu/drm/drm_gpusvm.c
   :doc: Overview

.. kernel-doc:: drivers/gpu/drm/drm_gpusvm.c
   :doc: Locking

.. kernel-doc:: drivers/gpu/drm/drm_gpusvm.c
   :doc: Partial Unmapping of Ranges

Baseline drm_gpusvm design

78-90

Baseline design은 `drivers/gpu/drm/drm_gpusvm.c`의 네 `kernel-doc` block으로 구성됩니다. `Overview`는 전체 모델, `Locking`은 동기화 계약, `Partial Unmapping of Ranges`는 일부 range 해제, `Examples`는 사용 예를 설명합니다.

drm_gpusvm kernel-doc
Block범위
OverviewGPU SVM object·range 전체 모델
LockingNotifier·page table·MM lock 계약
Partial Unmapping of RangesRange 일부 unmap 처리
ExamplesAPI 사용 흐름

Baseline 구현에서 읽어야 할 네 문서 block입니다.

Baseline 문서 순서
OverviewLockingPartial Unmapping of RangesExamples

개념에서 locking과 range operation으로 내려갑니다.


.. kernel-doc:: drivers/gpu/drm/drm_gpusvm.c
   :doc: Examples

Overview of drm_pagemap design
==============================

.. kernel-doc:: drivers/gpu/drm/drm_pagemap.c
   :doc: Overview

.. kernel-doc:: drivers/gpu/drm/drm_pagemap.c
   :doc: Migration

drm_pagemap design

91-99

`drm_pagemap` 설계는 `drivers/gpu/drm/drm_pagemap.c`의 `Overview`와 `Migration` `kernel-doc` block에서 설명합니다.

drm_pagemap kernel-doc
BlockSource
Overviewdrivers/gpu/drm/drm_pagemap.c
Migrationdrivers/gpu/drm/drm_pagemap.c

Page mapping과 migration의 구현 문서입니다.

drm_pagemap 문서 축
Overview: page-map modelMigration: system↔device 이동

Page representation에서 migration operation으로 이어집니다.

Possible future design features
===============================

* Concurrent GPU faults
        * CPU faults are concurrent so makes sense to have concurrent GPU
          faults.
        * Should be possible with fined grained locking in the driver GPU
          fault handler.
        * No expected GPU SVM changes required.

가능한 미래 기능

100-118

CPU fault처럼 GPU fault도 concurrent하게 처리하는 기능을 고려합니다. Driver GPU fault handler의 fine-grained locking으로 가능하며 GPU SVM 자체 변경은 필요하지 않을 것으로 예상합니다.

System page와 device page가 섞인 range는 필요하면 `drm_gpusvm_get_pages`에 비교적 쉽게 추가할 수 있습니다. Multi-GPU 지원은 진행 중이며 GPU SVM 최초 landing 뒤 patch가 예정되어 있고, 가능하면 GPU SVM 변경을 최소화합니다.

Notifier 속도를 높이기 위해 range 대신 radix tree를 사용할 수 있습니다. Compound device page는 migrate-device layer의 비싼 core MM call 횟수를 줄여 NVIDIA·AMD·Intel이 공통으로 지적한 performance bottleneck을 완화할 수 있습니다.

Intel hardware에서는 4K DMA mapping이 migration 성능을 해치므로 higher-order 2M DMA mapping이 도움이 될 수 있습니다.

그 밖에 GPU SVM 위의 공통 userptr 구현, driver-side `madvise`와 migration policy, Leon/NVIDIA의 pending dma-mapping API 변경 반영이 후보입니다.

Future GPU SVM feature
기능목표
Concurrent GPU faultsDriver fine-grained locking, SVM 변경 없음 예상
Mixed system/device pagesdrm_gpusvm_get_pages 확장
Multi-GPU최소한의 GPU SVM 변경
Radix tree더 빠른 notifier
Compound device pagesCore MM call 횟수 감소
2M DMA mappingIntel migration 성능 개선
Userptr·madvise공통 pinning과 migration policy

확장 방향과 예상 영향입니다.

향후 성능 개선
Concurrent GPU fault handlerMixed page·multi-GPU rangeRadix-tree notifierCompound device pageHigher-order 2M DMA mappingCommon userptr·driver madvise policy

Fault concurrency와 migration granularity를 함께 확장합니다.

* Ranges with mixed system and device pages
        * Can be added if required to drm_gpusvm_get_pages fairly easily.
* Multi-GPU support
        * Work in progress and patches expected after initially landing on GPU
          SVM.
        * Ideally can be done with little to no changes to GPU SVM.
* Drop ranges in favor of radix tree
        * May be desirable for faster notifiers.
* Compound device pages
        * Nvidia, AMD, and Intel all have agreed expensive core MM functions in
          migrate device layer are a performance bottleneck, having compound
          device pages should help increase performance by reducing the number
          of these expensive calls.
* Higher order dma mapping for migration
        * 4k dma mapping adversely affects migration performance on Intel
          hardware, higher order (2M) dma mapping should help here.
* Build common userptr implementation on top of GPU SVM
* Driver side madvise implementation and migration policies
* Pull in pending dma-mapping API changes from Leon / Nvidia when these land