The TTM shrinker backs up a ttm_tt page by page, and can stop part way through, for example on an allocation failure. A failed restore can likewise leave some pages resident and some backed up. The ttm_tt has no way to represent such a partially backed-up state, so its status and the driver's shrinker accounting can become inconsistent.
This series introduces TTM_TT_FLAG_PARTIAL, which allows a tt to be partially backed up, keeping track of the pages that were already backed up and the pages that are still resident. Xe shrinker accounting is converted to track the number of remaining resident pages so that partial tts are accounted correctly. Patch 1 stops marking backed-up shmem folios accessed. Patch 2 is a pure refactor of the Xe shrinker account helpers. Patch 3 introduces TTM_TT_FLAG_PARTIAL and the matching Xe accounting. Patch 4 gates reserve-dipping backup retries on may_writeback. Note that patch 4 may increase the number of partially backed-up ttm_tts, since a backup that would need to dip into the kernel reserves is now aborted when writeback isn't allowed, keeping the progress made so far. This makes the partial tt handling of patch 3 more important. Testing: - W=1 build, checkpatch and kernel-doc are clean. - TTM and Xe KUnit tests pass. - The partial backup and restore paths are exercised by the shrink-fault-inject* subtests of the xe_bo_shrink IGT test, posted separately, using the TTM backup_fault_inject debugfs attribute. They need CONFIG_FAULT_INJECTION and CONFIG_FAULT_INJECTION_DEBUG_FS. The may_writeback retry in patch 4 is only hit statistically by that test. IGT test: https://patchwork.freedesktop.org/series/176563/ Test-with: [email protected] AI tool use: an AI coding assistant was used for review and for drafting parts of the implementation and commit messages. The author has reviewed and takes responsibility for all of the changes. Thomas Hellström (4): drm/ttm: Don't mark backed-up shmem folios accessed drm/xe/bo: Pass page and tt counts to the shrinker account helpers drm/ttm, drm/xe: Introduce TTM_TT_FLAG_PARTIAL for partially backed-up tts drm/ttm, drm/xe: Gate reserve-dipping backup retries on may_writeback drivers/gpu/drm/ttm/ttm_backup.c | 1 - drivers/gpu/drm/ttm/ttm_bo.c | 5 +- drivers/gpu/drm/ttm/ttm_bo_util.c | 9 +- drivers/gpu/drm/ttm/ttm_pool.c | 175 +++++++++++++++++++++--- drivers/gpu/drm/ttm/ttm_pool_internal.h | 2 + drivers/gpu/drm/ttm/ttm_tt.c | 36 ++++- drivers/gpu/drm/xe/tests/xe_bo.c | 6 +- drivers/gpu/drm/xe/xe_bo.c | 110 ++++++++++----- drivers/gpu/drm/xe/xe_bo.h | 9 +- drivers/gpu/drm/xe/xe_shrinker.c | 39 +++++- include/drm/ttm/ttm_bo.h | 9 +- include/drm/ttm/ttm_tt.h | 58 ++++++-- 12 files changed, 371 insertions(+), 88 deletions(-) -- 2.56.0
