Instead of the walker wrapper use the underlying foreach. Saves us quite
a bunch of complexity and loc.

Signed-off-by: Christian König <christian.koe...@amd.com>
---
 drivers/gpu/drm/ttm/ttm_bo.c     | 57 ++++++--------------------------
 drivers/gpu/drm/ttm/ttm_device.c | 19 ++++++++---
 include/drm/ttm/ttm_bo.h         |  5 ++-
 3 files changed, 27 insertions(+), 54 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index ea963dc43b62..2a4b98bfde57 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -1087,25 +1087,18 @@ int ttm_bo_wait_ctx(struct ttm_buffer_object *bo, 
struct ttm_operation_ctx *ctx)
 EXPORT_SYMBOL(ttm_bo_wait_ctx);
 
 /**
- * struct ttm_bo_swapout_walk - Parameters for the swapout walk
+ * ttm_bo_swapout() - Swap out buffer objects on the LRU list to shmem.
+ * @bo: The buffer to swap out.
+ * @ctx: The ttm_operation_ctx governing the swapout operation.
+ * @gfp_flags: The gfp flags used for shmem page allocations.
+ *
+ * Return: The number of bytes actually swapped out, or negative error code
+ * on error.
  */
-struct ttm_bo_swapout_walk {
-       /** @walk: The walk base parameters. */
-       struct ttm_lru_walk walk;
-       /** @gfp_flags: The gfp flags to use for ttm_tt_swapout() */
-       gfp_t gfp_flags;
-       /** @hit_low: Whether we should attempt to swap BO's with low watermark 
threshold */
-       /** @evict_low: If we cannot swap a bo when @try_low is false (first 
pass) */
-       bool hit_low, evict_low;
-};
-
-static s64
-ttm_bo_swapout_cb(struct ttm_lru_walk *walk, struct ttm_buffer_object *bo)
+s64 ttm_bo_swapout(struct ttm_buffer_object *bo, struct ttm_operation_ctx *ctx,
+                  gfp_t gfp_flags)
 {
        struct ttm_place place = {.mem_type = bo->resource->mem_type};
-       struct ttm_bo_swapout_walk *swapout_walk =
-               container_of(walk, typeof(*swapout_walk), walk);
-       struct ttm_operation_ctx *ctx = walk->arg.ctx;
        s64 ret;
 
        /*
@@ -1176,7 +1169,7 @@ ttm_bo_swapout_cb(struct ttm_lru_walk *walk, struct 
ttm_buffer_object *bo)
                ttm_resource_del_bulk_move(bo->resource, bo);
                spin_unlock(&bo->bdev->lru_lock);
 
-               ret = ttm_tt_swapout(bo->bdev, bo->ttm, 
swapout_walk->gfp_flags);
+               ret = ttm_tt_swapout(bo->bdev, bo->ttm, gfp_flags);
 
                spin_lock(&bo->bdev->lru_lock);
                if (ret)
@@ -1193,36 +1186,6 @@ ttm_bo_swapout_cb(struct ttm_lru_walk *walk, struct 
ttm_buffer_object *bo)
        return ret;
 }
 
-/**
- * ttm_bo_swapout() - Swap out buffer objects on the LRU list to shmem.
- * @bdev: The ttm device.
- * @ctx: The ttm_operation_ctx governing the swapout operation.
- * @man: The resource manager whose resources / buffer objects are
- * goint to be swapped out.
- * @gfp_flags: The gfp flags used for shmem page allocations.
- * @target: The desired number of bytes to swap out.
- *
- * Return: The number of bytes actually swapped out, or negative error code
- * on error.
- */
-s64 ttm_bo_swapout(struct ttm_device *bdev, struct ttm_operation_ctx *ctx,
-                  struct ttm_resource_manager *man, gfp_t gfp_flags,
-                  s64 target)
-{
-       struct ttm_bo_swapout_walk swapout_walk = {
-               .walk = {
-                       .process_bo = ttm_bo_swapout_cb,
-                       .arg = {
-                               .ctx = ctx,
-                               .trylock_only = true,
-                       },
-               },
-               .gfp_flags = gfp_flags,
-       };
-
-       return ttm_lru_walk_for_evict(&swapout_walk.walk, bdev, man, target);
-}
-
 void ttm_bo_tt_destroy(struct ttm_buffer_object *bo)
 {
        if (bo->ttm == NULL)
diff --git a/drivers/gpu/drm/ttm/ttm_device.c b/drivers/gpu/drm/ttm/ttm_device.c
index c3e2fcbdd2cc..7ba18e782131 100644
--- a/drivers/gpu/drm/ttm/ttm_device.c
+++ b/drivers/gpu/drm/ttm/ttm_device.c
@@ -173,6 +173,12 @@ int ttm_device_swapout(struct ttm_device *bdev, struct 
ttm_operation_ctx *ctx,
                       gfp_t gfp_flags)
 {
        struct ttm_resource_manager *man;
+       struct ttm_bo_lru_cursor cursor;
+       struct ttm_buffer_object *bo;
+       struct ttm_lru_walk_arg arg = {
+               .ctx = ctx,
+               .trylock_only = true
+       };
        unsigned i;
        s64 lret;
 
@@ -181,10 +187,15 @@ int ttm_device_swapout(struct ttm_device *bdev, struct 
ttm_operation_ctx *ctx,
                if (!man || !man->use_tt)
                        continue;
 
-               lret = ttm_bo_swapout(bdev, ctx, man, gfp_flags, 1);
-               /* Can be both positive (num_pages) and negative (error) */
-               if (lret)
-                       return lret;
+               ttm_bo_lru_for_each_reserved_guarded(&cursor, man, &arg, bo) {
+                       lret = ttm_bo_swapout(bo, ctx, gfp_flags);
+                               continue;
+                       /* Can be both positive (num_pages) and negative 
(error) */
+                       if (lret && lret != -EBUSY && lret != -EALREADY)
+                               return lret;
+               }
+               if (IS_ERR(bo))
+                       return PTR_ERR(bo);
        }
        return 0;
 }
diff --git a/include/drm/ttm/ttm_bo.h b/include/drm/ttm/ttm_bo.h
index 63331a4b37f9..6e85f9e207ad 100644
--- a/include/drm/ttm/ttm_bo.h
+++ b/include/drm/ttm/ttm_bo.h
@@ -398,9 +398,8 @@ void *ttm_bo_kmap_try_from_panic(struct ttm_buffer_object 
*bo, unsigned long pag
 int ttm_bo_vmap(struct ttm_buffer_object *bo, struct iosys_map *map);
 void ttm_bo_vunmap(struct ttm_buffer_object *bo, struct iosys_map *map);
 int ttm_bo_mmap_obj(struct vm_area_struct *vma, struct ttm_buffer_object *bo);
-s64 ttm_bo_swapout(struct ttm_device *bdev, struct ttm_operation_ctx *ctx,
-                  struct ttm_resource_manager *man, gfp_t gfp_flags,
-                  s64 target);
+s64 ttm_bo_swapout(struct ttm_buffer_object *bo, struct ttm_operation_ctx *ctx,
+                  gfp_t gfp_flags);
 void ttm_bo_pin(struct ttm_buffer_object *bo);
 void ttm_bo_unpin(struct ttm_buffer_object *bo);
 int ttm_bo_evict_first(struct ttm_device *bdev,
-- 
2.43.0

Reply via email to