* [PATCH] PM: hibernate: call preallocate_image after freeze prepare
@ 2026-03-21 8:51 Matthew Leach
2026-03-23 15:23 ` YoungJun Park
0 siblings, 1 reply; 3+ messages in thread
From: Matthew Leach @ 2026-03-21 8:51 UTC (permalink / raw)
To: Rafael J. Wysocki, Pavel Machek, Len Brown, Mario Limonciello
Cc: linux-pm, linux-kernel, kernel, Matthew Leach
Certain drivers release resources (pinned pages, etc.) into system
memory during the prepare freeze PM op, making them swappable.
Currently, hibernate_preallocate_memory is called before prepare freeze,
so those drivers have no opportunity to release resources first. If a
driver is holding a large amount of unswappable system RAM, this can
cause hibernate_preallocate_memory to fail.
Move the call to hibernate_preallocate_memory after prepare freeze.
According to the documentation for the prepare callback, devices should
be left in a usable state, so storage drivers should still be able to
service I/O requests. This allows drivers to release unswappable
resources prior to preallocation, so they can be swapped out through
hibernate_preallocate_memory's reclaim path.
Signed-off-by: Matthew Leach <matthew.leach@collabora.com>
---
kernel/power/hibernate.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index af8d07bafe02..ff62e220ded1 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -425,14 +425,9 @@ int hibernation_snapshot(int platform_mode)
if (error)
goto Close;
- /* Preallocate image memory before shutting down devices. */
- error = hibernate_preallocate_memory();
- if (error)
- goto Close;
-
error = freeze_kernel_threads();
if (error)
- goto Cleanup;
+ goto Close;
if (hibernation_test(TEST_FREEZER)) {
@@ -450,6 +445,11 @@ int hibernation_snapshot(int platform_mode)
goto Thaw;
}
+ /* Preallocate image memory before shutting down devices. */
+ error = hibernate_preallocate_memory();
+ if (error)
+ goto Thaw;
+
/*
* Device drivers may move lots of data to shmem in dpm_prepare(). The shmem
* pages will use lots of system memory, causing hibernation image creation
@@ -494,8 +494,6 @@ int hibernation_snapshot(int platform_mode)
Thaw:
thaw_kernel_threads();
- Cleanup:
- swsusp_free();
goto Close;
}
---
base-commit: f338e77383789c0cae23ca3d48adcc5e9e137e3c
change-id: 20260321-hibernation-fixes-69bca2ee5b65
Best regards,
--
Matt
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] PM: hibernate: call preallocate_image after freeze prepare
2026-03-21 8:51 [PATCH] PM: hibernate: call preallocate_image after freeze prepare Matthew Leach
@ 2026-03-23 15:23 ` YoungJun Park
2026-03-24 9:22 ` Matthew Leach
0 siblings, 1 reply; 3+ messages in thread
From: YoungJun Park @ 2026-03-23 15:23 UTC (permalink / raw)
To: Matthew Leach
Cc: Rafael J. Wysocki, Pavel Machek, Len Brown, Mario Limonciello,
linux-pm, linux-kernel, kernel
On Sat, Mar 21, 2026 at 08:51:31AM +0000, Matthew Leach wrote:
Hi Matthew,
> + /* Preallocate image memory before shutting down devices. */
> + error = hibernate_preallocate_memory();
The shrink_shmem_memory() below is also intended to run after
dpm_prepare(), and the motivation is the same. Since
hibernate_preallocate_memory() already does shrinking internally,
how about pulling out the shrink-related parts and consolidating
them together?
> + if (error)
> + goto Thaw;
Don't we need to call dpm_complete(PMSG_RECOVER) in this error path?
> Thaw:
> thaw_kernel_threads();
> - Cleanup:
> - swsusp_free();
> goto Close;
Thanks,
Youngjun Park
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] PM: hibernate: call preallocate_image after freeze prepare
2026-03-23 15:23 ` YoungJun Park
@ 2026-03-24 9:22 ` Matthew Leach
0 siblings, 0 replies; 3+ messages in thread
From: Matthew Leach @ 2026-03-24 9:22 UTC (permalink / raw)
To: YoungJun Park
Cc: Rafael J. Wysocki, Pavel Machek, Len Brown, Mario Limonciello,
linux-pm, linux-kernel, kernel
YoungJun Park <youngjun.park@lge.com> writes:
> On Sat, Mar 21, 2026 at 08:51:31AM +0000, Matthew Leach wrote:
>
> Hi Matthew,
Hi Youngjun,
Thanks for the review.
>> + /* Preallocate image memory before shutting down devices. */
>> + error = hibernate_preallocate_memory();
>
> The shrink_shmem_memory() below is also intended to run after
> dpm_prepare(), and the motivation is the same. Since
> hibernate_preallocate_memory() already does shrinking internally,
> how about pulling out the shrink-related parts and consolidating
> them together?
Agreed. I'll remove shrink_shmem_memory() completely since
hibernate_preallocate_memory() will have swapped out as many pages as is
required to construct the image in system RAM. There's no point doing
another reclaim.
>> + if (error)
>> + goto Thaw;
>
> Don't we need to call dpm_complete(PMSG_RECOVER) in this error path?
Yes, good catch.
Regards,
--
Matt
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-03-24 9:22 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-21 8:51 [PATCH] PM: hibernate: call preallocate_image after freeze prepare Matthew Leach
2026-03-23 15:23 ` YoungJun Park
2026-03-24 9:22 ` Matthew Leach
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox