All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Matthew Brost" <matthew.brost@intel.com>,
	intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v5 21/36] drm/xe: Defrag using out-of-lock page preallocation
Date: Wed, 02 Dec 2026 23:56:10 +0000	[thread overview]
Message-ID: <sashiko-outbox-246786@kernel.org> (raw)
In-Reply-To: <20261202233323.3743190-22-matthew.brost@intel.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] drm/xe: FlatCCS extra_pages size mismatch in
  xe_bo_defrag_one()
- [Medium] drm/xe: TTM WC/UC page pool bypass in xe_bo_defrag_one()
  preallocation
--

commit 27539e0916948f7e33871d52a57501de9005f821
Author: Matthew Brost <matthew.brost@intel.com>

drm/xe: Defrag using out-of-lock page preallocation

This commit converts xe_bo_defrag_one() to preallocate beneficial-order
pages via ttm_pool_prealloc_fill() outside the BO dma-resv lock before
validating the BO with the preallocated page bag.

> diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
> index af9bdb7f05ef4..f3ce4e7ed98d1 100644
> --- a/drivers/gpu/drm/xe/xe_bo.c
> +++ b/drivers/gpu/drm/xe/xe_bo.c
> @@ -1510,16 +1510,65 @@ static int xe_bo_defrag_one(struct xe_device *xe, struct xe_bo *bo,
>  		.defrag_bytes_remaining = budget,
>  	};
>  	struct ttm_buffer_object *ttm_bo = &bo->ttm;
> +	struct ttm_pool *pool = &ttm_bo->bdev->pool;
> +	struct ttm_pool_prealloc pp = {};
>  	struct ttm_placement placement;
>  	struct ttm_place place;
> +	enum ttm_caching tt_caching;
> +	unsigned int order, want = 0;
>  	int ret = 0;
>  
>  	*consumed = 0;
>  	*needs_more = false;
>  
> +	/*
> +	 * Phase 1: under the BO lock, re-check eligibility and estimate how
> +	 * many beneficial-order chunks the move will (re)allocate, bounded by
> +	 * the run's byte budget. Then drop the lock so the high-order, possibly
> +	 * reclaim/compaction stalling allocations happen unlocked.
> +	 */
> +	xe_bo_lock(bo, false);
> +	if (!xe_bo_needs_defrag(bo)) {
> +		xe_bo_defrag_remove(bo);
> +		xe_bo_unlock(bo);
> +		goto out;
> +	}
> +	tt_caching = bo->ttm.ttm->caching;
> +	order = ttm_pool_prealloc_order(pool);
> +	if (order && ttm_bo->ttm) {
> +		u32 suboptimal = ttm_tt_suboptimal_pages(ttm_bo->ttm);
> +		u64 cap = min_t(u64, budget, xe_bo_size(bo)) >> PAGE_SHIFT;
> +
> +		/* Prealloc only the beneficial-order chunks the move replaces. */
> +		want = DIV_ROUND_UP_ULL(min_t(u64, suboptimal, cap), 1UL << order);
> +	}

[Severity: Medium]
Can capping want by xe_bo_size(bo) while reading suboptimal from
ttm_tt_suboptimal_pages() trigger XE_WARN_ON(!fence) in
__xe_migrate_copy() on integrated GPUs with FlatCCS?

For compressible system-memory BOs, xe_ttm_tt_create() appends FlatCCS
extra_pages beyond xe_bo_size(bo), and ttm_pool accounts sub-optimal
chunks across the full tt->num_pages range.  On a 1 GiB compressible BO
(512 order-9 data chunks plus one order-9 extra_pages chunk), cap limits
want to 512 even with a 1 GiB budget, so the first pass upgrades the 512
data chunks and harvests the extra_pages chunk as sub-optimal.

On the next pass (or whenever all data chunks are already at order 9 and
only the trailing extra_pages chunk is sub-optimal), want is 1.
ttm_bo_validate() borrows all data pages and reallocates only the
extra_pages chunk, but __xe_migrate_copy() only iterates over
xe_bo_size(src_bo), finds no non-borrowed pages to copy, hits
XE_WARN_ON(!fence), and fails with -EINVAL while leaving the BO on the
defrag list to repeat on later runs.

> +
> +	/*
> +	 * Nothing the move could upgrade: TTM would fail a defrag move that
> +	 * allocates no chunk, so drop the BO rather than retry it forever. It
> +	 * is re-added if a later populate backs it sub-optimally again.
> +	 */
> +	if (!want) {
> +		xe_bo_defrag_remove(bo);
> +		xe_bo_unlock(bo);
> +		goto out;
> +	}
> +	xe_bo_unlock(bo);
> +
> +	/* Phase 2: preallocate outside the lock; */
> +	ret = ttm_pool_prealloc_fill(pool, tt_caching, &pp, want);
> +	if (ret || !pp.count) {
> +		ret = ret ?: -ENOMEM;
> +		xe_gt_stats_incr(xe_root_mmio_gt(xe),
> +				 XE_GT_STATS_ID_DEFRAG_FAILED_COUNT, 1);
> +		goto out_err;
> +	}

[Severity: Medium]
Does switching to ttm_pool_prealloc_fill() and ttm_pool_prealloc_fini()
bypass the TTM WC/UC page pools during defragmentation?

Before this change, in-line allocation via ttm_pool_iter_acquire_page()
checked ttm_pool_select_type() and ttm_pool_type_take() first to reuse
already cache-converted order-9 pages from the TTM pool.  Unlike
ttm_pool_prealloc_fill_full(), ttm_pool_prealloc_fill() never consults
the TTM pool: it unconditionally calls ttm_pool_alloc_page() for fresh
write-back pages from the buddy allocator and converts their PAT caching
via ttm_pool_prealloc_apply_caching().  Similarly,
ttm_pool_prealloc_fini() frees unconsumed chunks via
ttm_pool_free_page() (converting each chunk back to write-back) instead
of returning WC/UC chunks to the TTM pool.

For WC and UC system-memory BOs on x86, this forces order-9 buddy
allocations, direct reclaim/compaction, and cross-CPU PAT/TLB shootdown
IPIs (or -ENOMEM defrag failures) even when pre-converted order-9 pages
are sitting idle in the TTM pool.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261202233323.3743190-1-matthew.brost@intel.com?part=21

  reply	other threads:[~2026-12-02 23:56 UTC|newest]

Thread overview: 53+ 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
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-03  0:25   ` Niranjana Vishwanathapura
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 [this message]
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
2026-12-03  0:21 ` ✗ CI.checkpatch: warning for drm/ttm, drm/xe: Avoid foreground high-order reclaim and defragment sub-optimally backed BOs (rev2) Patchwork
2026-12-03  0:23 ` ✓ CI.KUnit: success " 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=sashiko-outbox-246786@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=matthew.brost@intel.com \
    --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 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.