Add a new debug configuration option DRM_XE_DEBUG_DEFRAG that forces beneficial_reclaim_backoff when defragmentation is disabled in xe_ttm_tt_populate(). This helps force defragmentation to run.
When enabled, the driver will always set beneficial_reclaim_backoff to true for non-defrag allocations, preventing aggressive reclaim attempts that could prevent defragmentation from running. The option depends on EXPERT and is disabled by default, intended only for driver developers debugging memory fragmentation issues. Cc: Carlos Santa <[email protected]> Cc: Ryan Neph <[email protected]> Cc: Christian Koenig <[email protected]> Cc: Huang Rui <[email protected]> Cc: Matthew Auld <[email protected]> Cc: Maarten Lankhorst <[email protected]> Cc: Maxime Ripard <[email protected]> Cc: Thomas Zimmermann <[email protected]> Cc: David Airlie <[email protected]> Cc: Simona Vetter <[email protected]> Cc: [email protected] Cc: [email protected] Cc: Thomas Hellström <[email protected]> Assisted-by: GitHub_Copilot:claude-haiku-4.5 Signed-off-by: Matthew Brost <[email protected]> --- drivers/gpu/drm/xe/Kconfig.debug | 13 +++++++++++++ drivers/gpu/drm/xe/xe_bo.c | 3 ++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/xe/Kconfig.debug b/drivers/gpu/drm/xe/Kconfig.debug index 01227c77f6d7..f9cbb58dbcc3 100644 --- a/drivers/gpu/drm/xe/Kconfig.debug +++ b/drivers/gpu/drm/xe/Kconfig.debug @@ -102,6 +102,19 @@ config DRM_XE_DEBUG_GUC If in doubt, say "N". +config DRM_XE_DEBUG_DEFRAG + bool "Enable extra defragmentation debugging" + depends on EXPERT + default n + help + Choose this option when debugging memory defragmentation issues. + Forces beneficial_reclaim_backoff when defrag is disabled to help + force defragmentation. + + Recommended for driver developers only. + + If in doubt, say "N". + config DRM_XE_USERPTR_INVAL_INJECT bool "Inject userptr invalidation -EINVAL errors" depends on DRM_GPUSVM diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c index 1612e4ece1e1..f74fd6f5504a 100644 --- a/drivers/gpu/drm/xe/xe_bo.c +++ b/drivers/gpu/drm/xe/xe_bo.c @@ -592,7 +592,8 @@ static int xe_ttm_tt_populate(struct ttm_device *ttm_dev, struct ttm_tt *tt, if (ctx->defrag) ctx->beneficial_reclaim_backoff = false; - else if (atomic_read(&xe->mem.defrag.count) >= + else if (IS_ENABLED(CONFIG_DRM_XE_DEBUG_DEFRAG) || + atomic_read(&xe->mem.defrag.count) >= XE_BO_DEFRAG_RECLAIM_BACKOFF_THRESHOLD) ctx->beneficial_reclaim_backoff = true; -- 2.34.1
