diff mbox series

[RFC,3/5] drm/ttm: Add preferred placement flag

Message ID 20240508180946.96863-4-tursulin@igalia.com (mailing list archive)
State New, archived
Headers show
Series Discussion around eviction improvements | expand

Commit Message

Tvrtko Ursulin May 8, 2024, 6:09 p.m. UTC
From: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>

Currently the fallback placement flag can achieve a hint that buffer
should be migrated back to the non-fallback placement, however that only
works while there is no memory pressure. As soon as we reach full VRAM
utilisation, or worse overcommit, the logic is happy to leave buffers in
the fallback placement. Consequence of this is that once buffers are
evicted they never get considered to be migrated back until the memory
pressure subsides, leaving a potentially active client not able to bring
its buffers back in.

Add a "preferred" placement flag which drivers can set when they want some
extra effort to be attempted for bringing a buffer back in.

QQQ:
Is the current "desired" flag unfortunately named perhaps? I ended up
understanding it as more like "would be nice if possible but absolutely
don't bother under memory pressure".

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Cc: Christian König <christian.koenig@amd.com>
Cc: Friedrich Vock <friedrich.vock@gmx.de>
---
 drivers/gpu/drm/ttm/ttm_resource.c | 13 +++++++++----
 include/drm/ttm/ttm_placement.h    |  3 +++
 2 files changed, 12 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/drivers/gpu/drm/ttm/ttm_resource.c b/drivers/gpu/drm/ttm/ttm_resource.c
index 4a66b851b67d..59f3d1bcc11f 100644
--- a/drivers/gpu/drm/ttm/ttm_resource.c
+++ b/drivers/gpu/drm/ttm/ttm_resource.c
@@ -305,6 +305,8 @@  bool ttm_resource_compatible(struct ttm_resource *res,
 			     struct ttm_placement *placement,
 			     bool evicting)
 {
+	const u32 incompatible_flag = evicting ? TTM_PL_FLAG_DESIRED :
+						 TTM_PL_FLAG_FALLBACK;
 	struct ttm_buffer_object *bo = res->bo;
 	struct ttm_device *bdev = bo->bdev;
 	unsigned i;
@@ -316,11 +318,14 @@  bool ttm_resource_compatible(struct ttm_resource *res,
 		const struct ttm_place *place = &placement->placement[i];
 		struct ttm_resource_manager *man;
 
-		if (res->mem_type != place->mem_type)
-			continue;
+		if (res->mem_type != place->mem_type) {
+			if (place->flags & TTM_PL_FLAG_PREFERRED)
+				return false;
+			else
+				continue;
+		}
 
-		if (place->flags & (evicting ? TTM_PL_FLAG_DESIRED :
-				    TTM_PL_FLAG_FALLBACK))
+		if (place->flags & incompatible_flag)
 			continue;
 
 		if (place->flags & TTM_PL_FLAG_CONTIGUOUS &&
diff --git a/include/drm/ttm/ttm_placement.h b/include/drm/ttm/ttm_placement.h
index b510a4812609..8ea0865e9cc8 100644
--- a/include/drm/ttm/ttm_placement.h
+++ b/include/drm/ttm/ttm_placement.h
@@ -70,6 +70,9 @@ 
 /* Placement is only used during eviction */
 #define TTM_PL_FLAG_FALLBACK	(1 << 4)
 
+/* Placement is only used during eviction */
+#define TTM_PL_FLAG_PREFERRED	(1 << 5)
+
 /**
  * struct ttm_place
  *