From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from 5.mo534.mail-out.ovh.net (5.mo534.mail-out.ovh.net [54.36.140.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 10825442134 for ; Mon, 6 Jul 2026 10:16:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=54.36.140.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783333006; cv=none; b=VePqCDDbmsIQpCqudBxiPwJVJ4+EtdlSoJ7j1PxPF0WhqAmkUUOgtbMJVV0J3ZKnnHhc3euotNVP07VVw6AAZuMVe2vwxWisvnqUW+xi7bXZ1g7LYK+j7bcPKkswBolmqReTfmBf/kJR8qu9+3pLAOP2tAFH7cgH/WBY8bp9h0M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783333006; c=relaxed/simple; bh=OTEWjMxR3ANDFCit+2ZsCLsugft1M4ubX/l+C4k3AjQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cMbAD0Knqzw2iflRoXVwqfBrcamVS72FtSbGEwxzUewx1sznhG6i1VKDwU0XOem1NyxfD0R/+IYxCled4XSUPKF/1c4yvvXx3CQB+3Ygvfr4538HRHU/VITIBXclVRAVU5Fck8aCNVBBfzlkdjkgAn1e70DahEAHmd+qOw6NJvQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pixelcluster.dev; spf=pass smtp.mailfrom=pixelcluster.dev; dkim=pass (2048-bit key) header.d=pixelcluster.dev header.i=@pixelcluster.dev header.b=g2qFX0Bb; arc=none smtp.client-ip=54.36.140.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pixelcluster.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pixelcluster.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pixelcluster.dev header.i=@pixelcluster.dev header.b="g2qFX0Bb" Received: from director4.derp.mail-out.ovh.net (director4.derp.mail-out.ovh.net [79.137.60.37]) by mo534.mail-out.ovh.net (Postfix) with ESMTPS id 4gv0SL0cLtz6JQw; Mon, 6 Jul 2026 10:08:50 +0000 (UTC) Received: from director4.derp.mail-out.ovh.net (director4.derp.mail-out.ovh.net. [127.0.0.1]) by director4.derp.mail-out.ovh.net (inspect_sender_mail_agent) with SMTP for ; Mon, 6 Jul 2026 10:08:49 +0000 (UTC) Received: from mta6.priv.ovhmail-u1.ea.mail.ovh.net (unknown [10.110.188.244]) by director4.derp.mail-out.ovh.net (Postfix) with ESMTPS id 4gv0SK6gg8z1xpM; Mon, 6 Jul 2026 10:08:49 +0000 (UTC) Received: from pixelcluster.dev (unknown [10.1.6.11]) (Authenticated sender: nat@pixelcluster.dev) by mta6.priv.ovhmail-u1.ea.mail.ovh.net (Postfix) with ESMTPSA id D6BB88E1900; Mon, 6 Jul 2026 10:08:47 +0000 (UTC) Authentication-Results:garm.ovh; auth=pass (GARM-104R0059e04c65d-8d6d-4e04-b7d3-3cab13c6df7f, F224CF1D020274B13B21E639C91833BCDAC0997A) smtp.auth=nat@pixelcluster.dev X-OVh-ClientIp:88.133.252.134 From: Natalie Vock Date: Mon, 06 Jul 2026 12:07:47 +0200 Subject: [PATCH v2 05/10] drm/ttm: switch to ttm_bo_lru_for_each_reserved_guarded for swapout Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20260706-ttm_2_drm_exec-v2-5-4bf6bfc0d320@pixelcluster.dev> References: <20260706-ttm_2_drm_exec-v2-0-4bf6bfc0d320@pixelcluster.dev> In-Reply-To: <20260706-ttm_2_drm_exec-v2-0-4bf6bfc0d320@pixelcluster.dev> To: Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , Christian Koenig , Huang Rui , Matthew Auld , Matthew Brost , =?utf-8?q?Thomas_Hellstr=C3=B6m?= , Alex Deucher Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org, amd-gfx@lists.freedesktop.org X-Mailer: b4 0.15.2 x-ovh-tracer-id: 9129077919805890876 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: dmFkZTGrlNJ8ShesFc0BsmoWFi51A7F15j2IaCkSK7BVZBg/BM8MBdGhyqLZmkbZMHw/TdptOPm8sgahQti1Nc9RjBh0KMZiGtpja+p6qhts3jrWUso58aRKRrx2DXtHoeXDd8faKpktnEASA9l57md6lmCqaecpmqLv9KOaMd5Cxk2fFcLRCf7Y1jiwLpKZwWHOg5MLCHSu/c85HhHBD+9tK6DpmR22NTjUbN0dGZJB9cmuuQPGLboQ0v7ZPGbXkip9C+NIKd694im0qBCyEcUf/DwxdiDWy9o5iBQA1zQlg0Y75Jpr3La1ocQctyDO3tKJ1UAaq83N/bdymi3oIi31d22Yh6zN0szX2fjCorgmlUwVsjE42R4cTUcyqWz8MJeNfTNeP58CJHiBRHfaOjZHzza+XgPWTFpoIfg39AhpFofapCMjO7Ye8tJfkRcDZwKWHSZc3S4MvZTGAWdHg0lHSkQGvwVvhKn4W9HZH5r47r2MwndWzZPkDQNff/femBsHqANAlYoPK31aHYUR7TGaR5mpDIFitIRzL4jD39nXjOaEIIrSfuIPhhnyDASz5xnxL4YR3aqQtkjp50TS0CduEin0X3zqcP3/gH9LpY70gs6RDaQxwEGlT6DffCe+DpM7fanv05/Q08DKKvxNKcQEIfnBFMr26Jpm5IvsA5zPes/H5Q DKIM-Signature: a=rsa-sha256; bh=pL2GIfs9pCSQWKYD/oWsFK8PH5Ljesh1GOwIouQX/U8=; c=relaxed/relaxed; d=pixelcluster.dev; h=From; s=ovhmo-selector-1; t=1783332530; v=1; b=g2qFX0Bb0GEdNQAwaBtdy+IvZftPdYvnKZW6Sjv1c6W2jfP5cVO0sbPkGkDwBMIw9wwlgQiP SDbMVtBb1l1dGwl5RJRyZpsbaB9PVt8p1hi7Agsn+s/nNT5fn2zG5RXZchu956j9fWjzvAsVFw8 vLFOe3n1nzzDPqouUk+Eqjs0u5N9nFa9efKPwBrJXuNiste1osfgtOwhYvvCFHPiOhkIEyACkXu zEdLxvpnhG6wr3P7xeQ9ZPveToyVKkLOpz2v3hemmtq86dm87aGNjAZAmHvgr7FJoIY5sqd8r7W tgbuFcD/H4Y9zDvSyWeZKOk+20jJBa/k2ZCBKBYQTT4tw== Instead of the walker wrapper use the underlying foreach. Saves us quite a bunch of complexity and loc. Signed-off-by: Christian König Signed-off-by: Natalie Vock --- drivers/gpu/drm/ttm/ttm_bo.c | 58 +++++++--------------------------------- drivers/gpu/drm/ttm/ttm_device.c | 18 ++++++++++--- include/drm/ttm/ttm_bo.h | 5 ++-- 3 files changed, 26 insertions(+), 55 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index 1fb8c53da0362..24c52df169ac8 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -1080,25 +1080,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; struct ttm_device *bdev = bo->bdev; struct ttm_tt *tt = bo->ttm; s64 ret; @@ -1166,7 +1159,7 @@ ttm_bo_swapout_cb(struct ttm_lru_walk *walk, struct ttm_buffer_object *bo) bdev->funcs->swap_notify(bo); if (ttm_tt_is_populated(tt)) { - ret = ttm_tt_swapout(bdev, tt, swapout_walk->gfp_flags); + ret = ttm_tt_swapout(bdev, tt, gfp_flags); if (!ret) { spin_lock(&bdev->lru_lock); ttm_resource_del_bulk_move_unevictable(bo->resource, bo); @@ -1183,37 +1176,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 pages to swap out. - * - * Return: The number of pages 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); -} -EXPORT_SYMBOL_FOR_TESTS_ONLY(ttm_bo_swapout); - 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 d3bfb9a696a74..06fc5255d4091 100644 --- a/drivers/gpu/drm/ttm/ttm_device.c +++ b/drivers/gpu/drm/ttm/ttm_device.c @@ -171,6 +171,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; @@ -179,10 +185,14 @@ 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); + /* 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 0fcd5082a7080..bbed63064c9a9 100644 --- a/include/drm/ttm/ttm_bo.h +++ b/include/drm/ttm/ttm_bo.h @@ -408,9 +408,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.55.0