All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>
To: intel-xe@lists.freedesktop.org
Cc: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
	"Natalie Vock" <nat@pixelcluster.dev>,
	"Arun Pravin" <arunpravin.paneerselvam@amd.com>,
	"Matthew Auld" <matthew.auld@intel.com>,
	"Matthew Brost" <matthew.brost@intel.com>,
	"Niranjana Vishwanathapura" <niranjana.vishwanathapura@intel.com>,
	dri-devel@lists.freedesktop.org
Subject: [PATCH 2/4] drm/xe/bo: Pass page and tt counts to the shrinker account helpers
Date: Wed,  4 Nov 2026 21:13:29 +0100	[thread overview]
Message-ID: <20261104201331.2462-3-thomas.hellstrom@linux.intel.com> (raw)
In-Reply-To: <20261104201331.2462-1-thomas.hellstrom@linux.intel.com>

xe_ttm_tt_account_add() and xe_ttm_tt_account_subtract() always
account tt->num_pages and a single populated tt. Partial backup
support will need to account a subset of a tt's pages, and to keep
a partially backed-up tt counted as populated.

Add explicit page and tt count parameters. All callers pass
tt->num_pages and 1, so there is no functional change.

Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
---
 drivers/gpu/drm/xe/tests/xe_bo.c |  6 ++++--
 drivers/gpu/drm/xe/xe_bo.c       | 28 ++++++++++++++++------------
 2 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/xe/tests/xe_bo.c b/drivers/gpu/drm/xe/tests/xe_bo.c
