Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Brost <matthew.brost@intel.com>
To: <sashiko-reviews@lists.linux.dev>
Cc: <intel-xe@lists.freedesktop.org>, <dri-devel@lists.freedesktop.org>
Subject: Re: [PATCH v5 11/36] drm/ttm: Add full out-of-lock preallocation for ttm_pool_alloc()
Date: Wed, 2 Dec 2026 16:16:44 -0800	[thread overview]
Message-ID: <axC07EXXPOS7qlb8@gsse-cloud1.jf.intel.com> (raw)
In-Reply-To: <sashiko-outbox-246793@kernel.org>

On Wed, Dec 02, 2026 at 11:59:42PM +0000, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue to consider:
> - [Medium] drm/ttm: repeated empty-pool list_lru locking in
>   ttm_pool_prealloc_fill_full()

IMO micro-optimization but it exists in the main alloc path so might as
well add it here as it simple enough to code up.

Matt 

> --
> 
> commit a9c3c46ffa013c41ec426391623e966b58881b75
> Author: Matthew Brost <matthew.brost@intel.com>
> 
> drm/ttm: Add full out-of-lock preallocation for ttm_pool_alloc()
> 
> This commit adds ttm_pool_prealloc_fill_full() to preallocate the entire
> backing of a system-memory ttm_tt at mixed orders outside the dma-resv
> lock.
> 
> > diff --git a/drivers/gpu/drm/ttm/ttm_pool.c b/drivers/gpu/drm/ttm/ttm_pool.c
> > index fa76f880d5632..7b1736324f7e5 100644
> > --- a/drivers/gpu/drm/ttm/ttm_pool.c
> > +++ b/drivers/gpu/drm/ttm/ttm_pool.c
> 
> [ ... ]
> 
> > +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;
> > +}
> 
> [ ... ]
> 
> > +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)
> > +{
> 
> [ ... ]
> 
> > +	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--;
> > +		}
> 
> [Severity: Medium]
> Should ttm_pool_prealloc_fill_full() stop probing the pool at the current
> order once ttm_pool_type_take() returns NULL, the way
> ttm_pool_iter_acquire_page() does with it->allow_pools?
> 
> In the in-line allocator, once ttm_pool_type_take() misses at a given
> order, it->allow_pools is cleared until the allocator drops to a lower
> order.  Here, ttm_pool_take_page() calls ttm_pool_type_take() on every
> iteration of the while (remaining) loop.
> 
> On x86, ttm_write_combined and ttm_uncached use the global pool types, and
> ttm_pool_type_take() -> list_lru_walk_node() unconditionally acquires and
> releases the list_lru spinlock even when the list is empty.  When the
> global WC or UC pool is empty and allocation falls back to order 0 (for
> instance when beneficial_reclaim_backoff skips reclaim at higher orders),
> preallocating a buffer object acquires and releases the global order-0
> list_lru spinlock once per 4K page instead of once per order, contending
> across concurrent unlocked preallocations.
> 
> -- 
> Sashiko AI review · https://sashiko.dev/#/patchset/20261202233323.3743190-1-matthew.brost@intel.com?part=11

  reply	other threads:[~2026-12-03  0:17 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 23:32 [PATCH v5 00/36] drm/ttm, drm/xe: Avoid foreground high-order reclaim and defragment sub-optimally backed BOs Matthew Brost
2026-12-02 23:32 ` [PATCH v5 01/36] drm/ttm/pool: Allow backing off reclaim at the beneficial order Matthew Brost
2026-12-02 23:32 ` [PATCH v5 02/36] drm/ttm/pool: Add ttm_pool_page_order_nodma() helper Matthew Brost
2026-12-02 23:32 ` [PATCH v5 03/36] drm/ttm: Record sub-optimal page order allocations in ttm_tt Matthew Brost
2026-12-02 23:32 ` [PATCH v5 04/36] drm/ttm: Introduce ttm_pool_alloc_iter for __ttm_pool_alloc() Matthew Brost
2026-12-02 23:32 ` [PATCH v5 05/36] drm/ttm: Support defragmentation moves Matthew Brost
2026-12-02 23:32 ` [PATCH v5 06/36] drm/ttm: Add fault injection for beneficial-order allocation failures Matthew Brost
2026-12-02 23:32 ` [PATCH v5 07/36] drm/ttm/pool: Keep chunks self-aligned when resuming an interrupted restore Matthew Brost
2026-12-02 23:32 ` [PATCH v5 08/36] drm/ttm: Harvest beneficial-order pages on defragmentation moves Matthew Brost
2026-12-02 23:32 ` [PATCH v5 09/36] drm/ttm: Bound page (re)allocation per defragmentation move Matthew Brost
2026-12-02 23:32 ` [PATCH v5 10/36] drm/ttm: Preallocate beneficial-order defrag pages outside the lock Matthew Brost
2026-12-02 23:57   ` sashiko-bot
2026-12-03  0:08     ` Matthew Brost
2026-12-02 23:32 ` [PATCH v5 11/36] drm/ttm: Add full out-of-lock preallocation for ttm_pool_alloc() Matthew Brost
2026-12-02 23:59   ` sashiko-bot
2026-12-03  0:16     ` Matthew Brost [this message]
2026-12-02 23:32 ` [PATCH v5 12/36] drm/gpusvm: Add a DMA-mapping accounting callback Matthew Brost
2026-12-02 23:33 ` [PATCH v5 13/36] drm/xe: Add debugfs stats for DMA-mapped pages per order Matthew Brost
2026-12-02 23:33 ` [PATCH v5 14/36] drm/xe: Track BOs backed at a sub-optimal page order Matthew Brost
2026-12-02 23:53   ` sashiko-bot
2026-12-02 23:33 ` [PATCH v5 15/36] drm/xe: Add xe_migrate_copy_defrag() for on-GPU defrag copies Matthew Brost
2026-12-02 23:33 ` [PATCH v5 16/36] drm/xe: Handle defrag moves in xe_bo_move() Matthew Brost
2026-12-02 23:55   ` sashiko-bot
2026-12-02 23:33 ` [PATCH v5 17/36] drm/xe: Skip self-copies for borrowed pages on defrag moves Matthew Brost
2026-12-02 23:52   ` sashiko-bot
2026-12-02 23:33 ` [PATCH v5 18/36] drm/xe: Add a page defragmentation worker Matthew Brost
2026-12-03  0:12   ` sashiko-bot
2026-12-02 23:33 ` [PATCH v5 19/36] drm/xe: Add defrag GT stats Matthew Brost
2026-12-02 23:33 ` [PATCH v5 20/36] drm/xe: Add Kconfig.profile options for BO defrag configuration Matthew Brost
2026-12-02 23:33 ` [PATCH v5 21/36] drm/xe: Defrag using out-of-lock page preallocation Matthew Brost
2026-12-02 23:56   ` sashiko-bot
2026-12-02 23:33 ` [PATCH v5 22/36] drm/xe: Add defrag profiling tracepoints Matthew Brost
2026-12-02 23:33 ` [PATCH v5 23/36] drm/xe: Preallocate system BO backing outside the dma-resv lock Matthew Brost
2026-12-02 23:33 ` [PATCH v5 24/36] drm/xe: Add tracepoint for xe_gem_create_ioctl Matthew Brost
2026-12-02 23:33 ` [PATCH v5 25/36] drm/xe: Add IOVA-based xe_res_cursor variant Matthew Brost
2026-12-02 23:33 ` [PATCH v5 26/36] drm/xe: Don't DMA map tt pages after device unplug Matthew Brost
2026-12-02 23:52   ` sashiko-bot
2026-12-02 23:33 ` [PATCH v5 27/36] drm/xe/display: Flush cleanup work on unregister Matthew Brost
2026-12-02 23:58   ` sashiko-bot
2026-12-02 23:33 ` [PATCH v5 28/36] drm/xe: Lock the bo in xe_bo_dma_unmap_pinned() Matthew Brost
2026-12-02 23:33 ` [PATCH v5 29/36] drm/xe: Use IOVA-based DMA mapping for eligible tt BOs Matthew Brost
2026-12-03  0:06   ` sashiko-bot
2026-12-02 23:33 ` [PATCH v5 30/36] drm/xe: Add per-device dependency scheduler for IOVA defrag finalize Matthew Brost
2026-12-02 23:33 ` [PATCH v5 31/36] drm/xe: Add packed copy-step IOVA mapping for defrag Matthew Brost
2026-12-02 23:33 ` [PATCH v5 32/36] drm/xe: Blit src-natural to dst-packed for defrag-IOVA copies Matthew Brost
2026-12-02 23:33 ` [PATCH v5 33/36] drm/xe: Finalize defrag-IOVA moves with post-copy job Matthew Brost
2026-12-03  0:18   ` sashiko-bot
2026-12-02 23:33 ` [PATCH v5 34/36] drm/xe: Grow the USM batch pool to 2M and map it via a single PDE Matthew Brost
2026-12-02 23:33 ` [PATCH v5 35/36] drm/xe: Add bo_defrag debugfs entry Matthew Brost
2026-12-02 23:33 ` [PATCH v5 36/36] drm/xe: Make BO defrag tunables configurable via sysfs Matthew Brost

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=axC07EXXPOS7qlb8@gsse-cloud1.jf.intel.com \
    --to=matthew.brost@intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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