From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BC0B73812E5 for ; Fri, 10 Jul 2026 19:08:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783710485; cv=none; b=dIxQNwpuFheBxxrltAQajmhcejwHr5EtUA08/n8E1kFOq9+mqLZuKc60fCSmaDStHMGYboGd0eP3BmbPtw7/dAutLHRsiefVqLEBISXLDkeKMGAhy98o1isxq5ZxJoirMtIuAubfNc13UX7M2axrt1swiQw7rm8uCxz3RXAd7Zw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783710485; c=relaxed/simple; bh=qasvnRCrB3ieIXWkpaz8amivNwFZTK/Yd4MlEKm8nB4=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pbr12KObCx3bkaAM+YoGXaQRwrwwV8FXzR2EzSTUd0maOV7VTt8UaB6twfvwwNKdIufKFJsVrLj58XI+gXGWFt057CQIjkQCLCwU2O1u9yHqmbaWN+lRimRhesV4132CrxaGB8lxjWTQo0SjHtCBGMmZX1deEzAmH+MVNmu2lOk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=q4eWRLEn; arc=none smtp.client-ip=209.85.128.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="q4eWRLEn" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-493c733f15aso12062585e9.0 for ; Fri, 10 Jul 2026 12:08:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783710480; x=1784315280; darn=vger.kernel.org; h=content-transfer-encoding:reply-to:content-type:mime-version :references:in-reply-to:message-id:date:subject:to:from:from:to:cc :subject:date:message-id:reply-to:content-type; bh=Nud4LNt/xG3jbsNqzwGg/sdwe8KwtNGJ8l07srTvdek=; b=q4eWRLEn9pJMY+AKC23k/iM+hYkGtpZWuorV2dXInhXtzoTvBYzXj3QBW2bwDP5t9c 4S58Zzhd9z4et3U0M0GewdG5LM9Ng5Q9ToimLiH5kVxHaL5QcHB08R5maXiMMN4VK5yB 4QFyGmKwEtWyi8dfWG8WbkgoBNNB0bMdccW1XdLJikzRtwwu8CBGqzBuhtuIscUudeTl 4sgpqj1YvUSeKJOAqaGtyAhz2rB/lU716Gy6RAjRDjVDyy2SCIlSL47CEVW/dFjHUsFe AAFJEzyIa5IMACkEClb6kcN48IqBCLPr0BUPnXP52eJOciStDSzXTUI6l9TGodvt/5Zd 8cEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783710480; x=1784315280; h=content-transfer-encoding:reply-to:content-type:mime-version :references:in-reply-to:message-id:date:subject:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Nud4LNt/xG3jbsNqzwGg/sdwe8KwtNGJ8l07srTvdek=; b=s/gI+a1jCNniHkNrOK2AnWtBxnTM0BtbK35P5eWXtPKdFbcjbjaHnzFIqb4PRig2OB +YeplzSjPCHf/ceZzPkn0CsvoM+Q3oGnVb/RimCcdQludzRTUU0lSb0npV8uwTAVIaYe ty4fTp8wx93uNM8pMdztJOmDaVg9PVY0lvHY72hMOkmzuEHeGaCY2WqvfjCLHqBV+5XA o5MJ9KERBDCcdlT16ntSG4T30aN2hUtaUQ0YEreFmRXJxx4EhjFP/wsGruO6jJeKa22e PNgDzV22uGQEnG0FlXpHxIc4RrGeDPJdMeHrBWUX1mghaJ97Z8O3wZwSsIfmW3aYmXH8 vw1Q== X-Forwarded-Encrypted: i=1; AHgh+Ro/j9A4eRe/vcUdFvT+SmZUxxJjJ+OgJpufc+ApIrcTDkDHdnaOnlRXxGVylt5CAjVmgzHN/lLZMRmk5J0=@vger.kernel.org X-Gm-Message-State: AOJu0YzxgMZA/RM0V8mI9D0cmXfRKukyzTT0THACDhoEhs1ReY4Ag31m 9HjklwGiZpuiWeupmXnB21XDNrr1KDL61yDeIvemoTwiTIfL+tF5lh7D X-Gm-Gg: AfdE7cmHVhU7BsMPIPBqHWwJE1+PN17goU4qoVdhgrcHjAmYQEx/jLKmrsRVuLGT5pf vuQcr+YYheiSUZ7jDZaluzVtf0CgpjCqJSLp7zcczvmbtEI/fe/qVM/EMUyoQDqz7Fh/JuYZnLx Wc8+VF+Md+Y0J4PJt0CZ0MjpizHViw4zDqdeIFXGnTmaBPoY/gIi93gGLNmL+OeuhX9A5gE7yCj t7NJyOK4a900uyjDD5XqNRTuSVDrktx1gLxH6Ll38CShjDI67Hgb69Oqe/Wkqcsrvej7Y09CTjq 9/wgrVOb77vtH8ZNC09QarrAAHRGrB5ezTC8VG0JmYSEguEigcaVvp9VaRpY/LnTjM43cifiJmA wpXVnXphmueHvxvOIZsO6PdZMvgeWF2+7LxnEP1z1jOssJTbJURtqOxUVnIWVAwbPWHSe0W2edO yUMMtXB19Mku14f1DSVqMhtC+JnQ== X-Received: by 2002:a05:600c:1394:b0:493:b89b:9a27 with SMTP id 5b1f17b1804b1-493f87e6c34mr1200255e9.9.1783710479887; Fri, 10 Jul 2026 12:07:59 -0700 (PDT) Received: from able.fritz.box ([2a00:e180:154f:ec00:aa08:de24:db33:4496]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-493f567eadfsm55000755e9.6.2026.07.10.12.07.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jul 2026 12:07:59 -0700 (PDT) From: "=?UTF-8?q?Christian=20K=C3=B6nig?=" X-Google-Original-From: =?UTF-8?q?Christian=20K=C3=B6nig?= To: thomas.hellstrom@linux.intel.com, dakr@kernel.org, ecourtney@nvidia.com, simona@ffwll.ch, matthew.brost@intel.com, nat@pixelcluster.dev, airlied@gmail.com, 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 Subject: [PATCH 05/12] drm/ttm: switch to ttm_bo_lru_for_each_reserved_guarded for swapout Date: Fri, 10 Jul 2026 20:52:45 +0200 Message-ID: <20260710190752.2355-6-christian.koenig@amd.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260710190752.2355-1-christian.koenig@amd.com> References: <20260710190752.2355-1-christian.koenig@amd.com> 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 Reply-To: christian.koenig@amd.com Content-Transfer-Encoding: 8bit Instead of the walker wrapper use the underlying foreach. Saves us quite a bunch of complexity and loc. Signed-off-by: Christian König --- drivers/gpu/drm/ttm/ttm_bo.c | 64 ++++++-------------------------- drivers/gpu/drm/ttm/ttm_device.c | 19 ++++++++-- include/drm/ttm/ttm_bo.h | 5 +-- 3 files changed, 28 insertions(+), 60 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index 8cf266da2bc61..db72fb2fde9ff 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -1088,25 +1088,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_place place = {.mem_type = bo->resource->mem_type}; struct ttm_device *bdev = bo->bdev; struct ttm_tt *tt = bo->ttm; s64 ret; @@ -1174,7 +1167,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); @@ -1191,41 +1184,6 @@ ttm_bo_swapout_cb(struct ttm_lru_walk *walk, struct ttm_buffer_object *bo) return ret; } -const struct ttm_lru_walk_ops ttm_swap_ops = { - .process_bo = ttm_bo_swapout_cb, -}; - -/** - * 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 = { - .ops = &ttm_swap_ops, - .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..e4188e2ee7ab1 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,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 30e835414e721..33dfa61ba882a 100644 --- a/include/drm/ttm/ttm_bo.h +++ b/include/drm/ttm/ttm_bo.h @@ -423,9 +423,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