All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 08/33] drm/ttm: Bound page (re)allocation per defragmentation move
  2026-12-01 23:48 [PATCH v4 00/33] drm/ttm, drm/xe: Avoid foreground high-order reclaim and defragment sub-optimally backed BOs Matthew Brost
@ 2026-12-01 23:48 ` Matthew Brost
  2026-12-02  6:10   ` Niranjana Vishwanathapura
  0 siblings, 1 reply; 3+ messages in thread
From: Matthew Brost @ 2026-12-01 23:48 UTC (permalink / raw)
  To: intel-xe, dri-devel
  Cc: Carlos Santa, Ryan Neph, Natalie Vock, Arun Pravin, Matthew Auld,
	Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
	Simona Vetter, linux-kernel, Thomas Hellström

A defragmentation move reallocates an object's backing at the device's
beneficial order and harvests whatever the allocator cannot upgrade from
the old tt. For a very large object this can reallocate (and have the
driver re-copy) the entire backing in one move, which is expensive and
can stall concurrent work for an unbounded stretch.

Add an optional per-move byte budget so a large object can be upgraded in
slices across successive moves. Plumb a new
ttm_operation_ctx::defrag_bytes_remaining through to the pool allocator:
only pages actually (re)allocated at the beneficial order are charged
against it; pages harvested (borrowed) from defrag_old_tt are free and do
not count. Once the budget is exhausted the allocator stops upgrading and
completes the new tt by harvesting the remainder of the old tt as-is,
marking the tt sub-optimal (TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED) so the
driver re-queues it and a later move resumes the upgrade. The slices
already upgraded come back as free already-beneficial harvests on the
next pass, so each move spends budget only on new forward progress.

The allocator decrements the budget as it allocates and writes the unused
remainder back on success, letting the caller compute how many bytes were
actually spent. A value of 0 means unlimited (upgrade the whole object in
one move), preserving the previous behaviour. This is only consulted on a
defragmentation move, i.e. when defrag_old_tt is set.

v4:
 - Allow suboptimal to be NULL (Niranjana)
 - Reject defrag_bytes_remaining less than zero (Niranjana)
 - Move num_pages outside of loop (Niranjana)

Cc: Carlos Santa <carlos.santa@intel.com>
Cc: Ryan Neph <ryanneph@google.com>
Cc: Natalie Vock <nat@pixelcluster.dev>
Cc: Arun Pravin <arunpravin.paneerselvam@amd.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Cc: Maxime Ripard <mripard@kernel.org>
Cc: Thomas Zimmermann <tzimmermann@suse.de>
Cc: David Airlie <airlied@gmail.com>
Cc: Simona Vetter <simona@ffwll.ch>
Cc: dri-devel@lists.freedesktop.org
Cc: linux-kernel@vger.kernel.org
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Assisted-by: LLM
Signed-off-by: Matthew Brost <matthew.brost@intel.com>
---
 drivers/gpu/drm/ttm/ttm_pool.c | 103 +++++++++++++++++++++++++++++++--
 include/drm/ttm/ttm_bo.h       |  14 +++++
 2 files changed, 113 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_pool.c b/drivers/gpu/drm/ttm/ttm_pool.c
