From: "Christian König" <christian.koenig@amd.com>
To: Samuel Zhang <guoqing.zhang@amd.com>,
rafael@kernel.org, len.brown@intel.com, pavel@kernel.org,
alexander.deucher@amd.com, mario.limonciello@amd.com,
lijo.lazar@amd.com
Cc: victor.zhao@amd.com, haijun.chang@amd.com, Qing.Ma@amd.com,
amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/3] drm/amdgpu: move GTT to SHM after eviction for hibernation
Date: Mon, 30 Jun 2025 13:54:18 +0200 [thread overview]
Message-ID: <ce04e266-6c3f-4256-aade-bafca8609ab3@amd.com> (raw)
In-Reply-To: <20250630104116.3050306-2-guoqing.zhang@amd.com>
On 30.06.25 12:41, Samuel Zhang wrote:
> When hibernate with data center dGPUs, huge number of VRAM BOs evicted
> to GTT and takes too much system memory. This will cause hibernation
> fail due to insufficient memory for creating the hibernation image.
>
> Move GTT BOs to shmem in KMD, then shmem to swap disk in kernel
> hibernation code to make room for hibernation image.
This should probably be two patches, one for TTM and then an amdgpu patch to forward the event.
>
> Signed-off-by: Samuel Zhang <guoqing.zhang@amd.com>
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 13 ++++++++++++-
> drivers/gpu/drm/ttm/ttm_resource.c | 18 ++++++++++++++++++
> include/drm/ttm/ttm_resource.h | 1 +
> 3 files changed, 31 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> index 4d57269c9ca8..5aede907a591 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> @@ -2889,6 +2889,7 @@ int amdgpu_fill_buffer(struct amdgpu_bo *bo,
> int amdgpu_ttm_evict_resources(struct amdgpu_device *adev, int mem_type)
> {
> struct ttm_resource_manager *man;
> + int r;
>
> switch (mem_type) {
> case TTM_PL_VRAM:
> @@ -2903,7 +2904,17 @@ int amdgpu_ttm_evict_resources(struct amdgpu_device *adev, int mem_type)
> return -EINVAL;
> }
>
> - return ttm_resource_manager_evict_all(&adev->mman.bdev, man);
> + r = ttm_resource_manager_evict_all(&adev->mman.bdev, man);
> + if (r) {
> + DRM_ERROR("Failed to evict memory type %d\n", mem_type);
> + return r;
> + }
> + if (adev->in_s4 && mem_type == TTM_PL_VRAM) {
> + r = ttm_resource_manager_swapout();
> + if (r)
> + DRM_ERROR("Failed to swap out, %d\n", r);
> + }
> + return r;
> }
>
> #if defined(CONFIG_DEBUG_FS)
> diff --git a/drivers/gpu/drm/ttm/ttm_resource.c b/drivers/gpu/drm/ttm/ttm_resource.c
> index fd41b56e2c66..07b1f5a5afc2 100644
> --- a/drivers/gpu/drm/ttm/ttm_resource.c
> +++ b/drivers/gpu/drm/ttm/ttm_resource.c
> @@ -534,6 +534,24 @@ void ttm_resource_manager_init(struct ttm_resource_manager *man,
> }
> EXPORT_SYMBOL(ttm_resource_manager_init);
>
> +int ttm_resource_manager_swapout(void)
This needs documentation, better placement and a better name.
First of all put it into ttm_device.c instead of the resource manager.
Then call it something like ttm_device_prepare_hibernation or similar.
> +{
> + struct ttm_operation_ctx ctx = {
> + .interruptible = false,
> + .no_wait_gpu = false,
> + .force_alloc = true
> + };
> + int ret;
> +
> + while (true) {
Make that:
do {
ret = ...
} while (ret > 0);
> + ret = ttm_global_swapout(&ctx, GFP_KERNEL);
> + if (ret <= 0)
> + break;
> + }
> + return ret;
It's rather pointless to return the number of swapped out pages.
Make that "return ret < 0 ? ret : 0;
Regards,
Christian.
> +}
> +EXPORT_SYMBOL(ttm_resource_manager_swapout);
> +
> /*
> * ttm_resource_manager_evict_all
> *
> diff --git a/include/drm/ttm/ttm_resource.h b/include/drm/ttm/ttm_resource.h
> index b873be9597e2..46181758068e 100644
> --- a/include/drm/ttm/ttm_resource.h
> +++ b/include/drm/ttm/ttm_resource.h
> @@ -463,6 +463,7 @@ void ttm_resource_manager_init(struct ttm_resource_manager *man,
>
> int ttm_resource_manager_evict_all(struct ttm_device *bdev,
> struct ttm_resource_manager *man);
> +int ttm_resource_manager_swapout(void);
>
> uint64_t ttm_resource_manager_usage(struct ttm_resource_manager *man);
> void ttm_resource_manager_debug(struct ttm_resource_manager *man,
next prev parent reply other threads:[~2025-06-30 11:54 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-30 10:41 [PATCH 0/3] reduce system memory requirement for hibernation Samuel Zhang
2025-06-30 10:41 ` [PATCH 1/3] drm/amdgpu: move GTT to SHM after eviction " Samuel Zhang
2025-06-30 11:54 ` Christian König [this message]
[not found] ` <DM4PR12MB5937FFB3E121E489A261785DE541A@DM4PR12MB5937.namprd12.prod.outlook.com>
2025-07-01 8:22 ` Christian König
2025-07-02 7:28 ` Samuel Zhang
2025-07-02 7:48 ` Christian König
2025-06-30 10:41 ` [PATCH 2/3] PM: hibernate: shrink shmem pages after dev_pm_ops.prepare() Samuel Zhang
2025-06-30 20:21 ` Rafael J. Wysocki
2025-06-30 10:41 ` [PATCH 3/3] drm/amdgpu: skip kfd resume_process for dev_pm_ops.thaw() Samuel Zhang
2025-06-30 11:58 ` Christian König
[not found] ` <8eb1700d-4d60-4a1e-9d09-718f65baaf1e@amd.com>
2025-07-01 8:32 ` Christian König
2025-07-01 16:07 ` Alex Deucher
2025-07-02 7:23 ` Sam
2025-07-02 13:54 ` Alex Deucher
2025-07-02 14:07 ` Lazar, Lijo
2025-07-04 10:24 ` Zhang, GuoQing (Sam)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ce04e266-6c3f-4256-aade-bafca8609ab3@amd.com \
--to=christian.koenig@amd.com \
--cc=Qing.Ma@amd.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=guoqing.zhang@amd.com \
--cc=haijun.chang@amd.com \
--cc=len.brown@intel.com \
--cc=lijo.lazar@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=mario.limonciello@amd.com \
--cc=pavel@kernel.org \
--cc=rafael@kernel.org \
--cc=victor.zhao@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox