Re: [PATCH v6 12/12] drm/xe/bo: Skip zero-refcount BOs in shrinker

Thomas Hellström
2026-03-05T15:49:50Z

On Tue, 2026-03-03 at 20:50 +0530, Arvind Yadav wrote:
> Zero-refcount BOs are being destroyed. Skip them in the shrinker
> to avoid racing with cleanup by returning -EBUSY.
>
> Ghost BOs from ttm_bo_pipeline_gutting() still hold reclaimable
> pages, so continue processing them via xe_bo_shrink_purge().
>
> Fixes: 00c8efc3180f ("drm/xe: Add a shrinker for xe bos")
>
> v6:
>   - Split from patch 0010 (Thomas)
>
> Cc: Matthew Brost <matthew.brost@intel.com>
> Cc: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
> Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
> Signed-off-by: Arvind Yadav <arvind.yadav@intel.com>

Hi, Arvind.

> ---
>  drivers/gpu/drm/xe/xe_bo.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
> index 598d4463baf3..07acce383cb1 100644
> --- a/drivers/gpu/drm/xe/xe_bo.c
> +++ b/drivers/gpu/drm/xe/xe_bo.c
> @@ -1295,9 +1295,13 @@ long xe_bo_shrink(struct ttm_operation_ctx
> *ctx, struct ttm_buffer_object *bo,
>   if (!xe_bo_eviction_valuable(bo, &place))
>   return -EBUSY;
>
> - if (!xe_bo_is_xe_bo(bo) || !xe_bo_get_unless_zero(xe_bo))

Looking a bit closer at this, I realized this is intentional. The bo
has two refcounts. One is the gem refcount (which we fail to grab here)
and one is the ttm refcount, which we have successfully grabbed,
otherwise this function wouldn't be called. So the bo is in a zombie
state (all xe-specific members are invalidd) but calling
xe_bo_shrink_purge is allowed. So this patch could actually be dropped.

Question is did you see any issues from xe_bo_shrink_purge() without
this patch?

Thanks,
Thomas