diff mbox series

[2/2] drm/ttm: Move pinned objects off LRU lists when pinning

Message ID 20240902154159.78871-3-thomas.hellstrom@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series drm/ttm: Really use a separate LRU list for swapped- and pinned objects | expand

Commit Message

Thomas Hellström Sept. 2, 2024, 3:41 p.m. UTC
The ttm_bo_pin() and ttm_bo_unpin() functions weren't moving their
resources off the LRU list to the unevictable list.

Make sure that happens so that pinned objects don't accidently linger
on the LRU lists, and also make sure to move them back once they
are unpinned.

Cc: Christian König <christian.koenig@amd.com>
Cc: Matthew Brost <matthew.brost@intel.com>
Cc: <dri-devel@lists.freedesktop.org>
Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
---
 drivers/gpu/drm/ttm/ttm_bo.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

Comments

Christian König Sept. 3, 2024, 7:57 a.m. UTC | #1
Am 02.09.24 um 17:41 schrieb Thomas Hellström:
> The ttm_bo_pin() and ttm_bo_unpin() functions weren't moving their
> resources off the LRU list to the unevictable list.
>
> Make sure that happens so that pinned objects don't accidently linger
> on the LRU lists, and also make sure to move them back once they
> are unpinned.
>
> Cc: Christian König <christian.koenig@amd.com>
> Cc: Matthew Brost <matthew.brost@intel.com>
> Cc: <dri-devel@lists.freedesktop.org>
> Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>

I really can't figure out why we removed that. Anyway Reviewed-by: 
Christian König <christian.koenig@amd.com> for now.

> ---
>   drivers/gpu/drm/ttm/ttm_bo.c | 10 ++++++----
>   1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index d244566a7e48..057a65f51969 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -592,9 +592,10 @@ void ttm_bo_pin(struct ttm_buffer_object *bo)
>   	dma_resv_assert_held(bo->base.resv);
>   	WARN_ON_ONCE(!kref_read(&bo->kref));
>   	spin_lock(&bo->bdev->lru_lock);
> -	if (bo->resource)
> +	if (!bo->pin_count++ && bo->resource) {
>   		ttm_resource_del_bulk_move(bo->resource, bo);
> -	++bo->pin_count;
> +		ttm_resource_move_to_lru_tail(bo->resource);
> +	}
>   	spin_unlock(&bo->bdev->lru_lock);
>   }
>   EXPORT_SYMBOL(ttm_bo_pin);
> @@ -613,9 +614,10 @@ void ttm_bo_unpin(struct ttm_buffer_object *bo)
>   		return;
>   
>   	spin_lock(&bo->bdev->lru_lock);
> -	--bo->pin_count;
> -	if (bo->resource)
> +	if (!--bo->pin_count && bo->resource) {
>   		ttm_resource_add_bulk_move(bo->resource, bo);
> +		ttm_resource_move_to_lru_tail(bo->resource);
> +	}
>   	spin_unlock(&bo->bdev->lru_lock);
>   }
>   EXPORT_SYMBOL(ttm_bo_unpin);
diff mbox series

Patch

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index d244566a7e48..057a65f51969 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -592,9 +592,10 @@  void ttm_bo_pin(struct ttm_buffer_object *bo)
 	dma_resv_assert_held(bo->base.resv);
 	WARN_ON_ONCE(!kref_read(&bo->kref));
 	spin_lock(&bo->bdev->lru_lock);
-	if (bo->resource)
+	if (!bo->pin_count++ && bo->resource) {
 		ttm_resource_del_bulk_move(bo->resource, bo);
-	++bo->pin_count;
+		ttm_resource_move_to_lru_tail(bo->resource);
+	}
 	spin_unlock(&bo->bdev->lru_lock);
 }
 EXPORT_SYMBOL(ttm_bo_pin);
@@ -613,9 +614,10 @@  void ttm_bo_unpin(struct ttm_buffer_object *bo)
 		return;
 
 	spin_lock(&bo->bdev->lru_lock);
-	--bo->pin_count;
-	if (bo->resource)
+	if (!--bo->pin_count && bo->resource) {
 		ttm_resource_add_bulk_move(bo->resource, bo);
+		ttm_resource_move_to_lru_tail(bo->resource);
+	}
 	spin_unlock(&bo->bdev->lru_lock);
 }
 EXPORT_SYMBOL(ttm_bo_unpin);