[PATCH 17/60] PM: hibernate: size the image from common memory

From: Gregory Price via B4 Relay

Date: Fri Nov 20 2026 - 13:12:36 EST


From: "Gregory Price (Meta)" <gourry@xxxxxxxxxx>

hibernate_preallocate_memory(), enough_free_mem() and
count_free_highmem_pages() 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.

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

diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c
index d5dba0e50b2e..912804bee361 100644
--- a/kernel/power/snapshot.c
+++ b/kernel/power/snapshot.c
@@ -1291,16 +1291,19 @@ static void mark_free_pages(struct zone *zone)
/**
* count_free_highmem_pages - Compute the total number of free highmem pages.
*
- * The returned number is system-wide.
+ * Only common memory counts, since image pages come from common memory.
*/
static unsigned int count_free_highmem_pages(void)
{
struct zone *zone;
unsigned int cnt = 0;

- for_each_populated_zone(zone)
+ for_each_populated_zone(zone) {
+ if (!node_state(zone_to_nid(zone), N_MEMORY_COMMON))
+ continue;
if (is_highmem(zone))
cnt += zone_page_state(zone, NR_FREE_PAGES);
+ }

return cnt;
}
@@ -1868,6 +1871,9 @@ int hibernate_preallocate_memory(void)
size = 0;
for_each_populated_zone(zone) {
size += snapshot_additional_pages(zone);
+ /* Image pages come from ordinary allocations. */
+ if (!node_state(zone_to_nid(zone), N_MEMORY_COMMON))
+ continue;
if (is_highmem(zone))
highmem += zone_page_state(zone, NR_FREE_PAGES);
else
@@ -2011,9 +2017,12 @@ 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(zone) {
+ if (!node_state(zone_to_nid(zone), N_MEMORY_COMMON))
+ continue;
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.56.1