[PATCH 20/22] PM: hibernate: size the image from common memory

From: Gregory Price (Meta)

Date: Sat Nov 14 2026 - 02:12:44 EST


hibernate_preallocate_memory() and enough_free_mem() count the free
pages of every populated zone as room for the hibernation image, but
the pages used to store the image can only come from common memory.

Count free pages only in zones on N_MEMORY_COMMON nodes.

The image metadata estimate is a separate sum. The bitmaps track the
page frames, and every zone's frames are tracked (regardless of node),
so that sum still needs to be calculated for all populated zones.

Every node with memory is common, so hibernation is unchanged.

Signed-off-by: Gregory Price (Meta) <gourry@xxxxxxxxxx>
---
kernel/power/snapshot.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c
index d5dba0e50b2eb..8aeb086a3fd3d 100644
--- a/kernel/power/snapshot.c
+++ b/kernel/power/snapshot.c
@@ -1866,8 +1866,10 @@ int hibernate_preallocate_memory(void)
saveable += save_highmem;
highmem = save_highmem;
size = 0;
- for_each_populated_zone(zone) {
+ for_each_populated_zone(zone)
size += snapshot_additional_pages(zone);
+ /* Image pages come from ordinary allocations. */
+ for_each_populated_zone_state(zone, N_MEMORY_COMMON) {
if (is_highmem(zone))
highmem += zone_page_state(zone, NR_FREE_PAGES);
else
@@ -2011,9 +2013,10 @@ static int enough_free_mem(unsigned int nr_pages, unsigned int nr_highmem)
struct zone *zone;
unsigned int free = alloc_normal;

- for_each_populated_zone(zone)
+ for_each_populated_zone_state(zone, N_MEMORY_COMMON) {
if (!is_highmem(zone))
free += zone_page_state(zone, NR_FREE_PAGES);
+ }

nr_pages += count_pages_for_highmem(nr_highmem);
pr_debug("Normal pages needed: %u + %u, available pages: %u\n",
--
2.53.1-Meta