On 11/18/26 16:10, William Palacek wrote:
> Registering a large userptr BO (hipHostMalloc) holds mmap_lock, p->mutex
> and process_info->lock while every page of the range is faulted in. For
> 32 GiB on MI300X that takes seconds, and every other thread of the
> process that submits GPU work waits behind it for the whole time.
> 
> Patch 1 limits userptr sg segments to half of sg->length. Larger
> physically contiguous segments can overflow the padded segment length in
> iommu_dma_map_sg(), and the pin fails. This already happens without the
> series; patch 3 makes the pages contiguous enough that it hits on a
> freshly booted system, so it goes first.
> 
> Patch 2 drops p->mutex from AMDKFD_IOC_GET_CLOCK_COUNTERS, which other
> threads call while submitting work.
> 
> Patch 3 drops mmap_lock between 2 MiB chunks while faulting userptr
> pages in.
> 
> Patch 4 faults in and validates userptr pages without p->mutex and
> process_info->lock, and adds the BO to the valid list only if no
> invalidation happened meanwhile.

Absolutely clear NAK to the whole approach! Userptrs are fragile enough without 
this.

That the performance of userptrs isn't the best is expected and won't be fixed.

Regards,
Christian.

> 
> Tested with two 32 GiB hipHostMalloc/hipHostFree cycles next to 4
> PyTorch streams on 2 GPUs, measuring the worst GPU submission latency
> of the other threads (limit 1 s), on the amdgpu 7.2 DKMS driver:
> 
>   MI300X, IOMMU DMA-FQ     unpatched    0/3 (6.1-6.2 s; on other boots
>                                          the 32 GiB pin itself fails)
>                            series       3/3 (0.80-0.95 s)
>   MI300X, IOMMU identity   unpatched    0/3 (9.6-10.1 s)
>                            patches 2-3  0/3 (10.5-11.0 s)
>                            patches 2-4  3/3 (0.81-0.93 s)
>   MI350X, IOMMU identity   unpatched    0/4 (4.55-4.84 s)
>                            series       7/7 (0.21-0.39 s)
> 
> kfdtest KFDMemoryTest.* and KFDEvictTest.* pass on both GPUs.
> 
> William Palacek (4):
>   drm/amdgpu: limit userptr sg segments to half of sg->length
>   drm/amdkfd: don't take p->mutex in AMDKFD_IOC_GET_CLOCK_COUNTERS
>   drm/amdgpu: drop mmap_lock between chunks when faulting userptr pages
>   drm/amdkfd: register userptr pages without holding KFD process locks
> 
>  .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c  | 53 +++++++++++--------
>  drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.c       | 14 ++++-
>  drivers/gpu/drm/amd/amdgpu/amdgpu_hmm.h       |  2 +-
>  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c       |  9 ++--
>  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h       |  7 +++
>  drivers/gpu/drm/amd/amdkfd/kfd_chardev.c      | 10 +++-
>  drivers/gpu/drm/amd/amdkfd/kfd_svm.c          |  2 +-
>  7 files changed, 66 insertions(+), 31 deletions(-)
> 

Reply via email to