[RFC PATCH 0/7] Introduce sparse DRM shmem object allocations
From: Adrián Larumbe
Date: Tue Feb 18 2025 - 18:29:13 EST
This patch series is a proposal for implementing sparse page allocations
for shmem objects. It was initially motivated by a kind of BO managed by
the Panfrost driver, the tiler heap, which grows on demand every time the
GPU faults on a virtual address within its drm_mm-managed ranged.
Because keeping a struct page pointer array that can describe the entire
virtual range is wasteful when only a few backing pages have been
allocated, at Collabora we thought a sparse allocation approach with
xarrays was a more efficient choice.
Since sparse and 'dense' DRM shmem objects must be managed slightly
differently, the API is expanded to allow client drivers to create sparse
objects and also to expand their page backing range, but everything else
should remain as transparent as possible and be handled from within the DRM
shmem system itself.
Another side feature that was introduced in this patch series is an shmem
helper for non-blocking allocation of pages. This is motivated by the desire
to avoid deadlocks with the shrinker.
Adrián Larumbe (7):
shmem: Introduce non-blocking allocation of shmem pages
lib/scatterlist.c: Support constructing sgt from page xarray
drm/prime: Let drm_prime_pages_to_sg use the page_array interface
drm/shmem: Introduce the notion of sparse objects
drm/shmem: Implement sparse allocation of pages for shmem objects
drm/panfrost: Use shmem sparse allocation for heap BOs
drm/panfrost/panthor: Take sparse objects into account for fdinfo
drivers/gpu/drm/drm_gem.c | 32 +++++
drivers/gpu/drm/drm_gem_shmem_helper.c | 163 ++++++++++++++++++++++--
drivers/gpu/drm/drm_prime.c | 7 +-
drivers/gpu/drm/panfrost/panfrost_gem.c | 16 ++-
drivers/gpu/drm/panfrost/panfrost_gem.h | 2 +-
drivers/gpu/drm/panfrost/panfrost_mmu.c | 85 +++---------
drivers/gpu/drm/panthor/panthor_gem.c | 4 +-
include/drm/drm_gem.h | 3 +
include/drm/drm_gem_shmem_helper.h | 30 ++++-
include/linux/scatterlist.h | 47 +++++++
include/linux/shmem_fs.h | 7 +
lib/scatterlist.c | 128 +++++++++++++++++++
12 files changed, 435 insertions(+), 89 deletions(-)
base-commit: 4fd6ca90fc7f509977585d39885f21b2911123f3
--
2.47.1