[PATCH 1/4] drm/panthor: Add freed_sz parameter to reclaim_priv_bos

From: Nicolas Frattaroli

Date: Wed May 06 2026 - 06:47:30 EST


panthor_mmu_reclaim_priv_bos returns the number of freed pages. However,
how many bytes of freed memory this translates to can't generally be
deduced from the number of pages, as the page size is a per-VM property.

It may be useful to know the exact number of bytes that have been freed
for observability and debugging purposes. To that end, add a new
parameter "freed_sz", which is a pointer to a size_t where this
information will be stored. It may be NULL, in which case the
information isn't stored at all.

Signed-off-by: Nicolas Frattaroli <nicolas.frattaroli@xxxxxxxxxxxxx>
---
drivers/gpu/drm/panthor/panthor_gem.c | 3 ++-
drivers/gpu/drm/panthor/panthor_mmu.c | 12 ++++++++++--
drivers/gpu/drm/panthor/panthor_mmu.h | 1 +
3 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/panthor/panthor_gem.c b/drivers/gpu/drm/panthor/panthor_gem.c
index 13295d7a593d..80e82238f3c5 100644
--- a/drivers/gpu/drm/panthor/panthor_gem.c
+++ b/drivers/gpu/drm/panthor/panthor_gem.c
@@ -1511,7 +1511,8 @@ panthor_gem_shrinker_scan(struct shrinker *shrinker, struct shrink_control *sc)
goto out;

freed += panthor_mmu_reclaim_priv_bos(ptdev, sc->nr_to_scan - freed,
- &remaining, panthor_gem_try_evict);
+ &remaining, NULL,
+ panthor_gem_try_evict);
if (freed >= sc->nr_to_scan)
goto out;

diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/panthor/panthor_mmu.c
index a7ee14986849..b81388b35a58 100644
--- a/drivers/gpu/drm/panthor/panthor_mmu.c
+++ b/drivers/gpu/drm/panthor/panthor_mmu.c
@@ -3127,13 +3127,18 @@ int panthor_vm_prepare_mapped_bos_resvs(struct drm_exec *exec, struct panthor_vm
unsigned long
panthor_mmu_reclaim_priv_bos(struct panthor_device *ptdev,
unsigned int nr_to_scan, unsigned long *remaining,
+ size_t *freed_sz,
bool (*shrink)(struct drm_gem_object *,
struct ww_acquire_ctx *))
{
+ unsigned long newly_freed;
unsigned long freed = 0;
LIST_HEAD(remaining_vms);
LIST_HEAD(vms);

+ if (freed_sz)
+ *freed_sz = 0;
+
mutex_lock(&ptdev->reclaim.lock);
list_splice_init(&ptdev->reclaim.vms, &vms);

@@ -3152,8 +3157,11 @@ panthor_mmu_reclaim_priv_bos(struct panthor_device *ptdev,

mutex_unlock(&ptdev->reclaim.lock);

- freed += drm_gem_lru_scan(&vm->reclaim.lru, nr_to_scan - freed,
- remaining, shrink, NULL);
+ newly_freed = drm_gem_lru_scan(&vm->reclaim.lru, nr_to_scan - freed,
+ remaining, shrink, NULL);
+ if (freed_sz)
+ *freed_sz += panthor_vm_page_size(vm) * newly_freed;
+ freed += newly_freed;

mutex_lock(&ptdev->reclaim.lock);

diff --git a/drivers/gpu/drm/panthor/panthor_mmu.h b/drivers/gpu/drm/panthor/panthor_mmu.h
index 3522fbbce369..12b18b5f90e1 100644
--- a/drivers/gpu/drm/panthor/panthor_mmu.h
+++ b/drivers/gpu/drm/panthor/panthor_mmu.h
@@ -52,6 +52,7 @@ int panthor_vm_evict_bo_mappings_locked(struct panthor_gem_object *bo);
unsigned long
panthor_mmu_reclaim_priv_bos(struct panthor_device *ptdev,
unsigned int nr_to_scan, unsigned long *remaining,
+ size_t *freed_sz,
bool (*shrink)(struct drm_gem_object *,
struct ww_acquire_ctx *));
int panthor_vm_prepare_mapped_bos_resvs(struct drm_exec *exec,

--
2.54.0