From: Matthew Brost <matthew.brost@intel.com>
To: intel-xe@lists.freedesktop.org
Subject: [PATCH v3 2/3] drm/ttm: Allow skipping to the next priority in the bo LRU cursor
Date: Tue, 20 Oct 2026 12:08:39 -0700 [thread overview]
Message-ID: <20261020190840.854525-3-matthew.brost@intel.com> (raw)
In-Reply-To: <20261020190840.854525-1-matthew.brost@intel.com>
Drivers walking a manager's LRU with ttm_bo_lru_for_each_reserved_guarded()
may decide that the rest of the current priority isn't worth walking,
for example when the priority is roughly age ordered and the walk hit
a BO that is still too hot to evict. Today the only option is to stop
the walk altogether, which also gives up on the remaining priorities.
Add ttm_resource_manager_next_priority() to move a resource cursor to
the start of the next priority, and ttm_bo_lru_cursor_skip_priority()
to make the next ttm_bo_lru_cursor_next() use it.
While at it, stop incrementing the cursor priority past the last valid
priority once the iteration is done.
Assisted-by: LLM
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
---
drivers/gpu/drm/ttm/ttm_bo_util.c | 3 +++
drivers/gpu/drm/ttm/ttm_resource.c | 35 ++++++++++++++++++++++++++----
include/drm/ttm/ttm_bo.h | 19 ++++++++++++++++
include/drm/ttm/ttm_resource.h | 2 ++
4 files changed, 55 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
index f9458a4d5a09..d626f014e61f 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_util.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
@@ -997,6 +997,9 @@ __ttm_bo_lru_cursor_next(struct ttm_bo_lru_cursor *curs)
if (first) {
res = ttm_resource_manager_first(&curs->res_curs);
first = false;
+ } else if (curs->skip_priority) {
+ res = ttm_resource_manager_next_priority(&curs->res_curs);
+ curs->skip_priority = false;
} else {
res = ttm_resource_manager_next(&curs->res_curs);
}
diff --git a/drivers/gpu/drm/ttm/ttm_resource.c b/drivers/gpu/drm/ttm/ttm_resource.c
index 4e6d3d658d85..e631507d7aa1 100644
--- a/drivers/gpu/drm/ttm/ttm_resource.c
+++ b/drivers/gpu/drm/ttm/ttm_resource.c
@@ -674,6 +674,17 @@ ttm_resource_cursor_check_bulk(struct ttm_resource_cursor *cursor,
}
}
+static bool ttm_resource_cursor_next_priority(struct ttm_resource_cursor *cursor)
+{
+ if (cursor->priority + 1 >= TTM_MAX_BO_PRIORITY)
+ return false;
+
+ list_move(&cursor->hitch.link, &cursor->man->lru[++cursor->priority]);
+ ttm_resource_cursor_clear_bulk(cursor);
+
+ return true;
+}
+
/**
* ttm_resource_manager_first() - Start iterating over the resources
* of a resource manager
@@ -723,16 +734,32 @@ ttm_resource_manager_next(struct ttm_resource_cursor *cursor)
}
}
- if (++cursor->priority >= TTM_MAX_BO_PRIORITY)
+ if (!ttm_resource_cursor_next_priority(cursor))
break;
-
- list_move(&cursor->hitch.link, &man->lru[cursor->priority]);
- ttm_resource_cursor_clear_bulk(cursor);
}
return NULL;
}
+/**
+ * ttm_resource_manager_next_priority() - Skip the rest of the current
+ * priority and continue iterating at the next one
+ * @cursor: cursor to record the position
+ *
+ * Return: the first resource of the next non-empty priority, or NULL if
+ * there is none.
+ */
+struct ttm_resource *
+ttm_resource_manager_next_priority(struct ttm_resource_cursor *cursor)
+{
+ lockdep_assert_held(&cursor->man->bdev->lru_lock);
+
+ if (!ttm_resource_cursor_next_priority(cursor))
+ return NULL;
+
+ return ttm_resource_manager_next(cursor);
+}
+
/**
* ttm_lru_first_res_or_null() - Return the first resource on an lru list
* @head: The list head of the lru list.
diff --git a/include/drm/ttm/ttm_bo.h b/include/drm/ttm/ttm_bo.h
index 32791c4db2a9..2fc517dbf03d 100644
--- a/include/drm/ttm/ttm_bo.h
+++ b/include/drm/ttm/ttm_bo.h
@@ -507,10 +507,29 @@ struct ttm_bo_lru_cursor {
* unlock before the next iteration or after loop exit.
*/
bool needs_unlock;
+ /**
+ * @skip_priority: Continue at the next LRU priority on the next
+ * iteration. See ttm_bo_lru_cursor_skip_priority().
+ */
+ bool skip_priority;
/** @arg: Pointer to common BO LRU walk arguments. */
struct ttm_lru_walk_arg *arg;
};
+/**
+ * ttm_bo_lru_cursor_skip_priority() - Skip the rest of the current priority
+ * @curs: The cursor.
+ *
+ * Make the next ttm_bo_lru_cursor_next() skip the remaining buffer objects
+ * of the current LRU priority and continue at the next priority, for
+ * example when the caller decides the rest of the priority isn't worth
+ * walking.
+ */
+static inline void ttm_bo_lru_cursor_skip_priority(struct ttm_bo_lru_cursor *curs)
+{
+ curs->skip_priority = true;
+}
+
void ttm_bo_lru_cursor_fini(struct ttm_bo_lru_cursor *curs);
struct ttm_bo_lru_cursor *
diff --git a/include/drm/ttm/ttm_resource.h b/include/drm/ttm/ttm_resource.h
index 714c533622c2..8cd70d1e5481 100644
--- a/include/drm/ttm/ttm_resource.h
+++ b/include/drm/ttm/ttm_resource.h
@@ -499,6 +499,8 @@ struct ttm_resource *
ttm_resource_manager_first(struct ttm_resource_cursor *cursor);
struct ttm_resource *
ttm_resource_manager_next(struct ttm_resource_cursor *cursor);
+struct ttm_resource *
+ttm_resource_manager_next_priority(struct ttm_resource_cursor *cursor);
struct ttm_resource *
ttm_lru_first_res_or_null(struct list_head *head);
--
2.34.1
next prev parent reply other threads:[~2026-10-20 19:09 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-20 19:08 [PATCH v3 0/3] Add a minimum age gate to the shrinker Matthew Brost
2026-10-20 19:08 ` [PATCH v3 1/3] drm/xe: Tie BO TTM LRU priority to DONTNEED/WILLNEED madvise state Matthew Brost
2026-10-20 19:08 ` Matthew Brost [this message]
2026-10-20 19:08 ` [PATCH v3 3/3] drm/xe: Add a minimum age gate to the shrinker Matthew Brost
2026-10-20 19:36 ` sashiko-bot
2026-10-21 22:13 ` Matthew Brost
2026-10-20 20:20 ` ✓ CI.KUnit: success for " Patchwork
2026-10-20 20:57 ` ✓ Xe.CI.BAT: " Patchwork
2026-10-21 2:24 ` ✓ Xe.CI.FULL: " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261020190840.854525-3-matthew.brost@intel.com \
--to=matthew.brost@intel.com \
--cc=intel-xe@lists.freedesktop.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.