index 6a17e13d58cf..472d5577e0fe 100644
--- a/drivers/gpu/drm/xe/tests/xe_bo.c
+++ b/drivers/gpu/drm/xe/tests/xe_bo.c
@@ -736,9 +736,11 @@ static int shrink_test_run_device(struct xe_device *xe)
 		 * other way around, they may not be subject to swapping...
 		 */
 		if (alloced < purgeable) {
-			xe_ttm_tt_account_subtract(xe, &xe_tt->ttm);
+			xe_ttm_tt_account_subtract(xe, &xe_tt->ttm,
+						   xe_tt->ttm.num_pages, 1);
 			xe_tt->purgeable = true;
-			xe_ttm_tt_account_add(xe, &xe_tt->ttm);
+			xe_ttm_tt_account_add(xe, &xe_tt->ttm,
+					      xe_tt->ttm.num_pages, 1);
 			bo->ttm.priority = 0;
 			spin_lock(&bo->ttm.bdev->lru_lock);
 			ttm_bo_move_to_lru_tail(&bo->ttm);
diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
index 42a6aa1a2e4a..2afee1a6de66 100644
--- a/drivers/gpu/drm/xe/xe_bo.c
+++ b/drivers/gpu/drm/xe/xe_bo.c
@@ -452,24 +452,26 @@ struct sg_table *xe_bo_sg(struct xe_bo *bo)
  * Account ttm pages against the device shrinker's shrinkable and
  * purgeable counts.
  */
-static void xe_ttm_tt_account_add(struct xe_device *xe, struct ttm_tt *tt)
+static void xe_ttm_tt_account_add(struct xe_device *xe, struct ttm_tt *tt,
+				  long num_pages, long tts)
 {
 	struct xe_ttm_tt *xe_tt = container_of(tt, struct xe_ttm_tt, ttm);
 
 	if (xe_tt->purgeable)
-		xe_shrinker_mod_pages(xe->mem.shrinker, 0, tt->num_pages, 1);
+		xe_shrinker_mod_pages(xe->mem.shrinker, 0, num_pages, tts);
 	else
-		xe_shrinker_mod_pages(xe->mem.shrinker, tt->num_pages, 0, 1);
+		xe_shrinker_mod_pages(xe->mem.shrinker, num_pages, 0, tts);
 }
 
-static void xe_ttm_tt_account_subtract(struct xe_device *xe, struct ttm_tt *tt)
+static void xe_ttm_tt_account_subtract(struct xe_device *xe, struct ttm_tt *tt,
+				       long num_pages, long tts)
 {
 	struct xe_ttm_tt *xe_tt = container_of(tt, struct xe_ttm_tt, ttm);
 
 	if (xe_tt->purgeable)
-		xe_shrinker_mod_pages(xe->mem.shrinker, 0, -(long)tt->num_pages, -1);
+		xe_shrinker_mod_pages(xe->mem.shrinker, 0, -num_pages, -tts);
 	else
-		xe_shrinker_mod_pages(xe->mem.shrinker, -(long)tt->num_pages, 0, -1);
+		xe_shrinker_mod_pages(xe->mem.shrinker, -num_pages, 0, -tts);
 }
 
 static bool xe_ttm_bo_is_imported(struct ttm_buffer_object *tbo)
@@ -503,7 +505,8 @@ static void xe_bo_account_pin(struct xe_bo *bo)
 
 	if (bo->ttm.pin_count == 1 && bo->ttm.ttm && ttm_tt_is_populated(bo->ttm.ttm) &&
 	    !xe_ttm_bo_is_imported(&bo->ttm))
-		xe_ttm_tt_account_subtract(xe, bo->ttm.ttm);
+		xe_ttm_tt_account_subtract(xe, bo->ttm.ttm,
+					   bo->ttm.ttm->num_pages, 1);
 }
 
 /*
@@ -534,7 +537,8 @@ static void xe_bo_account_unpin(struct xe_bo *bo)
 
 	if (last_unpin && bo->ttm.ttm && ttm_tt_is_populated(bo->ttm.ttm) &&
 	    !xe_ttm_bo_is_imported(&bo->ttm))
-		xe_ttm_tt_account_add(xe, bo->ttm.ttm);
+		xe_ttm_tt_account_add(xe, bo->ttm.ttm, bo->ttm.ttm->num_pages,
+				      1);
 }
 
 /**
@@ -682,7 +686,7 @@ static int xe_ttm_tt_populate(struct ttm_device *ttm_dev, struct ttm_tt *tt,
 		return err;
 
 	xe_tt->purgeable = false;
-	xe_ttm_tt_account_add(ttm_to_xe_device(ttm_dev), tt);
+	xe_ttm_tt_account_add(ttm_to_xe_device(ttm_dev), tt, tt->num_pages, 1);
 	update_global_total_pages(ttm_dev, tt->num_pages);
 
 	return 0;
@@ -699,7 +703,7 @@ static void xe_ttm_tt_unpopulate(struct ttm_device *ttm_dev, struct ttm_tt *tt)
 	xe_tt_unmap_sg(xe, tt);
 
 	ttm_pool_free(&ttm_dev->pool, tt);
-	xe_ttm_tt_account_subtract(xe, tt);
+	xe_ttm_tt_account_subtract(xe, tt, tt->num_pages, 1);
 	update_global_total_pages(ttm_dev, -(long)tt->num_pages);
 }
 
@@ -1391,7 +1395,7 @@ static long xe_bo_shrink_purge(struct ttm_operation_ctx *ctx,
 			      .allow_move = false});
 
 	if (lret > 0) {
-		xe_ttm_tt_account_subtract(xe, bo->ttm);
+		xe_ttm_tt_account_subtract(xe, bo->ttm, bo->ttm->num_pages, 1);
 		update_global_total_pages(bo->bdev, -(long)tt->num_pages);
 	}
 
@@ -1483,7 +1487,7 @@ long xe_bo_shrink(struct ttm_operation_ctx *ctx, struct ttm_buffer_object *bo,
 		xe_pm_runtime_put(xe);
 
 	if (lret > 0) {
-		xe_ttm_tt_account_subtract(xe, tt);
+		xe_ttm_tt_account_subtract(xe, tt, tt->num_pages, 1);
 		update_global_total_pages(bo->bdev, -(long)tt->num_pages);
 	}
 
-- 
2.56.0


  parent reply	other threads:[~2026-11-04 20:14 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-04 20:13 [PATCH 0/4] drm/ttm, drm/xe: Support partially backed-up ttm_tts Thomas Hellström
2026-11-04 20:13 ` [PATCH 1/4] drm/ttm: Don't mark backed-up shmem folios accessed Thomas Hellström
2026-11-04 20:13 ` Thomas Hellström [this message]
2026-11-04 20:13 ` [PATCH 3/4] drm/ttm, drm/xe: Introduce TTM_TT_FLAG_PARTIAL for partially backed-up tts Thomas Hellström
2026-11-04 20:47   ` sashiko-bot
2026-11-05  4:50   ` kernel test robot
2026-11-04 20:13 ` [PATCH 4/4] drm/ttm, drm/xe: Gate reserve-dipping backup retries on may_writeback Thomas Hellström
2026-11-04 20:41   ` sashiko-bot
2026-11-04 20:23 ` ✓ CI.KUnit: success for drm/ttm, drm/xe: Support partially backed-up ttm_tts Patchwork
2026-11-04 20:57 ` ✓ Xe.CI.BAT: " Patchwork
2026-11-05  4:36 ` ✓ CI.KUnit: success for drm/ttm, drm/xe: Support partially backed-up ttm_tts (rev2) Patchwork
2026-11-05  5:13 ` ✓ Xe.CI.BAT: " 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=20261104201331.2462-3-thomas.hellstrom@linux.intel.com \
    --to=thomas.hellstrom@linux.intel.com \
    --cc=arunpravin.paneerselvam@amd.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=niranjana.vishwanathapura@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.