[PATCH v2 7/7] drm/gem: Add cgroup memory accounting for VRAM helper.
From: Maarten Lankhorst
Date: Wed Dec 04 2024 - 08:44:37 EST
From: Maxime Ripard <mripard@xxxxxxxxxx>
This allows any driver using the VRAM helper to set limits on VRAM using
cgroup.
Signed-off-by: Maxime Ripard <mripard@xxxxxxxxxx>
Signed-off-by: Maarten Lankhorst <dev@xxxxxxxxxxxx>
---
drivers/gpu/drm/drm_gem_vram_helper.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/drm_gem_vram_helper.c b/drivers/gpu/drm/drm_gem_vram_helper.c
index 22b1fe9c03b81..70979523ee984 100644
--- a/drivers/gpu/drm/drm_gem_vram_helper.c
+++ b/drivers/gpu/drm/drm_gem_vram_helper.c
@@ -925,6 +925,7 @@ EXPORT_SYMBOL(drm_vram_mm_debugfs_init);
static int drm_vram_mm_init(struct drm_vram_mm *vmm, struct drm_device *dev,
uint64_t vram_base, size_t vram_size)
{
+ struct ttm_resource_manager *man;
int ret;
vmm->vram_base = vram_base;
@@ -939,8 +940,20 @@ static int drm_vram_mm_init(struct drm_vram_mm *vmm, struct drm_device *dev,
ret = ttm_range_man_init(&vmm->bdev, TTM_PL_VRAM,
false, vram_size >> PAGE_SHIFT);
- if (ret)
+ if (ret) {
+ ttm_device_fini(&vmm->bdev);
return ret;
+ }
+
+ man = ttm_manager_type(&vmm->bdev, TTM_PL_VRAM);
+ man->cg = drmm_register_region(dev, "vram", size);
+ if (IS_ERR(man->cg)) {
+ ret = PTR_ERR(man->cg);
+
+ ttm_range_man_fini(&vmm->bdev, TTM_PL_VRAM);
+ ttm_device_fini(&vmm->bdev);
+ return ret;
+ }
return 0;
}
--
2.43.0