From: Niranjana Vishwanathapura <niranjana.vishwanathapura@intel.com>
To: Matthew Brost <matthew.brost@intel.com>
Cc: intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
"Carlos Santa" <carlos.santa@intel.com>,
"Ryan Neph" <ryanneph@google.com>,
"Matthew Auld" <matthew.auld@intel.com>,
"Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
"Natalie Vock" <nat@pixelcluster.dev>,
"Arun Pravin" <arunpravin.paneerselvam@amd.com>
Subject: Re: [PATCH v5 35/36] drm/xe: Add bo_defrag debugfs entry
Date: Thu, 3 Dec 2026 09:35:23 -0800 [thread overview]
Message-ID: <axGoW6ICfUy0Ga9e@nvishwa1-desk> (raw)
In-Reply-To: <20261202233323.3743190-36-matthew.brost@intel.com>
On Wed, Dec 02, 2026 at 03:33:22PM -0800, Matthew Brost wrote:
>Add a bo_defrag debugfs file to inspect the state of the BO
>defragmentation worker. It reports whether defrag is supported, the
>beneficial page order, the per-run size limit, the current (possibly
>backed-off) worker interval along with its default and maximum, whether
>the worker is pending (and when it will next run), running or idle, and
>the number of BOs on the defrag list.
>
>Each BO on the defrag list is then printed with its size, the number of
>bytes still backed below the beneficial order (the bytes a defrag move
>would reallocate) and whether it still needs defrag, followed by totals.
>
>A reference to each listed BO is taken under the defrag list lock and
>the BO is then locked to sample its backing, as the tt can be torn down
>while the BO is still on the list. The per-BO output is therefore a
>best-effort snapshot.
>
>Cc: Carlos Santa <carlos.santa@intel.com>
>Cc: Ryan Neph <ryanneph@google.com>
>Cc: Matthew Auld <matthew.auld@intel.com>
>Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
>Cc: Natalie Vock <nat@pixelcluster.dev>
>Cc: Arun Pravin <arunpravin.paneerselvam@amd.com>
>Signed-off-by: Matthew Brost <matthew.brost@intel.com>
>---
> drivers/gpu/drm/xe/xe_bo.c | 97 +++++++++++++++++++++++++++++++++
> drivers/gpu/drm/xe/xe_bo.h | 1 +
> drivers/gpu/drm/xe/xe_debugfs.c | 9 +++
> 3 files changed, 107 insertions(+)
>
>diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
>index 65ab974c56ac..85552da80bf5 100644
>--- a/drivers/gpu/drm/xe/xe_bo.c
>+++ b/drivers/gpu/drm/xe/xe_bo.c
>@@ -2476,6 +2476,103 @@ static void xe_bo_defrag_update(struct xe_bo *bo)
> xe_bo_defrag_remove(bo);
> }
>
>+/**
>+ * xe_bo_defrag_print() - Print the BO defragmentation state
>+ * @xe: xe device instance
>+ * @p: The drm_printer to print to
>+ *
>+ * Print the defrag worker configuration and state, followed by each BO on the
>+ * defrag list with its size and the bytes still backed below the beneficial
>+ * order (i.e. the bytes a defrag move would reallocate). A reference to each
>+ * listed BO is taken under the list lock and the BO is then locked to sample
>+ * its backing, so the per-BO output is a best-effort snapshot.
>+ *
>+ * Return: 0 on success, negative error code on failure.
>+ */
>+int xe_bo_defrag_print(struct xe_device *xe, struct drm_printer *p)
>+{
>+ struct delayed_work *dwork = &xe->mem.defrag.worker;
>+ u64 total_size = 0, total_subopt = 0;
>+ unsigned int count = 0, nr = 0, i;
>+ unsigned int interval_ms;
>+ struct xe_bo **bos, *bo;
>+ int err = 0;
>+
>+ drm_printf(p, "supported: %s\n",
>+ str_yes_no(xe_bo_defrag_supported(xe)));
>+ if (!xe_bo_defrag_supported(xe))
>+ return 0;
>+
>+ scoped_guard(spinlock, &xe->mem.defrag.lock) {
>+ interval_ms = xe->mem.defrag.interval_ms;
>+ list_for_each_entry(bo, &xe->mem.defrag.list, defrag_link)
>+ count++;
>+ }
>+
>+ drm_printf(p, "beneficial_order: %u\n",
>+ ttm_pool_prealloc_order(&xe->ttm.pool));
>+ drm_printf(p, "size_limit: %llu\n", (u64)XE_BO_DEFRAG_SIZE_LIMIT);
>+ drm_printf(p, "interval_ms: %u (default %u, max %u)\n", interval_ms,
>+ XE_BO_DEFRAG_INTERVAL_MS, XE_BO_DEFRAG_INTERVAL_MAX_MS);
>+ if (delayed_work_pending(dwork)) {
>+ long delay = (long)(READ_ONCE(dwork->timer.expires) - jiffies);
>+
>+ drm_printf(p, "worker: pending, next run in %u ms\n",
>+ jiffies_to_msecs(max(delay, 0L)));
>+ } else {
>+ drm_printf(p, "worker: %s\n",
>+ work_busy(&dwork->work) ? "running" : "idle");
>+ }
>+ drm_printf(p, "list_count: %u\n", count);
>+ if (!count)
>+ return 0;
>+
>+ bos = kvmalloc_array(count, sizeof(*bos), GFP_KERNEL);
>+ if (!bos)
>+ return -ENOMEM;
>+
>+ /* The list may have changed while unlocked; snapshot at most @count. */
>+ scoped_guard(spinlock, &xe->mem.defrag.lock) {
>+ list_for_each_entry(bo, &xe->mem.defrag.list, defrag_link) {
>+ if (nr == count)
>+ break;
>+ bos[nr] = xe_bo_get_unless_zero(bo);
>+ if (bos[nr])
>+ nr++;
>+ }
>+ }
>+
>+ for (i = 0; i < nr; i++) {
>+ u64 size, subopt = 0;
>+ bool needs;
>+
>+ bo = bos[i];
>+ if (!err)
>+ err = xe_bo_lock(bo, true);
>+ if (!err) {
>+ size = xe_bo_size(bo);
>+ if (bo->ttm.ttm)
>+ subopt = (u64)ttm_tt_suboptimal_pages(bo->ttm.ttm) <<
>+ PAGE_SHIFT;
>+ needs = xe_bo_needs_defrag(bo);
>+ xe_bo_unlock(bo);
>+
>+ drm_printf(p, " bo[%u] %p: size=%llu suboptimal=%llu needs_defrag=%s\n",
>+ i, bo, size, subopt, str_yes_no(needs));
>+ total_size += size;
>+ total_subopt += subopt;
>+ }
>+ xe_bo_put(bo);
>+ }
>+ kvfree(bos);
>+
>+ if (!err)
>+ drm_printf(p, "total: bos=%u size=%llu suboptimal=%llu\n",
>+ nr, total_size, total_subopt);
>+
NIT...so, in case of a BO locking error in the middle of the above loop,
we will endup with prining BO info of some BOs (before the error) and will
not print the totals, which is also not clean. May be we should just skip
the BO that ran into error and continue printing the rest and the totals?
As any difference between 'count' printed above and 'bos' printed here will
tell it is best-effort snapshot?
>+ return err;
>+}
NIT...Also, the patch 36 updates some fields of this function. May be it
is cleaner to swap the order of patches to minimize such changes.
In anycase,
Reviewed-by: Niranjana Vishwanathapura <niranjana.vishwanathapura@intel.com>
>+
> /*
> * Attempt to defragment a single BO by forcing a move that reallocates its
> * backing at the device's beneficial order. @budget bounds how many bytes of
>diff --git a/drivers/gpu/drm/xe/xe_bo.h b/drivers/gpu/drm/xe/xe_bo.h
>index 871d1aa1425c..28325341b4d1 100644
>--- a/drivers/gpu/drm/xe/xe_bo.h
>+++ b/drivers/gpu/drm/xe/xe_bo.h
>@@ -241,6 +241,7 @@ int xe_bo_defrag_init(struct xe_device *xe);
> void xe_bo_defrag_suspend(struct xe_device *xe);
> void xe_bo_defrag_resume(struct xe_device *xe);
> void xe_bo_defrag_kick(struct xe_device *xe);
>+int xe_bo_defrag_print(struct xe_device *xe, struct drm_printer *p);
> int xe_bo_validate(struct xe_bo *bo, struct xe_vm *vm, bool allow_res_evict,
> struct drm_exec *exec);
>
>diff --git a/drivers/gpu/drm/xe/xe_debugfs.c b/drivers/gpu/drm/xe/xe_debugfs.c
>index be533435097f..b070835b8d24 100644
>--- a/drivers/gpu/drm/xe/xe_debugfs.c
>+++ b/drivers/gpu/drm/xe/xe_debugfs.c
>@@ -372,11 +372,20 @@ static int dma_mapped_pages_show(struct seq_file *m, void *data)
> }
> DEFINE_SHOW_ATTRIBUTE(dma_mapped_pages);
>
>+static int bo_defrag(struct seq_file *m, void *data)
>+{
>+ struct xe_device *xe = node_to_xe(m->private);
>+ struct drm_printer p = drm_seq_file_printer(m);
>+
>+ return xe_bo_defrag_print(xe, &p);
>+}
>+
> static const struct drm_info_list debugfs_list[] = {
> {"info", info, 0},
> { .name = "sriov_info", .show = sriov_info, },
> { .name = "workarounds", .show = workaround_info, },
> { .name = "pagefault_info", .show = pagefault_info, },
>+ { .name = "bo_defrag", .show = bo_defrag, },
> };
>
> static const struct drm_info_list pcode_info_debugfs[] = {
>--
>2.34.1
>
next prev parent reply other threads:[~2026-12-03 17:35 UTC|newest]
Thread overview: 77+ 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-03 0:29 ` 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-03 0:34 ` Matthew Brost
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-03 0:45 ` Matthew Brost
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-03 0:52 ` Matthew Brost
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-03 1:00 ` Matthew Brost
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-03 3:35 ` Niranjana Vishwanathapura
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-03 18:46 ` Matthew Brost
2026-12-02 23:33 ` [PATCH v5 22/36] drm/xe: Add defrag profiling tracepoints Matthew Brost
2026-12-03 4:03 ` Niranjana Vishwanathapura
2026-12-02 23:33 ` [PATCH v5 23/36] drm/xe: Preallocate system BO backing outside the dma-resv lock Matthew Brost
2026-12-03 4:38 ` Niranjana Vishwanathapura
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-03 1:12 ` Matthew Brost
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-03 1:13 ` Matthew Brost
2026-12-02 23:33 ` [PATCH v5 28/36] drm/xe: Lock the bo in xe_bo_dma_unmap_pinned() Matthew Brost
2026-12-03 16:18 ` Matthew Auld
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-03 1:20 ` Matthew Brost
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-03 1:15 ` Matthew Brost
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-03 9:17 ` Matthew Auld
2026-12-03 19:23 ` Niranjana Vishwanathapura
2026-12-02 23:33 ` [PATCH v5 35/36] drm/xe: Add bo_defrag debugfs entry Matthew Brost
2026-12-03 10:31 ` Matthew Auld
2026-12-03 17:35 ` Niranjana Vishwanathapura [this message]
2026-12-03 18:26 ` 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 16:10 ` Matthew Auld
2026-12-03 17:12 ` Niranjana Vishwanathapura
2026-12-03 18:27 ` 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
2026-12-03 0:56 ` ✓ Xe.CI.BAT: " Patchwork
2026-12-03 22:44 ` ✓ 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=axGoW6ICfUy0Ga9e@nvishwa1-desk \
--to=niranjana.vishwanathapura@intel.com \
--cc=arunpravin.paneerselvam@amd.com \
--cc=carlos.santa@intel.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=matthew.auld@intel.com \
--cc=matthew.brost@intel.com \
--cc=nat@pixelcluster.dev \
--cc=ryanneph@google.com \
--cc=thomas.hellstrom@linux.intel.com \
/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.