@@ -36,6 +36,13 @@ struct panfrost_gem_object {
*/
atomic_t gpu_usecount;
+ /* Actual memory used by the BO. Should be zero before pages are
+ * pinned, then the size of the BO, unless it's a heap BO. In
+ * this case the resident size is updated when the fault handler
+ * allocates memory.
+ */
+ size_t resident_size;
+
bool noexec :1;
bool is_heap :1;
};
@@ -54,6 +54,7 @@ static bool panfrost_gem_purge(struct drm_gem_object *obj)
panfrost_gem_teardown_mappings_locked(bo);
drm_gem_shmem_purge_locked(&bo->base);
ret = true;
+ bo->resident_size = 0;
mutex_unlock(&shmem->pages_lock);
@@ -340,6 +340,7 @@ int panfrost_mmu_map(struct panfrost_gem_mapping *mapping)
mmu_map_sg(pfdev, mapping->mmu, mapping->mmnode.start << PAGE_SHIFT,
prot, sgt);
mapping->active = true;
+ bo->resident_size = bo->base.base.size;
return 0;
}
@@ -508,6 +509,7 @@ static int panfrost_mmu_map_fault_addr(struct panfrost_device *pfdev, int as,
}
}
+ bo->resident_size += SZ_2M;
mutex_unlock(&bo->base.pages_lock);
sgt = &bo->sgts[page_offset / (SZ_2M / PAGE_SIZE)];
Heap BOs use an on-demand allocation scheme, meaning that the resident size is different from the BO side. Track resident size so we can more accurately per-FD expose memory usage. Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com> --- drivers/gpu/drm/panfrost/panfrost_gem.h | 7 +++++++ drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c | 1 + drivers/gpu/drm/panfrost/panfrost_mmu.c | 2 ++ 3 files changed, 10 insertions(+)