index 111d83da5971..9e95e368ff82 100644
--- a/drivers/gpu/drm/ttm/ttm_pool.c
+++ b/drivers/gpu/drm/ttm/ttm_pool.c
@@ -92,6 +92,11 @@ struct ttm_pool_dma {
  * @dma_addr: Pointer to the next tt dma_address entry to populate if any.
  * @remaining_pages: Remaining pages to populate.
  * @tt_caching: The requested cpu-caching for the pages allocated.
+ * @defrag_bytes_remaining: Byte budget for newly (re)allocated pages on a
+ * defragmentation move, seeded from ttm_operation_ctx::defrag_bytes_remaining.
+ * Pages harvested (borrowed) from the old tt are free and do not count; once
+ * this drops to zero the allocator stops upgrading and harvests the remainder.
+ * On completion it holds the unused budget. 0 means unlimited (no defrag cap).
  */
 struct ttm_pool_alloc_state {
 	struct page **pages;
@@ -99,6 +104,7 @@ struct ttm_pool_alloc_state {
 	dma_addr_t *dma_addr;
 	pgoff_t remaining_pages;
 	enum ttm_caching tt_caching;
+	s64 defrag_bytes_remaining;
 };
 
 /**
@@ -796,6 +802,7 @@ static void ttm_pool_alloc_state_init(const struct ttm_tt *tt,
 	alloc->dma_addr = tt->dma_address;
 	alloc->remaining_pages = tt->num_pages;
 	alloc->tt_caching = tt->caching;
+	alloc->defrag_bytes_remaining = 0;
 }
 
 /*
@@ -901,8 +908,13 @@ static int ttm_pool_harvest_page(struct ttm_tt *old_tt, unsigned int order,
 
 static int ttm_pool_harvest_remaining(struct ttm_pool *pool,
 				      struct ttm_tt *old_tt, pgoff_t off,
-				      struct ttm_pool_alloc_state *alloc)
+				      struct ttm_pool_alloc_state *alloc,
+				      bool *suboptimal)
 {
+	unsigned int beneficial = ttm_pool_beneficial_order(pool);
+	pgoff_t bnr = 1UL << beneficial;
+	pgoff_t num_pages = off + alloc->remaining_pages;
+
 	/*
 	 * @off is always an old-tt chunk head here, never a tail page, so
 	 * reading the per-chunk order below is safe. This holds because:
@@ -925,6 +937,20 @@ static int ttm_pool_harvest_remaining(struct ttm_pool *pool,
 		pgoff_t nr = 1UL << order;
 		int r;
 
+		/*
+		 * Only report a sub-optimal backing when a chunk we cannot
+		 * upgrade (out of budget/prealloc) sits in a beneficial-order
+		 * aligned region that fully fits in the tt: that region could
+		 * have been upgraded with more budget. A chunk below the
+		 * beneficial order is expected for the unaligned tail (the last
+		 * partial beneficial-order region) and for already beneficial-
+		 * order harvests - neither leaves real defrag work, so they must
+		 * not flag the tt for re-queue.
+		 */
+		if (suboptimal && beneficial && order < beneficial &&
+		    round_down(off, bnr) + bnr <= num_pages)
+			*suboptimal = true;
+
 		r = ttm_pool_harvest_page(old_tt, order, off, alloc);
 		if (r)
 			return r;
@@ -967,6 +993,7 @@ struct ttm_pool_alloc_iter {
 	struct ttm_tt *defrag_old_tt;
 	unsigned int beneficial_order;
 	gfp_t gfp_flags;
+	bool defrag_capped;
 
 	/* Mutated as the loop walks the orders. */
 	unsigned int order;
@@ -978,6 +1005,44 @@ struct ttm_pool_alloc_iter {
 	struct page *p;
 };
 
+/*
+ * Defrag move budget exhausted: the upgrade can make no further progress this
+ * pass. Snapshot @defrag_capped is set only when a byte budget was in force at
+ * entry.
+ */
+static bool ttm_pool_iter_defrag_exhausted(const struct ttm_pool_alloc_iter *it)
+{
+	if (!it->defrag_old_tt)
+		return false;
+
+	return it->defrag_capped && it->alloc->defrag_bytes_remaining <= 0;
+}
+
+/*
+ * Complete the new tt by harvesting the rest of the old tt as-is (borrowing its
+ * pages, including any still below beneficial order). Never fall back to in-lock
+ * reclaim for the shortfall - that would reintroduce the stall we preallocated
+ * to avoid. Only re-queue (flag) the tt when the harvested remainder is
+ * genuinely sub-optimal; if every remaining old chunk was already at beneficial
+ * order the move fully upgraded the object.
+ */
+static int ttm_pool_iter_harvest_rest(struct ttm_pool_alloc_iter *it)
+{
+	pgoff_t off = it->tt->num_pages - it->alloc->remaining_pages;
+	bool suboptimal = false;
+	int r;
+
+	r = ttm_pool_harvest_remaining(it->pool, it->defrag_old_tt, off,
+				       it->alloc, &suboptimal);
+	if (r)
+		return r;
+
+	if (suboptimal)
+		it->tt->page_flags |= TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED;
+
+	return 0;
+}
+
 /*
  * Defrag move: reuse an already beneficial-order chunk from the old tt at this
  * offset rather than reallocating it. Harvest whatever order the old chunk has
@@ -1082,7 +1147,7 @@ static int ttm_pool_iter_lower_order(struct ttm_pool_alloc_iter *it)
 
 			r = ttm_pool_harvest_remaining(it->pool,
 						       it->defrag_old_tt, off,
-						       it->alloc);
+						       it->alloc, NULL);
 			if (r)
 				return r;
 
@@ -1141,10 +1206,23 @@ static int __ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
 		gfp_flags |= GFP_HIGHUSER;
 
 	it.gfp_flags = gfp_flags;
+	it.defrag_capped = it.defrag_old_tt && alloc->defrag_bytes_remaining > 0;
 
 	for (it.order = ttm_pool_alloc_find_order(MAX_PAGE_ORDER, alloc);
 	     alloc->remaining_pages;
 	     it.order = ttm_pool_alloc_find_order(it.order, alloc)) {
+		/*
+		 * Out of defrag budget: harvest the rest of the old tt as-is and
+		 * stop (the tt is re-queued if the remainder is still
+		 * sub-optimal).
+		 */
+		if (ttm_pool_iter_defrag_exhausted(&it)) {
+			r = ttm_pool_iter_harvest_rest(&it);
+			if (r)
+				goto error_free_all;
+			break;
+		}
+
 		/* Reuse an already beneficial-order chunk from the old tt. */
 		r = ttm_pool_iter_reuse_old(&it);
 		if (r < 0)
@@ -1175,6 +1253,15 @@ static int __ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
 				goto error_free_all;
 		}
 
+		/*
+		 * Charge a newly (re)allocated chunk against the defrag move
+		 * budget. Harvested chunks borrow the old tt's pages for free
+		 * and never reach here.
+		 */
+		if (it.defrag_capped)
+			alloc->defrag_bytes_remaining -=
+				(s64)(1UL << it.order) << PAGE_SHIFT;
+
 		it.alloc_count++;
 	}
 
@@ -1224,14 +1311,22 @@ int ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
 		   struct ttm_operation_ctx *ctx)
 {
 	struct ttm_pool_alloc_state alloc;
+	int ret;
 
-	if (WARN_ON(ttm_tt_is_backed_up(tt)))
+	if (WARN_ON(ttm_tt_is_backed_up(tt)) ||
+	    WARN_ON(ctx->defrag_bytes_remaining < 0))
 		return -EINVAL;
 
 	tt->page_flags &= ~TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED;
 	ttm_pool_alloc_state_init(tt, &alloc);
+	alloc.defrag_bytes_remaining = ctx->defrag_bytes_remaining;
+
+	ret = __ttm_pool_alloc(pool, tt, ctx, &alloc, NULL);
+
+	/* Report the unused defrag budget back to the caller. */
+	ctx->defrag_bytes_remaining = alloc.defrag_bytes_remaining;
 
-	return __ttm_pool_alloc(pool, tt, ctx, &alloc, NULL);
+	return ret;
 }
 EXPORT_SYMBOL(ttm_pool_alloc);
 
