]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/xe: Adjust page count tracepoints in shrinker
authorMatthew Brost <matthew.brost@intel.com>
Wed, 7 Jan 2026 20:57:32 +0000 (12:57 -0800)
committerMatthew Brost <matthew.brost@intel.com>
Thu, 8 Jan 2026 05:29:38 +0000 (21:29 -0800)
Page accounting can change via the shrinker without calling
xe_ttm_tt_unpopulate(), which normally updates page count tracepoints
through update_global_total_pages. Add a call to
update_global_total_pages when the shrinker successfully shrinks a BO.

v2:
 - Don't adjust global accounting when pinning (Stuart)

Cc: stable@vger.kernel.org
Fixes: ce3d39fae3d3 ("drm/xe/bo: add GPU memory trace points")
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Stuart Summers <stuart.summers@intel.com>
Link: https://patch.msgid.link/20260107205732.2267541-1-matthew.brost@intel.com
drivers/gpu/drm/xe/xe_bo.c

index 8b6474cd3eaf237a267cc0d89b381f21f9c0e61d..6ab52fa397e3f24b4bd300b82d99115d4dd6a967 100644 (file)
@@ -1054,6 +1054,7 @@ static long xe_bo_shrink_purge(struct ttm_operation_ctx *ctx,
                               unsigned long *scanned)
 {
        struct xe_device *xe = ttm_to_xe_device(bo->bdev);
+       struct ttm_tt *tt = bo->ttm;
        long lret;
 
        /* Fake move to system, without copying data. */
@@ -1078,8 +1079,10 @@ static long xe_bo_shrink_purge(struct ttm_operation_ctx *ctx,
                              .writeback = false,
                              .allow_move = false});
 
-       if (lret > 0)
+       if (lret > 0) {
                xe_ttm_tt_account_subtract(xe, bo->ttm);
+               update_global_total_pages(bo->bdev, -(long)tt->num_pages);
+       }
 
        return lret;
 }
@@ -1165,8 +1168,10 @@ long xe_bo_shrink(struct ttm_operation_ctx *ctx, struct ttm_buffer_object *bo,
        if (needs_rpm)
                xe_pm_runtime_put(xe);
 
-       if (lret > 0)
+       if (lret > 0) {
                xe_ttm_tt_account_subtract(xe, tt);
+               update_global_total_pages(bo->bdev, -(long)tt->num_pages);
+       }
 
 out_unref:
        xe_bo_put(xe_bo);