[PATCH 3/3] drm/xe/bo: Allow migrating local bos to TT to make room in VRAM

Matthew Brost matthew.brost at intel.com
Mon Feb 26 21:45:29 UTC 2024


On Mon, Feb 26, 2024 at 05:44:55PM +0100, Thomas Hellström wrote:
> If VRAM is full and we want to evict local bos we can't typically
> do that, since we require all local bos to be residient at
> execution time.
> But we're allowed to migrate to TT if that's a valid placement
> for GPU access, so in that case, do that.
> 

Make sense to me:
Reviewed-by: Matthew Brost <matthew.brost at intel.com>

> Fixes: 24f947d58fe5 ("drm/xe: Use DRM GPUVM helpers for external- and evicted objects")
> Cc: Thomas Hellström <thomas.hellstrom at linux.intel.com>
> Cc: Rodrigo Vivi <rodrigo.vivi at intel.com>
> Cc: Matthew Brost <matthew.brost at intel.com>
> Cc: Lucas De Marchi <lucas.demarchi at intel.com>
> Cc: Oded Gabbay <ogabbay at kernel.org>
> Signed-off-by: Thomas Hellström <thomas.hellstrom at linux.intel.com>
> ---
>  drivers/gpu/drm/xe/xe_bo.c | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
> 
> diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
> index 2931b9030503..21141f877850 100644
> --- a/drivers/gpu/drm/xe/xe_bo.c
> +++ b/drivers/gpu/drm/xe/xe_bo.c
> @@ -1049,6 +1049,21 @@ static void xe_ttm_bo_delete_mem_notify(struct ttm_buffer_object *ttm_bo)
>  	}
>  }
>  
> +/*
> + * Does @bo have @mem_type as an allowed placement?
> + */
> +static bool xe_bo_may_reside_in(const struct xe_bo *bo, unsigned int mem_type)
> +{
> +	const struct ttm_placement *placement = &bo->placement;
> +	unsigned int i;
> +
> +	for (i = 0; i < placement->num_placement; ++i) {
> +		if (placement->placement[i].mem_type == mem_type)
> +			return true;
> +	}
> +	return false;
> +}
> +
>  static bool xe_bo_eviction_valuable(struct ttm_buffer_object *ttm_bo,
>  				    const struct ttm_place *place)
>  {
> @@ -1061,6 +1076,10 @@ static bool xe_bo_eviction_valuable(struct ttm_buffer_object *ttm_bo,
>  			/* Not bound to the vm? */
>  			if (list_empty(&ttm_bo->base.gpuva.list))
>  				goto allow;
> +			/* Is the bo gpu accessible even if placed in TT? */
> +			if (ttm_bo->resource && ttm_bo->resource->mem_type !=
> +			    XE_PL_TT && xe_bo_may_reside_in(xe_bo, XE_PL_TT))
> +				goto allow;
>  			return false;
>  		}
>  	}
> -- 
> 2.43.0
> 


More information about the Intel-xe mailing list