diff --git a/include/drm/ttm/ttm_bo.h b/include/drm/ttm/ttm_bo.h
index 22d12fea6f3c..4ab67d6a926e 100644
--- a/include/drm/ttm/ttm_bo.h
+++ b/include/drm/ttm/ttm_bo.h
@@ -223,6 +223,20 @@ struct ttm_operation_ctx {
 	 * NULL for non-defrag operations.
 	 */
 	struct ttm_tt *defrag_old_tt;
+	/**
+	 * @defrag_bytes_remaining: Byte budget for newly allocated pages during
+	 * a defragmentation move. Only pages that are actually (re)allocated at
+	 * the beneficial order count against it; pages harvested (borrowed) from
+	 * @defrag_old_tt are free and do not. When the budget is exhausted the
+	 * pool allocator stops upgrading and completes the new tt by harvesting
+	 * the remainder of @defrag_old_tt, marking the tt sub-optimal so the
+	 * driver can resume on a later pass. The allocator decrements this as it
+	 * allocates, so on return it holds the unused budget (which the caller
+	 * can use to compute how many bytes were spent). A value of 0 means
+	 * unlimited (upgrade the whole object). Only consulted when
+	 * @defrag_old_tt is set.
+	 */
+	s64 defrag_bytes_remaining;
 	/**
 	 * @resv: Reservation object to be used together with
 	 * @allow_res_evict.
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v4 08/33] drm/ttm: Bound page (re)allocation per defragmentation move
  2026-12-01 23:48 ` [PATCH v4 08/33] drm/ttm: Bound page (re)allocation per defragmentation move Matthew Brost
@ 2026-12-02  6:10   ` Niranjana Vishwanathapura
  0 siblings, 0 replies; 3+ messages in thread
From: Niranjana Vishwanathapura @ 2026-12-02  6:10 UTC (permalink / raw)
  To: Matthew Brost
  Cc: intel-xe, dri-devel, Carlos Santa, Ryan Neph, Natalie Vock,
	Arun Pravin, Matthew Auld, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Simona Vetter, linux-kernel,
	Thomas Hellström

On Tue, Dec 01, 2026 at 03:48:50PM -0800, Matthew Brost wrote:
>A defragmentation move reallocates an object's backing at the device's
>beneficial order and harvests whatever the allocator cannot upgrade from
>the old tt. For a very large object this can reallocate (and have the
>driver re-copy) the entire backing in one move, which is expensive and
>can stall concurrent work for an unbounded stretch.
>
>Add an optional per-move byte budget so a large object can be upgraded in
>slices across successive moves. Plumb a new
>ttm_operation_ctx::defrag_bytes_remaining through to the pool allocator:
>only pages actually (re)allocated at the beneficial order are charged
>against it; pages harvested (borrowed) from defrag_old_tt are free and do
>not count. Once the budget is exhausted the allocator stops upgrading and
>completes the new tt by harvesting the remainder of the old tt as-is,
>marking the tt sub-optimal (TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED) so the
>driver re-queues it and a later move resumes the upgrade. The slices
>already upgraded come back as free already-beneficial harvests on the
>next pass, so each move spends budget only on new forward progress.
>
>The allocator decrements the budget as it allocates and writes the unused
>remainder back on success, letting the caller compute how many bytes were
>actually spent. A value of 0 means unlimited (upgrade the whole object in
>one move), preserving the previous behaviour. This is only consulted on a
>defragmentation move, i.e. when defrag_old_tt is set.
>
>v4:
> - Allow suboptimal to be NULL (Niranjana)
> - Reject defrag_bytes_remaining less than zero (Niranjana)
> - Move num_pages outside of loop (Niranjana)
>
>Cc: Carlos Santa <carlos.santa@intel.com>
>Cc: Ryan Neph <ryanneph@google.com>
>Cc: Natalie Vock <nat@pixelcluster.dev>
>Cc: Arun Pravin <arunpravin.paneerselvam@amd.com>
>Cc: Matthew Auld <matthew.auld@intel.com>
>Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
>Cc: Maxime Ripard <mripard@kernel.org>
>Cc: Thomas Zimmermann <tzimmermann@suse.de>
>Cc: David Airlie <airlied@gmail.com>
>Cc: Simona Vetter <simona@ffwll.ch>
>Cc: dri-devel@lists.freedesktop.org
>Cc: linux-kernel@vger.kernel.org
>Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
>Assisted-by: LLM
>Signed-off-by: Matthew Brost <matthew.brost@intel.com>
>---
> drivers/gpu/drm/ttm/ttm_pool.c | 103 +++++++++++++++++++++++++++++++--
> include/drm/ttm/ttm_bo.h       |  14 +++++
> 2 files changed, 113 insertions(+), 4 deletions(-)
>
>diff --git a/drivers/gpu/drm/ttm/ttm_pool.c b/drivers/gpu/drm/ttm/ttm_pool.c
>index 111d83da5971..9e95e368ff82 100644
>--- a/drivers/gpu/drm/ttm/ttm_pool.c
>+++ b/drivers/gpu/drm/ttm/ttm_pool.c
>@@ -92,6 +92,11 @@ struct ttm_pool_dma {
>  * @dma_addr: Pointer to the next tt dma_address entry to populate if any.
>  * @remaining_pages: Remaining pages to populate.
>  * @tt_caching: The requested cpu-caching for the pages allocated.
>+ * @defrag_bytes_remaining: Byte budget for newly (re)allocated pages on a
>+ * defragmentation move, seeded from ttm_operation_ctx::defrag_bytes_remaining.
>+ * Pages harvested (borrowed) from the old tt are free and do not count; once
>+ * this drops to zero the allocator stops upgrading and harvests the remainder.
>+ * On completion it holds the unused budget. 0 means unlimited (no defrag cap).
>  */
> struct ttm_pool_alloc_state {
> 	struct page **pages;
>@@ -99,6 +104,7 @@ struct ttm_pool_alloc_state {
> 	dma_addr_t *dma_addr;
> 	pgoff_t remaining_pages;
> 	enum ttm_caching tt_caching;
>+	s64 defrag_bytes_remaining;
> };
>
> /**
>@@ -796,6 +802,7 @@ static void ttm_pool_alloc_state_init(const struct ttm_tt *tt,
> 	alloc->dma_addr = tt->dma_address;
> 	alloc->remaining_pages = tt->num_pages;
> 	alloc->tt_caching = tt->caching;
>+	alloc->defrag_bytes_remaining = 0;
> }
>
> /*
>@@ -901,8 +908,13 @@ static int ttm_pool_harvest_page(struct ttm_tt *old_tt, unsigned int order,
>
> static int ttm_pool_harvest_remaining(struct ttm_pool *pool,
> 				      struct ttm_tt *old_tt, pgoff_t off,
>-				      struct ttm_pool_alloc_state *alloc)
>+				      struct ttm_pool_alloc_state *alloc,
>+				      bool *suboptimal)
> {
>+	unsigned int beneficial = ttm_pool_beneficial_order(pool);
>+	pgoff_t bnr = 1UL << beneficial;
>+	pgoff_t num_pages = off + alloc->remaining_pages;
>+
> 	/*
> 	 * @off is always an old-tt chunk head here, never a tail page, so
> 	 * reading the per-chunk order below is safe. This holds because:
>@@ -925,6 +937,20 @@ static int ttm_pool_harvest_remaining(struct ttm_pool *pool,
> 		pgoff_t nr = 1UL << order;
> 		int r;
>
>+		/*
>+		 * Only report a sub-optimal backing when a chunk we cannot
>+		 * upgrade (out of budget/prealloc) sits in a beneficial-order
>+		 * aligned region that fully fits in the tt: that region could
>+		 * have been upgraded with more budget. A chunk below the
>+		 * beneficial order is expected for the unaligned tail (the last
>+		 * partial beneficial-order region) and for already beneficial-
>+		 * order harvests - neither leaves real defrag work, so they must
>+		 * not flag the tt for re-queue.
>+		 */
>+		if (suboptimal && beneficial && order < beneficial &&
>+		    round_down(off, bnr) + bnr <= num_pages)
>+			*suboptimal = true;
>+
> 		r = ttm_pool_harvest_page(old_tt, order, off, alloc);
> 		if (r)
> 			return r;
>@@ -967,6 +993,7 @@ struct ttm_pool_alloc_iter {
> 	struct ttm_tt *defrag_old_tt;
> 	unsigned int beneficial_order;
> 	gfp_t gfp_flags;
>+	bool defrag_capped;

If using kernel-doc for the structure, the fields need documentation.
With that taken care of,
Reviewed-by: Niranjana Vishwanathapura <niranjana.vishwanathapura@intel.com>

>
> 	/* Mutated as the loop walks the orders. */
> 	unsigned int order;
>@@ -978,6 +1005,44 @@ struct ttm_pool_alloc_iter {
> 	struct page *p;
> };
>
>+/*
>+ * Defrag move budget exhausted: the upgrade can make no further progress this
>+ * pass. Snapshot @defrag_capped is set only when a byte budget was in force at
>+ * entry.
>+ */
>+static bool ttm_pool_iter_defrag_exhausted(const struct ttm_pool_alloc_iter *it)
>+{
>+	if (!it->defrag_old_tt)
>+		return false;
>+
>+	return it->defrag_capped && it->alloc->defrag_bytes_remaining <= 0;
>+}
>+
>+/*
>+ * Complete the new tt by harvesting the rest of the old tt as-is (borrowing its
>+ * pages, including any still below beneficial order). Never fall back to in-lock
>+ * reclaim for the shortfall - that would reintroduce the stall we preallocated
>+ * to avoid. Only re-queue (flag) the tt when the harvested remainder is
>+ * genuinely sub-optimal; if every remaining old chunk was already at beneficial
>+ * order the move fully upgraded the object.
>+ */
>+static int ttm_pool_iter_harvest_rest(struct ttm_pool_alloc_iter *it)
>+{
>+	pgoff_t off = it->tt->num_pages - it->alloc->remaining_pages;
>+	bool suboptimal = false;
>+	int r;
>+
>+	r = ttm_pool_harvest_remaining(it->pool, it->defrag_old_tt, off,
>+				       it->alloc, &suboptimal);
>+	if (r)
>+		return r;
>+
>+	if (suboptimal)
>+		it->tt->page_flags |= TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED;
>+
>+	return 0;
>+}
>+
> /*
>  * Defrag move: reuse an already beneficial-order chunk from the old tt at this
>  * offset rather than reallocating it. Harvest whatever order the old chunk has
>@@ -1082,7 +1147,7 @@ static int ttm_pool_iter_lower_order(struct ttm_pool_alloc_iter *it)
>
> 			r = ttm_pool_harvest_remaining(it->pool,
> 						       it->defrag_old_tt, off,
>-						       it->alloc);
>+						       it->alloc, NULL);
> 			if (r)
> 				return r;
>
>@@ -1141,10 +1206,23 @@ static int __ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
> 		gfp_flags |= GFP_HIGHUSER;
>
> 	it.gfp_flags = gfp_flags;
>+	it.defrag_capped = it.defrag_old_tt && alloc->defrag_bytes_remaining > 0;
>
> 	for (it.order = ttm_pool_alloc_find_order(MAX_PAGE_ORDER, alloc);
> 	     alloc->remaining_pages;
> 	     it.order = ttm_pool_alloc_find_order(it.order, alloc)) {
>+		/*
>+		 * Out of defrag budget: harvest the rest of the old tt as-is and
>+		 * stop (the tt is re-queued if the remainder is still
>+		 * sub-optimal).
>+		 */
>+		if (ttm_pool_iter_defrag_exhausted(&it)) {
>+			r = ttm_pool_iter_harvest_rest(&it);
>+			if (r)
>+				goto error_free_all;
>+			break;
>+		}
>+
> 		/* Reuse an already beneficial-order chunk from the old tt. */
> 		r = ttm_pool_iter_reuse_old(&it);
> 		if (r < 0)
>@@ -1175,6 +1253,15 @@ static int __ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
> 				goto error_free_all;
> 		}
>
>+		/*
>+		 * Charge a newly (re)allocated chunk against the defrag move
>+		 * budget. Harvested chunks borrow the old tt's pages for free
>+		 * and never reach here.
>+		 */
>+		if (it.defrag_capped)
>+			alloc->defrag_bytes_remaining -=
>+				(s64)(1UL << it.order) << PAGE_SHIFT;
>+
> 		it.alloc_count++;
> 	}
>
>@@ -1224,14 +1311,22 @@ int ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
> 		   struct ttm_operation_ctx *ctx)
> {
> 	struct ttm_pool_alloc_state alloc;
>+	int ret;
>
>-	if (WARN_ON(ttm_tt_is_backed_up(tt)))
>+	if (WARN_ON(ttm_tt_is_backed_up(tt)) ||
>+	    WARN_ON(ctx->defrag_bytes_remaining < 0))
> 		return -EINVAL;
>
> 	tt->page_flags &= ~TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED;
> 	ttm_pool_alloc_state_init(tt, &alloc);
>+	alloc.defrag_bytes_remaining = ctx->defrag_bytes_remaining;
>+
>+	ret = __ttm_pool_alloc(pool, tt, ctx, &alloc, NULL);
>+
>+	/* Report the unused defrag budget back to the caller. */
>+	ctx->defrag_bytes_remaining = alloc.defrag_bytes_remaining;
>
>-	return __ttm_pool_alloc(pool, tt, ctx, &alloc, NULL);
>+	return ret;
> }
> EXPORT_SYMBOL(ttm_pool_alloc);
>
>diff --git a/include/drm/ttm/ttm_bo.h b/include/drm/ttm/ttm_bo.h
>index 22d12fea6f3c..4ab67d6a926e 100644
>--- a/include/drm/ttm/ttm_bo.h
>+++ b/include/drm/ttm/ttm_bo.h
>@@ -223,6 +223,20 @@ struct ttm_operation_ctx {
> 	 * NULL for non-defrag operations.
> 	 */
> 	struct ttm_tt *defrag_old_tt;
>+	/**
>+	 * @defrag_bytes_remaining: Byte budget for newly allocated pages during
>+	 * a defragmentation move. Only pages that are actually (re)allocated at
>+	 * the beneficial order count against it; pages harvested (borrowed) from
>+	 * @defrag_old_tt are free and do not. When the budget is exhausted the
>+	 * pool allocator stops upgrading and completes the new tt by harvesting
>+	 * the remainder of @defrag_old_tt, marking the tt sub-optimal so the
>+	 * driver can resume on a later pass. The allocator decrements this as it
>+	 * allocates, so on return it holds the unused budget (which the caller
>+	 * can use to compute how many bytes were spent). A value of 0 means
>+	 * unlimited (upgrade the whole object). Only consulted when
>+	 * @defrag_old_tt is set.
>+	 */
>+	s64 defrag_bytes_remaining;
> 	/**
> 	 * @resv: Reservation object to be used together with
> 	 * @allow_res_evict.
>-- 
>2.34.1
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v4 08/33] drm/ttm: Bound page (re)allocation per defragmentation move
@ 2026-12-02 23:48 kernel test robot
  0 siblings, 0 replies; 3+ messages in thread
From: kernel test robot @ 2026-12-02 23:48 UTC (permalink / raw)
  To: oe-kbuild; +Cc: lkp

:::::: 
:::::: Manual check reason: "same reports for this branch"
:::::: 

BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
In-Reply-To: <20261201234915.3305331-9-matthew.brost@intel.com>
References: <20261201234915.3305331-9-matthew.brost@intel.com>
TO: Matthew Brost <matthew.brost@intel.com>
TO: intel-xe@lists.freedesktop.org
TO: dri-devel@lists.freedesktop.org
CC: Carlos Santa <carlos.santa@intel.com>
CC: Ryan Neph <ryanneph@google.com>
CC: Natalie Vock <nat@pixelcluster.dev>
CC: Arun Pravin <arunpravin.paneerselvam@amd.com>
CC: Matthew Auld <matthew.auld@intel.com>
CC: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
CC: Maxime Ripard <mripard@kernel.org>
CC: Thomas Zimmermann <tzimmermann@suse.de>
CC: David Airlie <airlied@gmail.com>
CC: Simona Vetter <simona@ffwll.ch>
CC: linux-kernel@vger.kernel.org
CC: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>

Hi Matthew,

kernel test robot noticed the following build warnings:

[auto build test WARNING on drm-tip/drm-tip]
[also build test WARNING on next-20261130]
[cannot apply to drm-xe/drm-xe-next drm-misc/drm-misc-next daeinki-drm-exynos/exynos-drm-next drm/drm-next drm-i915/for-linux-next drm-i915/for-linux-next-fixes linus/master v7.4-rc5]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Matthew-Brost/drm-ttm-pool-Allow-backing-off-reclaim-at-the-beneficial-order/20261201-154843
base:   https://gitlab.freedesktop.org/drm/tip.git drm-tip
patch link:    https://lore.kernel.org/r/20261201234915.3305331-9-matthew.brost%40intel.com
patch subject: [PATCH v4 08/33] drm/ttm: Bound page (re)allocation per defragmentation move
:::::: branch date: 23 hours ago
:::::: commit date: 23 hours ago
config: x86_64-rhel-9.4 (https://download.01.org/0day-ci/archive/20261203/20261203071336.MjsLE1i8-lkp@intel.com/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261203/20261203071336.MjsLE1i8-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/r/20261203071336.MjsLE1i8-lkp@intel.com/

All warnings (new ones prefixed by >>):

   Warning: drivers/gpu/drm/ttm/ttm_pool.c:1005 struct member 'pool' not described in 'ttm_pool_alloc_iter'
   Warning: drivers/gpu/drm/ttm/ttm_pool.c:1005 struct member 'tt' not described in 'ttm_pool_alloc_iter'
   Warning: drivers/gpu/drm/ttm/ttm_pool.c:1005 struct member 'ctx' not described in 'ttm_pool_alloc_iter'
   Warning: drivers/gpu/drm/ttm/ttm_pool.c:1005 struct member 'alloc' not described in 'ttm_pool_alloc_iter'
   Warning: drivers/gpu/drm/ttm/ttm_pool.c:1005 struct member 'defrag_old_tt' not described in 'ttm_pool_alloc_iter'
   Warning: drivers/gpu/drm/ttm/ttm_pool.c:1005 struct member 'beneficial_order' not described in 'ttm_pool_alloc_iter'
   Warning: drivers/gpu/drm/ttm/ttm_pool.c:1005 struct member 'gfp_flags' not described in 'ttm_pool_alloc_iter'
>> Warning: drivers/gpu/drm/ttm/ttm_pool.c:1005 struct member 'defrag_capped' not described in 'ttm_pool_alloc_iter'
   Warning: drivers/gpu/drm/ttm/ttm_pool.c:1005 struct member 'order' not described in 'ttm_pool_alloc_iter'
   Warning: drivers/gpu/drm/ttm/ttm_pool.c:1005 struct member 'page_caching' not described in 'ttm_pool_alloc_iter'
   Warning: drivers/gpu/drm/ttm/ttm_pool.c:1005 struct member 'allow_pools' not described in 'ttm_pool_alloc_iter'
   Warning: drivers/gpu/drm/ttm/ttm_pool.c:1005 struct member 'fail_beneficial' not described in 'ttm_pool_alloc_iter'
   Warning: drivers/gpu/drm/ttm/ttm_pool.c:1005 struct member 'alloc_count' not described in 'ttm_pool_alloc_iter'
   Warning: drivers/gpu/drm/ttm/ttm_pool.c:1005 struct member 'old_cursor' not described in 'ttm_pool_alloc_iter'
   Warning: drivers/gpu/drm/ttm/ttm_pool.c:1005 struct member 'p' not described in 'ttm_pool_alloc_iter'
   Warning: drivers/gpu/drm/ttm/ttm_pool.c:1005 struct member 'pool' not described in 'ttm_pool_alloc_iter'
   Warning: drivers/gpu/drm/ttm/ttm_pool.c:1005 struct member 'tt' not described in 'ttm_pool_alloc_iter'
   Warning: drivers/gpu/drm/ttm/ttm_pool.c:1005 struct member 'ctx' not described in 'ttm_pool_alloc_iter'
   Warning: drivers/gpu/drm/ttm/ttm_pool.c:1005 struct member 'alloc' not described in 'ttm_pool_alloc_iter'
   Warning: drivers/gpu/drm/ttm/ttm_pool.c:1005 struct member 'defrag_old_tt' not described in 'ttm_pool_alloc_iter'
   Warning: drivers/gpu/drm/ttm/ttm_pool.c:1005 struct member 'beneficial_order' not described in 'ttm_pool_alloc_iter'
   Warning: drivers/gpu/drm/ttm/ttm_pool.c:1005 struct member 'gfp_flags' not described in 'ttm_pool_alloc_iter'
>> Warning: drivers/gpu/drm/ttm/ttm_pool.c:1005 struct member 'defrag_capped' not described in 'ttm_pool_alloc_iter'
   Warning: drivers/gpu/drm/ttm/ttm_pool.c:1005 struct member 'order' not described in 'ttm_pool_alloc_iter'
   Warning: drivers/gpu/drm/ttm/ttm_pool.c:1005 struct member 'page_caching' not described in 'ttm_pool_alloc_iter'
   Warning: drivers/gpu/drm/ttm/ttm_pool.c:1005 struct member 'allow_pools' not described in 'ttm_pool_alloc_iter'
   Warning: drivers/gpu/drm/ttm/ttm_pool.c:1005 struct member 'fail_beneficial' not described in 'ttm_pool_alloc_iter'
   Warning: drivers/gpu/drm/ttm/ttm_pool.c:1005 struct member 'alloc_count' not described in 'ttm_pool_alloc_iter'
   Warning: drivers/gpu/drm/ttm/ttm_pool.c:1005 struct member 'old_cursor' not described in 'ttm_pool_alloc_iter'
   Warning: drivers/gpu/drm/ttm/ttm_pool.c:1005 struct member 'p' not described in 'ttm_pool_alloc_iter'

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-12-02 23:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 23:48 [PATCH v4 08/33] drm/ttm: Bound page (re)allocation per defragmentation move kernel test robot
  -- strict thread matches above, loose matches on Subject: below --
2026-12-01 23:48 [PATCH v4 00/33] drm/ttm, drm/xe: Avoid foreground high-order reclaim and defragment sub-optimally backed BOs Matthew Brost
2026-12-01 23:48 ` [PATCH v4 08/33] drm/ttm: Bound page (re)allocation per defragmentation move Matthew Brost
2026-12-02  6:10   ` Niranjana Vishwanathapura

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.