From: Samuel Zhang <guoqing.zhang@amd.com>
To: <rafael@kernel.org>, <len.brown@intel.com>, <pavel@kernel.org>,
<alexander.deucher@amd.com>, <christian.koenig@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>,
Samuel Zhang <guoqing.zhang@amd.com>
Subject: [PATCH 2/3] PM: hibernate: shrink shmem pages after dev_pm_ops.prepare()
Date: Mon, 30 Jun 2025 18:41:15 +0800 [thread overview]
Message-ID: <20250630104116.3050306-3-guoqing.zhang@amd.com> (raw)
In-Reply-To: <20250630104116.3050306-1-guoqing.zhang@amd.com>
When hibernate with data center dGPUs, huge number of VRAM data will be
moved to shmem during dev_pm_ops.prepare(). These shmem pages take a lot
of system memory so that there's no enough free memory for creating the
hibernation image. This will cause hibernation fail and abort.
After dev_pm_ops.prepare(), call shrink_all_memory() to force move shmem
pages to swap disk and reclaim the pages, so that there's enough system
memory for hibernation image and less pages needed to copy to the image.
This patch can only flush and free about half shmem pages. It will be
better to flush and free more pages, even all of shmem pages, so that
there're less pages to be copied to the hibernation image and the overall
hibernation time can be reduced.
Signed-off-by: Samuel Zhang <guoqing.zhang@amd.com>
---
kernel/power/hibernate.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index 10a01af63a80..913a298c1d01 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -370,6 +370,17 @@ static int create_image(int platform_mode)
return error;
}
+static void shrink_shmem_memory(void)
+{
+ struct sysinfo info;
+ unsigned long pages, freed;
+
+ si_meminfo(&info);
+ pages = info.sharedram;
+ freed = shrink_all_memory(pages);
+ pr_debug("requested to reclaim %lu pages, freed %lu pages\n", pages, freed);
+}
+
/**
* hibernation_snapshot - Quiesce devices and create a hibernation image.
* @platform_mode: If set, use platform driver to prepare for the transition.
@@ -411,6 +422,8 @@ int hibernation_snapshot(int platform_mode)
goto Thaw;
}
+ shrink_shmem_memory();
+
suspend_console();
pm_restrict_gfp_mask();
--
2.43.5
next prev parent reply other threads:[~2025-06-30 10:41 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
[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 ` Samuel Zhang [this message]
2025-06-30 20:21 ` [PATCH 2/3] PM: hibernate: shrink shmem pages after dev_pm_ops.prepare() 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=20250630104116.3050306-3-guoqing.zhang@amd.com \
--to=guoqing.zhang@amd.com \
--cc=Qing.Ma@amd.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--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