[RFC PATCH 14/18] drm/ttm: Consider BOs placed in non-favorite locations evicted

Friedrich Vock friedrich.vock at gmx.de
Wed Apr 24 16:57:04 UTC 2024


If we didn't get the favorite placement because it was full, we should
try moving it into the favorite placement once there is space.

Signed-off-by: Friedrich Vock <friedrich.vock at gmx.de>
---
 drivers/gpu/drm/ttm/ttm_bo.c | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 6ac939c58a6b8..af8209f3bc894 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -1111,7 +1111,9 @@ int ttm_bo_validate(struct ttm_buffer_object *bo,
 		    struct ttm_placement *placement,
 		    struct ttm_operation_ctx *ctx)
 {
-	int ret;
+	struct ttm_resource_manager *man;
+	int favorite_mem_type;
+	int ret, i;

 	dma_resv_assert_held(bo->base.resv);

@@ -1133,6 +1135,30 @@ int ttm_bo_validate(struct ttm_buffer_object *bo,
 	if (ret)
 		return ret;

+	if (bo->resource) {
+		/*
+		 * Also mark the buffer as evicted if we ended up in a
+		 * non-favorite busy placement, so the buffer get
+		 * moved into the favorite spot if possible.
+		 */
+		for (i = 1; i < placement->num_busy_placement; ++i) {
+			if (bo->resource->mem_type !=
+			    placement->busy_placement[i].mem_type)
+				continue;
+
+			favorite_mem_type =
+				placement->busy_placement[0].mem_type;
+			man = ttm_manager_type(bo->bdev,
+					       favorite_mem_type);
+
+			spin_lock(&bo->bdev->unevict_lock);
+			list_add_tail(&bo->evicted, &man->evicted);
+			man->evicted_bytes += bo->base.size;
+			spin_unlock(&bo->bdev->unevict_lock);
+			bo->evicted_type = favorite_mem_type;
+		}
+	}
+
 	/*
 	 * We might need to add a TTM.
 	 */
--
2.44.0



More information about the dri-devel mailing list