RE: [PATCH v2 3/4] drm/xe: Wire up dmem cgroup reclaim for VRAM manager

Upadhyay, Tejas
2026-04-28T09:38:54Z

> -----Original Message-----
> From: Intel-xe <intel-xe-bounces@lists.freedesktop.org> On Behalf Of Thomas
> Hellström
> Sent: 28 April 2026 13:01
> To: intel-xe@lists.freedesktop.org
> Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>; Natalie Vock
> <natalie.vock@gmx.de>; Johannes Weiner <hannes@cmpxchg.org>; Tejun Heo
> <tj@kernel.org>; Michal Koutný <mkoutny@suse.com>;
> cgroups@vger.kernel.org; Huang Rui <ray.huang@amd.com>; Brost, Matthew
> <matthew.brost@intel.com>; Auld, Matthew <matthew.auld@intel.com>;
> Maarten Lankhorst <maarten.lankhorst@linux.intel.com>; Maxime Ripard
> <mripard@kernel.org>; Thomas Zimmermann <tzimmermann@suse.de>;
> Simona Vetter <simona@ffwll.ch>; David Airlie <airlied@gmail.com>; Christian
> König <christian.koenig@amd.com>; Alex Deucher
> <alexander.deucher@amd.com>; Vivi, Rodrigo <rodrigo.vivi@intel.com>; dri-
> devel@lists.freedesktop.org; amd-gfx@lists.freedesktop.org; linux-
> kernel@vger.kernel.org
> Subject: [PATCH v2 3/4] drm/xe: Wire up dmem cgroup reclaim for VRAM
> manager
>
> Register the VRAM manager with the dmem cgroup reclaim infrastructure so
> that lowering dmem.max below current VRAM usage triggers TTM eviction
> rather than failing with -EBUSY.
>
> Assisted-by: GitHub Copilot:claude-sonnet-4.6
> Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
> ---
> drivers/gpu/drm/xe/xe_ttm_vram_mgr.c | 19 ++++++++++++-------
> 1 file changed, 12 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/gpu/drm/xe/xe_ttm_vram_mgr.c
> b/drivers/gpu/drm/xe/xe_ttm_vram_mgr.c
> index 5fd0d5506a7e..1bdcb3fee901 100644
> --- a/drivers/gpu/drm/xe/xe_ttm_vram_mgr.c
> +++ b/drivers/gpu/drm/xe/xe_ttm_vram_mgr.c
> @@ -303,13 +303,6 @@ int __xe_ttm_vram_mgr_init(struct xe_device *xe,
> struct xe_ttm_vram_mgr *mgr,
> struct ttm_resource_manager *man = &mgr->manager;
> int err;
>
> - if (mem_type != XE_PL_STOLEN) {
> - const char *name = mem_type == XE_PL_VRAM0 ? "vram0" :
> "vram1";
> - man->cg = drmm_cgroup_register_region(&xe->drm, name,
> size);
> - if (IS_ERR(man->cg))
> - return PTR_ERR(man->cg);
> - }
> -
> man->func = &xe_ttm_vram_mgr_func;
> mgr->mem_type = mem_type;
> mutex_init(&mgr->lock);
> @@ -318,6 +311,18 @@ int __xe_ttm_vram_mgr_init(struct xe_device *xe,
> struct xe_ttm_vram_mgr *mgr,
> mgr->visible_avail = io_size;
>
> ttm_resource_manager_init(man, &xe->ttm, size);
> +
> + if (mem_type != XE_PL_STOLEN) {
> + const char *name = mem_type == XE_PL_VRAM0 ? "vram0" :
> "vram1";
> + struct dmem_cgroup_region *cg =
> + drmm_cgroup_register_region(&xe->drm, name,
> size);
> +
> + if (IS_ERR(cg))
> + return PTR_ERR(cg);
> +
> + ttm_resource_manager_set_dmem_region(man, cg);
> + }
> +

I think, this reordering is reasonable cleanup, LGTM:
Reviewed-by: Tejas Upadhyay <tejas.upadhyay@intel.com>

Tejas
> err = gpu_buddy_init(&mgr->mm, man->size, default_page_size);
> if (err)
> return err;
> --
> 2.53.0