Commit fc5d9667 authored by Thomas Hellström's avatar Thomas Hellström
Browse files

drm/ttm: Move swapped objects off the manager's LRU list



Resources of swapped objects remains on the TTM_PL_SYSTEM manager's
LRU list, which is bad for the LRU walk efficiency.

Rename the device-wide "pinned" list to "unevictable" and move
also resources of swapped-out objects to that list.

An alternative would be to create an "UNEVICTABLE" priority to
be able to keep the pinned- and swapped objects on their
respective manager's LRU without affecting the LRU walk efficiency.

v2:
- Remove a bogus WARN_ON (Christian König)
- Update ttm_resource_[add|del] bulk move (Christian König)
- Fix TTM KUNIT tests (Intel CI)
v3:
- Check for non-NULL bo->resource in ttm_bo_populate().
v4:
- Don't move to LRU tail during swapout until the resource
  is properly swapped or there was a swapout failure.
  (Intel Ci)
- Add a newline after checkpatch check.
v5:
- Introduce ttm_resource_is_swapped() to avoid a corner-case where
  a newly created resource was considered swapped. (Intel CI)
v6:
- Move an assert.

Cc: Christian König <christian.koenig@amd.com>
Cc: Matthew Brost <matthew.brost@intel.com>
Cc: <dri-devel@lists.freedesktop.org>
Signed-off-by: default avatarThomas Hellström <thomas.hellstrom@linux.intel.com>
Reviewed-by: default avatarChristian König <christian.koenig@amd.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20240911121859.85387-2-thomas.hellstrom@linux.intel.com
parent 42aa18d1
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -808,7 +808,7 @@ static int __i915_ttm_get_pages(struct drm_i915_gem_object *obj,
	}

	if (bo->ttm && !ttm_tt_is_populated(bo->ttm)) {
		ret = ttm_tt_populate(bo->bdev, bo->ttm, &ctx);
		ret = ttm_bo_populate(bo, &ctx);
		if (ret)
			return ret;

+1 −1
Original line number Diff line number Diff line
@@ -624,7 +624,7 @@ int i915_ttm_move(struct ttm_buffer_object *bo, bool evict,

	/* Populate ttm with pages if needed. Typically system memory. */
	if (ttm && (dst_man->use_tt || (ttm->page_flags & TTM_TT_FLAG_SWAPPED))) {
		ret = ttm_tt_populate(bo->bdev, ttm, ctx);
		ret = ttm_bo_populate(bo, ctx);
		if (ret)
			return ret;
	}
+2 −2
Original line number Diff line number Diff line
@@ -90,7 +90,7 @@ static int i915_ttm_backup(struct i915_gem_apply_to_region *apply,
		goto out_no_lock;

	backup_bo = i915_gem_to_ttm(backup);
	err = ttm_tt_populate(backup_bo->bdev, backup_bo->ttm, &ctx);
	err = ttm_bo_populate(backup_bo, &ctx);
	if (err)
		goto out_no_populate;

@@ -189,7 +189,7 @@ static int i915_ttm_restore(struct i915_gem_apply_to_region *apply,
	if (!backup_bo->resource)
		err = ttm_bo_validate(backup_bo, i915_ttm_sys_placement(), &ctx);
	if (!err)
		err = ttm_tt_populate(backup_bo->bdev, backup_bo->ttm, &ctx);
		err = ttm_bo_populate(backup_bo, &ctx);
	if (!err) {
		err = i915_gem_obj_copy_ttm(obj, backup, pm_apply->allow_gpu,
					    false);
+2 −2
Original line number Diff line number Diff line
@@ -308,11 +308,11 @@ static void ttm_bo_unreserve_pinned(struct kunit *test)
	err = ttm_resource_alloc(bo, place, &res2);
	KUNIT_ASSERT_EQ(test, err, 0);
	KUNIT_ASSERT_EQ(test,
			list_is_last(&res2->lru.link, &priv->ttm_dev->pinned), 1);
			list_is_last(&res2->lru.link, &priv->ttm_dev->unevictable), 1);

	ttm_bo_unreserve(bo);
	KUNIT_ASSERT_EQ(test,
			list_is_last(&res1->lru.link, &priv->ttm_dev->pinned), 1);
			list_is_last(&res1->lru.link, &priv->ttm_dev->unevictable), 1);

	ttm_resource_free(bo, &res1);
	ttm_resource_free(bo, &res2);
+3 −3
Original line number Diff line number Diff line
@@ -164,18 +164,18 @@ static void ttm_resource_init_pinned(struct kunit *test)

	res = kunit_kzalloc(test, sizeof(*res), GFP_KERNEL);
	KUNIT_ASSERT_NOT_NULL(test, res);
	KUNIT_ASSERT_TRUE(test, list_empty(&bo->bdev->pinned));
	KUNIT_ASSERT_TRUE(test, list_empty(&bo->bdev->unevictable));

	dma_resv_lock(bo->base.resv, NULL);
	ttm_bo_pin(bo);
	ttm_resource_init(bo, place, res);
	KUNIT_ASSERT_TRUE(test, list_is_singular(&bo->bdev->pinned));
	KUNIT_ASSERT_TRUE(test, list_is_singular(&bo->bdev->unevictable));

	ttm_bo_unpin(bo);
	ttm_resource_fini(man, res);
	dma_resv_unlock(bo->base.resv);

	KUNIT_ASSERT_TRUE(test, list_empty(&bo->bdev->pinned));
	KUNIT_ASSERT_TRUE(test, list_empty(&bo->bdev->unevictable));
}

static void ttm_resource_fini_basic(struct kunit *test)
Loading