On Wed, Dec 02, 2026 at 03:33:21PM -0800, Matthew Brost wrote:
The defrag copy path submits its migration batches from the USM batch
pool. When the pool is small, xe_bb_new() backs up in the suballocator
waiting for prior migrate batches to retire, and that stall happens while
the BO reservation lock is held during the move. Traces of a 32MB defrag
move showed the entire ~37ms lock hold sitting inside xe_migrate_copy_*()
at xe_bb_new(), i.e. pool backpressure rather than actual copy time.

Grow the USM batch pool from 512K (integrated) / 1M (DGFX) to a uniform
2M to give the migrate engine enough in-flight batch space to avoid this
backpressure.

On integrated (non-DGFX) the pool is mapped into the migrate VM through
the shared level-0 pagetable alongside the 1M kernel batch pool. A full
2M needs 512 PTEs and no longer fits in that shared table's 2M window.
Instead, map the USM pool through a dedicated level-0 pagetable (reusing
an otherwise unused pt_bo page, as the vram identity map pages are only
consumed on DGFX) and point a single reserved 2M PDE at it, mirroring the
large_page_copy reservation. DGFX is unaffected as it reaches the pool
through the vram identity map.

Cc: Natalie Vock <[email protected]>
Cc: Arun Pravin <[email protected]>
Signed-off-by: Matthew Brost <[email protected]>

LGTM.
Reviewed-by: Niranjana Vishwanathapura <[email protected]>

---
drivers/gpu/drm/xe/xe_gt.c      |  4 +---
drivers/gpu/drm/xe/xe_migrate.c | 34 ++++++++++++++++++++++++++-------
2 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_gt.c b/drivers/gpu/drm/xe/xe_gt.c
index 7eacbe950ccd..7fb89bb5df75 100644
--- a/drivers/gpu/drm/xe/xe_gt.c
+++ b/drivers/gpu/drm/xe/xe_gt.c
@@ -660,10 +660,8 @@ static int gt_init_with_all_forcewake(struct xe_gt *gt)
                 * USM has its only SA pool to non-block behind user operations
                 */
                if (gt_to_xe(gt)->info.has_usm) {
-                       struct xe_device *xe = gt_to_xe(gt);
-
                        gt->usm.bb_pool = xe_sa_bo_manager_init(gt_to_tile(gt),
-                                                               IS_DGFX(xe) ? 
SZ_1M : SZ_512K, 16);
+                                                               SZ_2M, 16);
                        if (IS_ERR(gt->usm.bb_pool))
                                return PTR_ERR(gt->usm.bb_pool);
                }
diff --git a/drivers/gpu/drm/xe/xe_migrate.c b/drivers/gpu/drm/xe/xe_migrate.c
index c894cd1f1305..5844d085d418 100644
--- a/drivers/gpu/drm/xe/xe_migrate.c
+++ b/drivers/gpu/drm/xe/xe_migrate.c
@@ -505,22 +505,42 @@ static void xe_migrate_prepare_vm(struct xe_tile *tile, 
struct xe_migrate *m,
                        level++;
                }
                if (xe->info.has_usm) {
+                       u64 usm_pt_ofs;
+                       u32 usm_pde_slot, usm_pte;
+
                        xe_tile_assert(tile, xe_bo_size(batch) == SZ_1M);

                        batch = tile->primary_gt->usm.bb_pool->bo;
-                       m->usm_batch_base_ofs = m->batch_base_ofs + SZ_1M;
-                       xe_tile_assert(tile, xe_bo_size(batch) == SZ_512K);
+                       xe_tile_assert(tile, xe_bo_size(batch) == SZ_2M);

-                       for (i = 0; i < xe_bo_size(batch);
+                       /*
+                        * The usm batch pool is a full 2M and no longer fits in
+                        * the shared level-0 pagetable alongside the kernel
+                        * batch pool. Map it through a dedicated level-0
+                        * pagetable (reusing an otherwise unused pt_bo page, as
+                        * the vram identity map pages are only consumed on
+                        * DGFX) and point a single reserved 2M PDE at it,
+                        * mirroring the large_page_copy reservation below.
+                        */
+                       usm_pt_ofs = xe_bo_size(bo) - 2 * XE_PAGE_SIZE;
+                       for (i = 0, usm_pte = 0; i < xe_bo_size(batch);
                             i += vm->flags & XE_VM_FLAG_64K ? XE_64K_PAGE_SIZE 
:
-                            XE_PAGE_SIZE) {
+                            XE_PAGE_SIZE, usm_pte++) {
                                entry = vm->pt_ops->pte_encode_bo(batch, i,
                                                                  pat_index, 0);

-                               xe_map_wr(xe, &bo->vmap, map_ofs + level * 8, 
u64,
-                                         entry);
-                               level++;
+                               xe_map_wr(xe, &bo->vmap,
+                                         usm_pt_ofs + usm_pte * 8, u64, entry);
                        }
+
+                       usm_pde_slot = NUM_PT_SLOTS - 1;
+                       xe_tile_assert(tile,
+                                      usm_pde_slot > map_ofs / XE_PAGE_SIZE);
+                       entry = vm->pt_ops->pde_encode_bo(bo, usm_pt_ofs);
+                       xe_map_wr(xe, &bo->vmap, map_ofs + XE_PAGE_SIZE +
+                                 usm_pde_slot * 8, u64, entry);
+                       m->usm_batch_base_ofs = (u64)usm_pde_slot <<
+                               xe_pt_shift(1);
                }
        } else {
                u64 batch_addr = xe_bo_addr(batch, 0, XE_PAGE_SIZE);
--
2.34.1

Reply via email to