]> git.ipfire.org Git - thirdparty/linux.git/commit
drm/panthor: Add a GEM shrinker
authorAkash Goel <akash.goel@arm.com>
Wed, 1 Apr 2026 13:48:54 +0000 (15:48 +0200)
committerBoris Brezillon <boris.brezillon@collabora.com>
Fri, 3 Apr 2026 11:23:57 +0000 (13:23 +0200)
commitfb42964e2a76f68a5fb581d382b5d2be2d5bda9b
tree325ab0d03ffa9f874641f99332295af71955c66d
parent3218aae54542f7f079bc9777c71b052de2208819
drm/panthor: Add a GEM shrinker

This implementation is losely based on the MSM shrinker, and it's
relying on the drm_gpuvm eviction/validation infrastructure.

Right now we only support swapout/eviction, but we could add an extra
flag to specify when buffer content doesn't need to be preserved to
avoid the swapout/swapin dance.

Locking is a bit of a nightmare, but using _trylock() all the way in
the reclaim path seems to make lockdep happy. And yes, we might be
missing opportunities to reclaim when the system is under heavy GPU
load/heavy memory pressure/heavy GPU VM activity, but that's better
than no reclaim at all.

v2:
- Move gpu_mapped_shared next to the mmapped LRU
- Add a bunch of missing is_[vm_bo,vma]_evicted() tests
- Only test mmap_count to check if a BO is mmaped
- Remove stale comment about shrinker not being a thing
- Allow pin_count to be non-zero in panthor_gem_swapin_locked()
- Fix panthor_gem_sync() to check for BO residency before doing the CPU sync
- Fix the value returned by panthor_gem_shrinker_count() in case some
  memory has been released
- Check drmm_mutex_init() ret code
- Explicitly mention that PANTHOR_GEM_UNRECLAIMABLE is the initial state
  of all BOs

v3:
- Make panthor_gem_try_evict() static
- Collect {A,R}-bs

v4:
- Update the reclaim_state in panthor_gem_mmap()
- Don't reclaim GPU-mapped BOs if can_block() returns false
- Skip evicited vm_bos in panthor_vm_update_bo_reclaim_lru_locked() to
  avoid spurious WARN_ON()s
- Explain why we have to do this
  select_evicted_vma/repopulate_evicted_vma dance

v5:
- Properly report the reclaimable size in panthor_gem_debugfs_print_bos()
- Check panthor_vm_lock_region() errors in
  panthor_vm_evict_bo_mappings_locked()
- Fix lock order inversion (dma_resv_wait_timeout() inside gpuva.lock)

v6:
- Don't remap if the unmapped VMA is evicted.
- Drop a stale comment in panthor_gem_dev_map_get_sgt_locked()
- s/PANTHOR_GEM_GPU_MAPPED_PRIVATE/PANTHOR_GEM_GPU_MAPPED_SINGLE_VM/
- s/PANTHOR_GEM_GPU_MAPPED_SHARED/PANTHOR_GEM_GPU_MAPPED_MULTI_VM/
- Just count the number of vm_bo to determine the reclaim state in
  is_gpu_mapped()
- Drop a redundant panthor_gem_backing_get_pages_locked() call in
  panthor_gem_swapin_locked()
- Add more comments to panthor_vm_evict_bo_mappings_locked() to
  convince Claude it's actually safe.
- Add a comment in panthor_gem_shrinker_count() to mention the race
  and hopefully clear Claude's concerns.
- Rework the "is-still-in-list" check we have in
  panthor_mmu_reclaim_priv_bos() to address Claude's concerns
- Don't call panthor_vm_unlock_region() if panthor_vm_lock_region()
  fails in remap_evicted_vma(). Was harmless, but confusing, as
  pointed out by Claude
- Fix can_block() to allow blocking on KSWAPD_RECLAIM-only in a kswapd
  context
- Fix a lockdep warning when the last ref on a BO is released in the
  shrinker path, where the resv lock can't be acquired other than with
  a try_lock()

v7:
- Skip drm_gpuvm_bo_deferred_cleanup() when repopulating VMAs to fix a
  deadlock

Signed-off-by: Akash Goel <akash.goel@arm.com>
Acked-by: Liviu Dudau <liviu.dudau@arm.com>
Reviewed-by: Steven Price <steven.price@arm.com>
Link: https://patch.msgid.link/20260401134854.2275433-11-boris.brezillon@collabora.com
Co-developed-by: Boris Brezillon <boris.brezillon@collabora.com>
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
drivers/gpu/drm/panthor/panthor_device.c
drivers/gpu/drm/panthor/panthor_device.h
drivers/gpu/drm/panthor/panthor_gem.c
drivers/gpu/drm/panthor/panthor_gem.h
drivers/gpu/drm/panthor/panthor_mmu.c
drivers/gpu/drm/panthor/panthor_mmu.h