The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Matthew Brost <matthew.brost@intel.com>
To: Niranjana Vishwanathapura <niranjana.vishwanathapura@intel.com>
Cc: intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
	"Carlos Santa" <carlos.santa@intel.com>,
	"Ryan Neph" <ryanneph@google.com>,
	"Christian Koenig" <christian.koenig@amd.com>,
	"Huang Rui" <ray.huang@amd.com>,
	"Matthew Auld" <matthew.auld@intel.com>,
	"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
	"Maxime Ripard" <mripard@kernel.org>,
	"Thomas Zimmermann" <tzimmermann@suse.de>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	linux-kernel@vger.kernel.org,
	"Thomas Hellström" <thomas.hellstrom@linux.intel.com>
Subject: Re: [PATCH v3 10/33] drm/ttm: Add full out-of-lock preallocation for ttm_pool_alloc()
Date: Tue, 1 Dec 2026 09:25:40 -0800	[thread overview]
Message-ID: <aw8DFH4lHGTAHz4x@gsse-cloud1.jf.intel.com> (raw)
In-Reply-To: <awEmGqzlcitPQtIv@nvishwa1-desk>

On Fri, Nov 20, 2026 at 09:03:22PM -0800, Niranjana Vishwanathapura wrote:
> On Thu, Nov 19, 2026 at 09:48:23PM -0800, Matthew Brost wrote:
> > On Tue, Nov 10, 2026 at 11:31:53PM -0800, Niranjana Vishwanathapura wrote:
> > > On Fri, Jul 10, 2026 at 07:55:56PM -0700, Matthew Brost wrote:
> > > > ttm_pool_prealloc_fill() lets a driver preallocate beneficial-order pages
> > > > outside the dma-resv lock for a defragmentation move, so the high-order
> > > > allocations that may stall in reclaim/compaction happen off the critical
> > > > section.  That bag is deliberately partial: it holds only interchangeable
> > > > beneficial-order chunks and the allocator consumes it opportunistically,
> > > > falling back to in-line allocation for everything else.
> > > >
> > > > An ordinary populate of a system-memory buffer object has the same
> > > > problem - the whole backing is allocated under the dma-resv lock - but no
> > > > way to move it out of the critical section, because the existing bag does
> > > > not cover sub-beneficial orders and does not describe a full tt.
> > > >
> > > > Add a "full" flavour of the same preallocation mechanism:
> > > >
> > > >  - struct ttm_pool_prealloc gains a @full flag.  In full mode the bag is
> > > >    an ordered tiling of an entire tt at mixed orders (pool pages
> > > >    included), rather than a set of interchangeable beneficial-order
> > > >    chunks.  The per-chunk order is recorded on the page itself and read
> > > >    back at consume time, so no parallel order array is needed.
> > > >
> > > >  - ttm_pool_prealloc_fill_full() allocates the whole backing for a tt of
> > > >    @num_pages pages up front, mirroring the in-line allocator's order
> > > >    walk (highest order first, capped by the remaining page count).  It
> > > >    reuses the existing unlocked helpers (ttm_pool_prealloc_gfp(),
> > > >    ttm_pool_set_caching()) via a new ttm_pool_take_page() helper that
> > > >    tries a same-order pool page before a fresh system allocation.
> > > >
> > > >  - ttm_pool_prealloc_fini() frees any unconsumed tail at each chunk's own
> > > >    order when @full.
> > > >
> > > >  - ttm_pool_prealloc_fill_full() takes a @beneficial_reclaim_backoff
> > > >    argument, plumbed to ttm_pool_alloc_page(), that lets the caller
> > > >    allocate higher-order chunks without aggressive reclaim/compaction.
> > > >    This suits a driver that upgrades suboptimal pages to beneficial order
> > > >    in place later (e.g. via a background defragmenter) and so has no need
> > > >    to stall the user context reclaiming for contiguity up front.
> > > >
> > > >  - __ttm_pool_alloc() consumes a full bag with a single early branch in
> > > >    ttm_pool_iter_acquire_page(): install the next chunk as-is (order
> > > >    taken from the page) and return; once the best-effort bag is drained
> > > >    the loop falls through to normal in-line allocation.  The defrag
> > > >    harvest and reuse-old phases are inert here as there is no
> > > >    defrag_old_tt.
> > > >
> > > > Like the defrag bag, this is best-effort: a short fill is fine (the pool
> > > > allocates the shortfall in-line) and DMA-alloc pools are unsupported
> > > > (caching is applied on the kernel mapping).  No functional change for
> > > > existing users; the new fill routine has no in-tree caller yet.
> > > >
> > > > Cc: Carlos Santa <carlos.santa@intel.com>
> > > > Cc: Ryan Neph <ryanneph@google.com>
> > > > Cc: Christian Koenig <christian.koenig@amd.com>
> > > > Cc: Huang Rui <ray.huang@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: GitHub_Copilot:claude-opus-4.8
> > > > Signed-off-by: Matthew Brost <matthew.brost@intel.com>
> > > > ---
> > > > drivers/gpu/drm/ttm/ttm_pool.c | 232 ++++++++++++++++++++++++++++++++-
> > > > include/drm/ttm/ttm_bo.h       |  19 +--
> > > > include/drm/ttm/ttm_pool.h     |  27 +++-
> > > > 3 files changed, 258 insertions(+), 20 deletions(-)
> > > >
> > > > diff --git a/drivers/gpu/drm/ttm/ttm_pool.c b/drivers/gpu/drm/ttm/ttm_pool.c
> > > > index da7d132c8297..4746f5d8cd7e 100644
> > > > --- a/drivers/gpu/drm/ttm/ttm_pool.c
> > > > +++ b/drivers/gpu/drm/ttm/ttm_pool.c
> > > > @@ -1046,6 +1046,7 @@ int ttm_pool_prealloc_fill(struct ttm_pool *pool, enum ttm_caching tt_caching,
> > > > 	pp->caching = tt_caching;
> > > > 	pp->count = 0;
> > > > 	pp->used = 0;
> > > > +	pp->full = false;
> > > >
> > > > 	/* Nothing to gain without a beneficial order or for DMA-alloc pools. */
> > > > 	if (!order || !count || ttm_pool_uses_dma_alloc(pool))
> > > > @@ -1102,6 +1103,187 @@ int ttm_pool_prealloc_fill(struct ttm_pool *pool, enum ttm_caching tt_caching,
> > > > }
> > > > EXPORT_SYMBOL(ttm_pool_prealloc_fill);
> > > >
> > > > +/*
> > > > + * Acquire a single *@order chunk, trying a same-order pool page first (already
> > > > + * carries @caching) then a fresh system allocation (write-back). Runs unlocked.
> > > > + * When @beneficial_reclaim_backoff is set, higher-order system allocations skip
> > > > + * aggressive reclaim/compaction (see ttm_pool_alloc_page()).
> > > > + *
> > > > + * A fresh system page is write-back and needs the tt's caching applied later in
> > > > + * bulk; *@need_caching is set true for it and false for a (pre-cached) pool
> > > > + * page.
> > > > + *
> > > > + * On a genuine failure *@order is left untouched (the caller lowers it by one
> > > > + * and retries). Fault injection instead pretends allocation at (or above) the
> > > > + * beneficial order failed and lowers *@order to the beneficial order, so the
> > > > + * caller's next attempt lands below it - mirroring the in-line acquire path's
> > > > + * fail_beneficial jump and exercising the beneficial_order_failed tracking
> > > > + * without driving the system into real fragmentation.
> > > > + *
> > > > + * Returns NULL if no page of *@order could be obtained.
> > > > + */
> > > > +static struct page *ttm_pool_take_page(struct ttm_pool *pool,
> > > > +				       enum ttm_caching caching,
> > > > +				       unsigned int *order, gfp_t gfp,
> > > > +				       bool *need_caching,
> > > > +				       bool beneficial_reclaim_backoff)
> > > > +{
> > > > +	unsigned int beneficial = ttm_pool_beneficial_order(pool);
> > > > +	struct ttm_pool_type *pt;
> > > > +	struct page *p;
> > > > +
> > > > +	*need_caching = false;
> > > > +
> > > > +	if (IS_ENABLED(CONFIG_FAULT_INJECTION) && beneficial &&
> > > > +	    *order >= beneficial &&
> > > > +	    should_fail(&beneficial_order_fault_inject, 1)) {
> > > > +		*order = beneficial;
> > > > +		return NULL;
> > > > +	}
> > > > +
> > > > +	pt = ttm_pool_select_type(pool, caching, *order);
> > > > +	if (pt) {
> > > > +		p = ttm_pool_type_take(pt, ttm_pool_nid(pool));
> > > > +		if (p)
> > > > +			return p;	/* pool page already carries @caching */
> > > > +	}
> > > > +
> > > > +	p = ttm_pool_alloc_page(pool, gfp, *order, beneficial_reclaim_backoff);
> > > > +	if (!p)
> > > > +		return NULL;
> > > > +
> > > > +	/* Fresh system page is write-back; caller applies @caching in bulk. */
> > > > +	*need_caching = true;
> > > > +	return p;
> > > > +}
> > > > +
> > > > +/**
> > > > + * ttm_pool_prealloc_fill_full() - Preallocate a whole tt's backing outside any
> > > > + * lock
> > > > + * @pool: The pool to allocate from.
> > > > + * @tt_caching: The requested cpu-caching for the pages allocated.
> > > > + * @pp: Prealloc bag to fill; marked @full and tiled with mixed-order chunks.
> > > > + * @num_pages: Number of 4K pages the tt needs backed.
> > > > + *
> > > > + * Unlike ttm_pool_prealloc_fill() (which parks a bag of interchangeable
> > > > + * beneficial-order defrag chunks), this allocates the ENTIRE backing for a tt
> > > > + * of @num_pages pages up front, at whatever mix of orders is available (pool
> > > > + * pages included), so that the subsequent __ttm_pool_alloc() under the dma-resv
> > > > + * lock merely installs the pages without stalling in reclaim/compaction. The
> > > > + * chunk orders mirror the in-line allocator's order walk; each chunk's order is
> > > > + * recorded on the page itself and read back at consume time.
> > > > + *
> > > > + * May sleep/reclaim freely as it runs unlocked. When
> > > > + * @beneficial_reclaim_backoff is set, higher-order chunks are taken without
> > > > + * aggressive reclaim/compaction: the caller relies on a background
> > > > + * defragmenter to upgrade to beneficial-order pages in place later, so there
> > > > + * is no need to stall the user context reclaiming for contiguity here. A short
> > > > + * fill is fine: the pool falls back to in-line allocation for the shortfall.
> > > > + * DMA-alloc pools are not supported (the bag stays empty). Returns 0 (release
> > > > + * with ttm_pool_prealloc_fini()).
> > > > + */
> > > > +int ttm_pool_prealloc_fill_full(struct ttm_pool *pool,
> > > > +				enum ttm_caching tt_caching,
> > > > +				struct ttm_pool_prealloc *pp,
> > > > +				unsigned int num_pages,
> > > > +				bool beneficial_reclaim_backoff)
> > > > +{
> > > > +	gfp_t gfp = ttm_pool_prealloc_gfp(pool) | __GFP_ZERO |
> > > > +		__GFP_RETRY_MAYFAIL | __GFP_NOWARN;
> > > 
> > > Assisted-by: LLM
> > > 
> > 
> > Yes.
> > 
> > > __GFP_RETRY_MAYFAIL is bit confusing here as as ttm_pool_alloc_page()
> > > is expected to suppy it (patch 1). I see that only applies to
> > > beneficial order, but here we have mixed-order and hence it is set
> > > here. May be add some documentation to clarify it?
> > > 
> > 
> > Ye, this is a bit confusing. ttm_pool_alloc_page will change these flags
> > based beneficial_reclaim_backoff / beneficial_order. In general I chose
> > to set __GFP_RETRY_MAYFAIL here as a default to avoid the prealloc to
> > avoid any chance of triggering OOM - i.e., if prealloc fails for
> > whatever reason we fall back the traditional TTM alloc path which I
> > think is correct.
> > 
> > So maybe '__GFP_RETRY_MAYFAIL is set to never trigger OOM on prealloc'.
> > 
> 
> Sounds good.
> 
> > > > +	unsigned int highest = MAX_PAGE_ORDER;
> > > > +	unsigned int remaining = num_pages;
> > > > +	struct page **cpages = NULL;
> > > > +	unsigned int ncpages = 0;
> > > > +	int r;
> > > > +
> > > > +	pp->pages = NULL;
> > > > +	pp->order = 0;
> > > > +	pp->caching = tt_caching;
> > > > +	pp->count = 0;
> > > > +	pp->used = 0;
> > > > +	pp->full = true;
> > > > +
> > > > +	/* Caching is applied on the kernel mapping, so DMA-alloc is unsupported. */
> > > > +	if (!num_pages || ttm_pool_uses_dma_alloc(pool))
> > > > +		return 0;
> > > > +
> > > > +	/* Worst case is one order-0 chunk per page. */
> > > > +	pp->pages = kvzalloc_objs(*pp->pages, num_pages);
> > > > +	if (!pp->pages)
> > > > +		return 0;
> > > > +
> > > > +	/*
> > > > +	 * Fresh write-back chunks get their caching changed in a single
> > > > +	 * set_pages_array_*() after the fill; collect their constituent pages
> > > > +	 * into an unpacked scratch array (one entry per 4K page) since the
> > > > +	 * packed bag holds mixed-order chunks. Cached tts and pool pages need
> > > > +	 * no change (and non-x86 handles caching at map time).
> > > > +	 */
> > > > +	if (IS_ENABLED(CONFIG_X86) && tt_caching != ttm_cached) {
> > > > +		cpages = kvzalloc_objs(*cpages, num_pages);
> > > 
> > > Same comment as in patch 9.
> > > cpages is tansient memory and unlike patch 9, it is not bounded by 'budget' here.
> > 
> > It is not bounded by any budget rather by the number pages in the BO
> > size.
> > 
> 
> I mean in defragment case, it is bounded by XE_BO_DEFRAG_SIZE_LIMIT, but
> in gem_create ioctl, it is not. So, for a 1GB BO, the required memory for
> this array is 2MB.
> 

This is true, but again the right trade is memory + one expensive call
vs code complexity + many expensive calls.

> > > may be it can be avoided altogether by using a one static 4k page in the
> > > pool and flush it with set_pages_array*() as and when it fills up?
> > > 
> > 
> > I think that is the wrong trade. set_pages_array on x86 does some
> > hardware interaction which is rather expensive, thus the entire reason
> > TTM pool exist to avoid calling set_pages_array on every alloc / free.
> > i.e., more tansient memory vs 1 hardware interaction is the right trade.
> > 
> 
> I meant batched set_pages_array*() call with fixed batch size (not for
> every page). But I agree, we shouldn't complicate it unless it is really
> required. So, code is fine as is.
> 
> > > > +		if (!cpages) {
> > > > +			kvfree(pp->pages);
> > > > +			pp->pages = NULL;
> > > > +			return 0;
> > > > +		}
> > > > +	}
> > > > +
> > > > +	while (remaining) {
> > > > +		unsigned int order = min_t(unsigned int, highest,
> > > > +					   __fls(remaining));
> > > > +		bool need_caching;
> > > > +		struct page *p;
> > > > +
> > > > +		for (;;) {
> > > > +			p = ttm_pool_take_page(pool, tt_caching, &order, gfp,
> > > > +					       &need_caching,
> > > > +					       beneficial_reclaim_backoff);
> > > > +			if (p)
> > > > +				break;
> > > > +			if (!order)
> > > > +				goto apply_caching;	/* short fill */
> > > > +			/*
> > > > +			 * Genuine failure: retry one order down. A fault
> > > > +			 * injection lowered @order to the beneficial order
> > > > +			 * above, so this drops it below - landing on a
> > > > +			 * sub-optimal (defrag-worthy) chunk.
> > > > +			 */
> > > > +			order--;
> > > > +		}
> > > > +
> > > > +		pp->pages[pp->count++] = p;
> > > > +		if (cpages && need_caching)
> > > > +			ttm_pool_prealloc_stage_caching(cpages, &ncpages, p,
> > > > +							order);
> > > > +		remaining -= 1u << order;
> > > > +		highest = order;
> > > > +	}
> > > > +
> > > > +apply_caching:
> > > > +	/*
> > > > +	 * Apply the requested caching to every collected page in one shot. On
> > > > +	 * failure the pages' caching is indeterminate, so drop the whole bag
> > > > +	 * (freeing restores write-back) and let the consumer allocate in-line.
> > > > +	 */
> > > > +	r = ttm_pool_prealloc_apply_caching(tt_caching, cpages, ncpages);
> > > > +	kvfree(cpages);
> > > > +	if (r) {
> > > > +		unsigned int i;
> > > > +
> > > > +		for (i = 0; i < pp->count; i++) {
> > > > +			struct page *p = pp->pages[i];
> > > > +
> > > > +			ttm_pool_free_page(pool, tt_caching,
> > > > +					   ttm_pool_page_order_nodma(p), p,
> > > > +					   false);
> > > > +		}
> > > > +		pp->count = 0;
> > > > +	}
> > > > +
> > > > +	return 0;
> > > > +}
> > > > +EXPORT_SYMBOL(ttm_pool_prealloc_fill_full);
> > > 
> > > It has lot of code common with ttm_pool_prealloc_fill(). May be extract common
> > > code to separate function/s?
> > 
> > I see what you mean, but the algorithms are different. One tries to
> > obtain N beneficially ordered pages, while the other fills an array with
> > any set of pages regardless of order.
> > 
> > I'm hesitant to force the code into helpers or create a single unified
> > function with conditionals just to save 70 lines of code. In my opinion,
> > the abstraction is already at the right level.
> > 
> 
> Ok
> 
> > > 
> > > > +
> > > > /**
> > > >  * ttm_pool_prealloc_fini() - Release unconsumed preallocated pages
> > > >  * @pool: The pool the pages came from.
> > > > @@ -1111,9 +1293,13 @@ void ttm_pool_prealloc_fini(struct ttm_pool *pool, struct ttm_pool_prealloc *pp)
> > > > {
> > > > 	unsigned int i;
> > > >
> > > > -	for (i = pp->used; i < pp->count; ++i)
> > > > -		ttm_pool_free_page(pool, pp->caching, pp->order, pp->pages[i],
> > > > -				   false);
> > > > +	for (i = pp->used; i < pp->count; ++i) {
> > > > +		struct page *p = pp->pages[i];
> > > > +		unsigned int order = pp->full ?
> > > > +			ttm_pool_page_order_nodma(p) : pp->order;
> > > > +
> > > > +		ttm_pool_free_page(pool, pp->caching, order, p, false);
> > > > +	}
> > > > 	kvfree(pp->pages);
> > > > 	pp->pages = NULL;
> > > > 	pp->count = 0;
> > > > @@ -1251,9 +1437,10 @@ static int ttm_pool_iter_reuse_old(struct ttm_pool_alloc_iter *it)
> > > >
> > > > /*
> > > >  * Acquire a single page for the current order, leaving it in @it->p (NULL on
> > > > - * failure). Tries, in order: a beneficial-order page preallocated outside the
> > > > - * dma-resv lock (defrag), a same-order pool page, then a fresh system
> > > > - * allocation. Fault injection can force the beneficial-order paths to "fail".
> > > > + * failure). Tries, in order: a chunk from a full out-of-lock prealloc (populate
> > > > + * of the whole tt), a beneficial-order page preallocated outside the dma-resv
> > > > + * lock (defrag), a same-order pool page, then a fresh system allocation. Fault
> > > > + * injection can force the beneficial-order paths to "fail".
> > > >  */
> > > > static void ttm_pool_iter_acquire_page(struct ttm_pool_alloc_iter *it)
> > > > {
> > > > @@ -1262,6 +1449,39 @@ static void ttm_pool_iter_acquire_page(struct ttm_pool_alloc_iter *it)
> > > >
> > > > 	it->p = NULL;
> > > >
> > > > +	/*
> > > > +	 * Full prealloc: the entire backing was allocated (pool + system, at
> > > > +	 * mixed orders) outside the dma-resv lock. Install the next chunk as-is,
> > > > +	 * taking its order from the page. Falls through to in-line allocation
> > > > +	 * once the best-effort bag is drained.
> > > > +	 */
> > > > +	if (pp && pp->full && pp->used < pp->count) {
> > > > +		it->fail_beneficial = false;
> > > > +		it->p = pp->pages[pp->used++];
> > > > +		it->order = ttm_pool_page_order_nodma(it->p);
> > > > +		it->page_caching = it->tt->caching;
> > > 
> > > Same comment as in 23.
> > > We should ensure caching has not changed here after prefill
> > > (ie., pp->caching == it->tt->caching). Though it is not expected to change
> > > in gem_create_ioctl call (unlike defragmentation case of patch 23),
> > > probably it is still better to check to ensure TTM prealloc() and
> > > pool_alloc_page() interfaces work correctly together?
> > > 
> > 
> > We don't have formalized assert framework in TTM like we do in Xe but
> > perhaps we should - I'd like add one in a follow up as there as so many
> > undocumented invarients in TTM...
> > 
> > So...
> > 
> > /* TODO: formalize invarients in a common TTM assert framework */
> > WARN_ON(it->tt->caching != pp->pp->caching)?
> > 
> 
> In gem_create ioctl case (which is the case here), the tt->caching is not
> expected to change between prefill and allocation (whereas in defragmentation
> case of patch 23, it can). So, yes a WARN_ON should be good here.

The caching should never change, so will add a warn_on.

> But given it is ttm code, may be in both cases (gem_create ioctl and
> defragmentation), we should probably fall back to regular allocation
> and free the preallocated pages?
> 

For gem_create:

If the prealloc fails mid allocation (non-fatal), we consume the
prealloc and fall back to TTM alloc page flow - if the 2nd step falls
this is fatal -ENOMEM. Or at least this was my intent.

For defrag:

We just prune in whatever amount of pages available in the pre-alloc.

Matt

> Niranjana
> 
> > Matt
> > 
> > > > +
> > > > +		/*
> > > > +		 * The full prealloc tiles at whatever orders were available
> > > > +		 * without stalling in reclaim. A sub-beneficial chunk only
> > > > +		 * means a sub-optimal backing (defrag-worthy) when it sits in a
> > > > +		 * beneficial-order aligned region that fully fits in the tt -
> > > > +		 * that region could have been a beneficial-order page. A low
> > > > +		 * order in the unaligned trailing tail is expected and must not
> > > > +		 * flag the tt (mirrors ttm_pool_harvest_remaining()).
> > > > +		 */
> > > > +		if (it->beneficial_order && it->order < it->beneficial_order) {
> > > > +			pgoff_t bnr = 1UL << it->beneficial_order;
> > > > +			pgoff_t off = it->tt->num_pages -
> > > > +				      it->alloc->remaining_pages;
> > > > +
> > > > +			if (round_down(off, bnr) + bnr <= it->tt->num_pages)
> > > > +				it->tt->page_flags |=
> > > > +					TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED;
> > > > +		}
> > > > +		return;
> > > > +	}
> > > > +
> > > > 	/*
> > > > 	 * Fault injection: pretend allocation at (or above) the device's
> > > > 	 * beneficial order failed, forcing a sub-optimal backing. Exercises the
> > > > diff --git a/include/drm/ttm/ttm_bo.h b/include/drm/ttm/ttm_bo.h
> > > > index a80304f179ba..52ec7e5c0d2d 100644
> > > > --- a/include/drm/ttm/ttm_bo.h
> > > > +++ b/include/drm/ttm/ttm_bo.h
> > > > @@ -238,14 +238,17 @@ struct ttm_operation_ctx {
> > > > 	 */
> > > > 	s64 defrag_bytes_remaining;
> > > > 	/**
> > > > -	 * @prealloc: Pages preallocated outside the dma-resv lock for a defrag
> > > > -	 * move. The pool allocator consumes these instead of allocating fresh
> > > > -	 * beneficial-order pages under the lock, moving the (potentially
> > > > -	 * reclaim/compaction stalling) high-order allocations out of the
> > > > -	 * critical section. NULL means allocate in-line as usual. The pool
> > > > -	 * silently falls back to in-line allocation for any shortfall. The
> > > > -	 * allocator consumes it for beneficial-order chunks of any populate;
> > > > -	 * drivers only set it for a defrag move.
> > > > +	 * @prealloc: Pages preallocated outside the dma-resv lock. The pool
> > > > +	 * allocator consumes these instead of allocating under the lock, moving
> > > > +	 * the (potentially reclaim/compaction stalling) allocations out of the
> > > > +	 * critical section. NULL means allocate in-line as usual. Two flavours,
> > > > +	 * distinguished by ttm_pool_prealloc::full:
> > > > +	 *   - defrag bag (full=false): a bag of interchangeable beneficial-order
> > > > +	 *     chunks consumed only for beneficial-order chunks of a defrag move.
> > > > +	 *   - full tiling (full=true): the entire backing of the tt, at mixed
> > > > +	 *     orders, consumed for every chunk of an ordinary populate.
> > > > +	 * The allocator silently falls back to in-line allocation for any
> > > > +	 * shortfall.
> > > > 	 */
> > > > 	struct ttm_pool_prealloc *prealloc;
> > > > 	/**
> > > > diff --git a/include/drm/ttm/ttm_pool.h b/include/drm/ttm/ttm_pool.h
> > > > index 71670350eb15..777d5aa08f6a 100644
> > > > --- a/include/drm/ttm/ttm_pool.h
> > > > +++ b/include/drm/ttm/ttm_pool.h
> > > > @@ -83,18 +83,27 @@ void ttm_pool_free(struct ttm_pool *pool, struct ttm_tt *tt);
> > > >
> > > > /**
> > > >  * struct ttm_pool_prealloc - Pages preallocated outside the dma-resv lock
> > > > - * @pages: Array of @count beneficial-order pages (or fewer if a fill fell
> > > > - *         short); each entry is the head page of a 1 << @order chunk.
> > > > - * @order: Page order of every preallocated chunk.
> > > > + * @pages: Array of @count preallocated chunks; each entry is the head page of a
> > > > + *         chunk. In defrag mode every chunk is @order pages; in @full mode the
> > > > + *         chunks tile a whole tt at mixed orders and the per-chunk order is read
> > > > + *         back from the page itself.
> > > > + * @order: Page order of every preallocated chunk (defrag mode only; 0 in @full
> > > > + *         mode where each chunk carries its own order).
> > > >  * @caching: CPU caching applied to the pages, so leftovers can be restored
> > > >  *           to write-back before being freed.
> > > >  * @count: Number of valid entries in @pages.
> > > >  * @used: Number of entries already consumed by the pool allocator.
> > > > + * @full: When set the bag holds a full, mixed-order tiling of an entire tt
> > > > + *        (produced by ttm_pool_prealloc_fill_full()) rather than a bag of
> > > > + *        interchangeable beneficial-order defrag chunks. The pool allocator
> > > > + *        then drains the bag in order for every populate, taking each chunk's
> > > > + *        order from the page, and falls back to in-line allocation only for any
> > > > + *        shortfall.
> > > >  *
> > > >  * Defrag pages are interchangeable, so only a count of beneficial-order chunks
> > > > - * is needed. ttm_pool_prealloc_fill() populates this outside the lock and
> > > > - * __ttm_pool_alloc() drains it; any unused tail is released by
> > > > - * ttm_pool_prealloc_fini().
> > > > + * is needed. ttm_pool_prealloc_fill() / ttm_pool_prealloc_fill_full() populate
> > > > + * this outside the lock and __ttm_pool_alloc() drains it; any unused tail is
> > > > + * released by ttm_pool_prealloc_fini().
> > > >  */
> > > > struct ttm_pool_prealloc {
> > > > 	struct page **pages;
> > > > @@ -102,10 +111,16 @@ struct ttm_pool_prealloc {
> > > > 	enum ttm_caching caching;
> > > > 	unsigned int count;
> > > > 	unsigned int used;
> > > > +	bool full;
> > > > };
> > > >
> > > > int ttm_pool_prealloc_fill(struct ttm_pool *pool, enum ttm_caching tt_caching,
> > > > 			   struct ttm_pool_prealloc *pp, unsigned int count);
> > > > +int ttm_pool_prealloc_fill_full(struct ttm_pool *pool,
> > > > +				enum ttm_caching tt_caching,
> > > > +				struct ttm_pool_prealloc *pp,
> > > > +				unsigned int num_pages,
> > > > +				bool beneficial_reclaim_backoff);
> > > > void ttm_pool_prealloc_fini(struct ttm_pool *pool,
> > > > 			    struct ttm_pool_prealloc *pp);
> > > > unsigned int ttm_pool_prealloc_order(struct ttm_pool *pool);
> > > > --
> > > > 2.34.1
> > > >

  reply	other threads:[~2026-12-01 17:25 UTC|newest]

Thread overview: 130+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-11  2:55 [PATCH v3 00/33] drm/ttm, drm/xe: Minimize dma-resv hold times and defragment sub-optimally backed BOs Matthew Brost
2026-07-11  2:55 ` [PATCH v3 01/33] drm/ttm/pool: Allow backing off reclaim at the beneficial order Matthew Brost
2026-11-06  2:55   ` Niranjana Vishwanathapura
2026-11-19 18:47     ` Matthew Brost
2026-07-11  2:55 ` [PATCH v3 02/33] drm/ttm/pool: Add ttm_pool_page_order_nodma() helper Matthew Brost
2026-11-05 11:27   ` Matthew Auld
2026-11-06  2:30   ` Niranjana Vishwanathapura
2026-07-11  2:55 ` [PATCH v3 03/33] drm/ttm: Record sub-optimal page order allocations in ttm_tt Matthew Brost
2026-11-06  2:34   ` Niranjana Vishwanathapura
2026-11-06 20:06     ` Matthew Brost
2026-07-11  2:55 ` [PATCH v3 04/33] drm/ttm: Introduce ttm_pool_alloc_iter for __ttm_pool_alloc() Matthew Brost
2026-11-06  2:39   ` Niranjana Vishwanathapura
2026-11-19 19:14     ` Matthew Brost
2026-07-11  2:55 ` [PATCH v3 05/33] drm/ttm: Support defragmentation moves Matthew Brost
2026-11-06  2:51   ` Niranjana Vishwanathapura
2026-11-19 20:15     ` Matthew Brost
2026-11-21  6:30       ` Niranjana Vishwanathapura
2026-11-23 17:53         ` Matthew Brost
2026-12-01  3:42           ` Niranjana Vishwanathapura
2026-07-11  2:55 ` [PATCH v3 06/33] drm/ttm: Add fault injection for beneficial-order allocation failures Matthew Brost
2026-11-06  2:54   ` Niranjana Vishwanathapura
2026-11-19 20:49     ` Matthew Brost
2026-07-11  2:55 ` [PATCH v3 07/33] drm/ttm: Harvest beneficial-order pages on defragmentation moves Matthew Brost
2026-11-10  2:37   ` Niranjana Vishwanathapura
2026-11-19 21:39     ` Matthew Brost
2026-11-20 23:09       ` Niranjana Vishwanathapura
2026-11-23 18:08         ` Matthew Brost
2026-07-11  2:55 ` [PATCH v3 08/33] drm/ttm: Bound page (re)allocation per defragmentation move Matthew Brost
2026-11-10  2:44   ` Niranjana Vishwanathapura
2026-11-20  2:14     ` Matthew Brost
2026-11-20 20:37       ` Niranjana Vishwanathapura
2026-11-23 21:24         ` Matthew Brost
2026-07-11  2:55 ` [PATCH v3 09/33] drm/ttm: Preallocate beneficial-order defrag pages outside the lock Matthew Brost
2026-11-11  0:29   ` Niranjana Vishwanathapura
2026-11-23 21:36     ` Matthew Brost
2026-11-11  7:49   ` Niranjana Vishwanathapura
2026-11-20  2:29     ` Matthew Brost
2026-07-11  2:55 ` [PATCH v3 10/33] drm/ttm: Add full out-of-lock preallocation for ttm_pool_alloc() Matthew Brost
2026-11-11  7:31   ` Niranjana Vishwanathapura
2026-11-20  5:48     ` Matthew Brost
2026-11-21  5:03       ` Niranjana Vishwanathapura
2026-12-01 17:25         ` Matthew Brost [this message]
2026-07-11  2:56 ` [PATCH v3 15/33] drm/xe: Track BOs backed at a sub-optimal page order Matthew Brost
2026-11-07  4:49   ` Niranjana Vishwanathapura
2026-11-20  6:02     ` Matthew Brost
2026-07-11  2:56 ` [PATCH v3 16/33] drm/xe: Back off beneficial-order reclaim under defrag pressure Matthew Brost
2026-11-07  5:02   ` Niranjana Vishwanathapura
2026-11-20  6:08     ` Matthew Brost
2026-07-11  2:56 ` [PATCH v3 17/33] drm/xe: Add xe_migrate_copy_defrag() for on-GPU defrag copies Matthew Brost
2026-11-03 12:58   ` Matthew Auld
2026-11-03 20:08     ` Matthew Brost
2026-11-04 12:37       ` Matthew Auld
2026-11-20  6:11         ` Matthew Brost
2026-11-07  5:07   ` Niranjana Vishwanathapura
2026-12-01 18:04     ` Matthew Brost
2026-07-11  2:56 ` [PATCH v3 18/33] drm/xe: Handle defrag moves in xe_bo_move() Matthew Brost
2026-11-07  5:12   ` Niranjana Vishwanathapura
2026-11-24 15:37     ` Matthew Brost
2026-07-11  2:56 ` [PATCH v3 19/33] drm/xe: Skip self-copies for borrowed pages on defrag moves Matthew Brost
2026-11-10  4:25   ` Niranjana Vishwanathapura
2026-11-24 16:08     ` Matthew Brost
2026-11-24 16:21       ` Matthew Brost
2026-07-11  2:56 ` [PATCH v3 20/33] drm/xe: Add a page defragmentation worker Matthew Brost
2026-11-07  5:27   ` Niranjana Vishwanathapura
2026-11-24 18:54     ` Matthew Brost
2026-11-30 23:27       ` Niranjana Vishwanathapura
2026-12-01  0:18         ` Matthew Brost
2026-07-11  2:56 ` [PATCH v3 21/33] drm/xe: Add defrag GT stats Matthew Brost
2026-11-09  1:10   ` Niranjana Vishwanathapura
2026-11-24 20:13     ` Matthew Brost
2026-11-30 23:02       ` Niranjana Vishwanathapura
2026-11-30 23:04         ` Matthew Brost
2026-07-11  2:56 ` [PATCH v3 22/33] drm/xe: Add Kconfig.profile options for BO defrag configuration Matthew Brost
2026-11-09  1:31   ` Niranjana Vishwanathapura
2026-11-24 20:25     ` Matthew Brost
2026-11-30 22:49       ` Niranjana Vishwanathapura
2026-11-30 22:52         ` Matthew Brost
2026-07-11  2:56 ` [PATCH v3 23/33] drm/xe: Defrag using out-of-lock page preallocation Matthew Brost
2026-11-11  0:39   ` Niranjana Vishwanathapura
2026-11-24 20:34     ` Matthew Brost
2026-07-11  2:56 ` [PATCH v3 24/33] drm/xe: Add defrag profiling tracepoints Matthew Brost
2026-11-09  4:34   ` Niranjana Vishwanathapura
2026-11-24 20:42     ` Matthew Brost
2026-11-30 21:13       ` Niranjana Vishwanathapura
2026-12-01 18:53         ` Matthew Brost
2026-07-11  2:56 ` [PATCH v3 25/33] drm/xe: Preallocate system BO backing outside the dma-resv lock Matthew Brost
2026-11-11  7:36   ` Niranjana Vishwanathapura
2026-11-24 20:44     ` Matthew Brost
2026-07-11  2:56 ` [PATCH v3 26/33] drm/xe: Add tracepoint for xe_gem_create_ioctl Matthew Brost
2026-11-11  7:37   ` Niranjana Vishwanathapura
2026-11-24 20:45     ` Matthew Brost
2026-11-30 21:05       ` Niranjana Vishwanathapura
2026-07-11  2:56 ` [PATCH v3 27/33] drm/xe: Add IOVA-based xe_res_cursor variant Matthew Brost
2026-11-04 12:23   ` Matthew Auld
2026-11-13  6:14   ` Niranjana Vishwanathapura
2026-12-01 19:29     ` Matthew Brost
2026-07-11  2:56 ` [PATCH v3 28/33] drm/xe: Use IOVA-based DMA mapping for eligible tt BOs Matthew Brost
2026-11-03 19:00   ` Matthew Auld
2026-11-03 20:21     ` Matthew Brost
2026-11-04 11:39       ` Matthew Auld
2026-11-05  3:04         ` Matthew Brost
2026-11-13  6:28   ` Niranjana Vishwanathapura
2026-11-13 20:09     ` Matthew Brost
2026-11-16  4:10       ` Niranjana Vishwanathapura
2026-07-11  2:56 ` [PATCH v3 29/33] drm/xe: Add per-device dependency scheduler for IOVA defrag finalize Matthew Brost
2026-11-14  1:47   ` Niranjana Vishwanathapura
2026-11-24 20:57     ` Matthew Brost
2026-11-30 19:15       ` Niranjana Vishwanathapura
2026-12-01 22:05         ` Matthew Brost
2026-07-11  2:56 ` [PATCH v3 30/33] drm/xe: Add packed copy-step IOVA mapping for defrag Matthew Brost
2026-11-14  1:52   ` Niranjana Vishwanathapura
2026-11-24 21:00     ` Matthew Brost
2026-11-30 19:57       ` Niranjana Vishwanathapura
2026-11-30 20:07         ` Matthew Brost
2026-07-11  2:56 ` [PATCH v3 31/33] drm/xe: Blit src-natural to dst-packed for defrag-IOVA copies Matthew Brost
2026-11-14  1:57   ` Niranjana Vishwanathapura
2026-11-24 21:18     ` Matthew Brost
2026-11-16  0:41   ` Niranjana Vishwanathapura
2026-11-24 21:12     ` Matthew Brost
2026-11-30 20:31       ` Niranjana Vishwanathapura
2026-07-11  2:56 ` [PATCH v3 32/33] drm/xe: Finalize defrag-IOVA moves with post-copy job Matthew Brost
2026-11-14  2:02   ` Niranjana Vishwanathapura
2026-11-24 21:08     ` Matthew Brost
2026-11-30 20:51       ` Niranjana Vishwanathapura
2026-07-11  2:56 ` [PATCH v3 33/33] drm/amdgpu: Preallocate system BO pages outside the reservation lock Matthew Brost
2026-07-11 10:46   ` Christian König
2026-07-13 20:24     ` Matthew Brost
2026-07-14  9:17       ` Christian König
2026-07-14 15:15         ` Matthew Brost
2026-11-16  1:01 ` [PATCH v3 00/33] drm/ttm, drm/xe: Minimize dma-resv hold times and defragment sub-optimally backed BOs Niranjana Vishwanathapura

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=aw8DFH4lHGTAHz4x@gsse-cloud1.jf.intel.com \
    --to=matthew.brost@intel.com \
    --cc=airlied@gmail.com \
    --cc=carlos.santa@intel.com \
    --cc=christian.koenig@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=matthew.auld@intel.com \
    --cc=mripard@kernel.org \
    --cc=niranjana.vishwanathapura@intel.com \
    --cc=ray.huang@amd.com \
    --cc=ryanneph@google.com \
    --cc=simona@ffwll.ch \
    --cc=thomas.hellstrom@linux.intel.com \
    --cc=tzimmermann@suse.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox