hibernate_pr...ocate_memory(9)
π€ hibernate_preallocate_memory(9) β the Kernel API Manual, bestie edition β¨
okay so you found the Kernel API Manual page for this one, and honestly? it's a whole vibe. let's get into it π«Ά
πΈ NAME πΈ
hibernate_preallocate_memory β preallocate memory for a hibernation image. that's it, that's the girl π
β¨ SYNOPSIS β¨
int hibernate_preallocate_memory (void );
π ARGUMENTS π
voidβ no arguments. nothing. zero. she takes no input, she simply is ππ
π DESCRIPTION π
so here's the situation, bestie. to create a hibernation image you literally have to make a copy of every page frame in use. every single one. no cap. π¦
but wait, there's more β we also need a bunch of page frames to be free during hibernation, because allocations happen while the image is being saved, and device drivers might need to allocate memory from their hibernation callbacks. needy, but we respect it π
these two numbers are given by:
PAGES_FOR_IOβ which is a rough estimate (she's approximate, she's doing her best β¨)reserved_sizedivided byPAGE_SIZEβ which is tunable through/sys/power/reserved_size, respectively π
to make this whole thing happen, we compute the total number of available page frames and allocate at least
([page frames total] - PAGES_FOR_IO - [metadata pages]) / 2
2 * DIV_ROUND_UP(reserved_size, PAGE_SIZE)
of them, which corresponds to the maximum size of a hibernation image. main character math fr fr π₯
aaaand if image_size is set below the number that follows from the formula above? the preallocation of memory just keeps going β until the total number of saveable pages in the system is below the requested image size, or the minimum acceptable image size returned by minimum_image_size, whichever is greater. she keeps going until one of them wins ππ
β SEE ALSO β
kernel file ./kernel/power/snapshot.c, plus the whole friend group β they're all iconique, go say hi:
get_image_page(9)free_image_page(9)alloc_rtree_node(9)free_mem_extents(9)create_mem_extents(9)memory_bm_next_pfn(9)mark_nosave_pages(9)create_basic_memory_bitmaps(9)free_basic_memory_bitmaps(9)snapshot_additional_pages(9)count_free_highmem_pages(9)count_highmem_pages(9)count_data_pages(9)swsusp_free(9)preallocate_image_pages(9)free_unnecessary_pages(9)minimum_image_size(9)pack_pfns(9)snapshot_read_next(9)unpack_orig_pfns(9)count_highmem_image_pages(9)prepare_highmem_image(9)copy_last_highmem_page(9)prepare_image(9)snapshot_write_next(9)restore_highmem(9)
π reminder: this is kernel-level hibernation memory stuff β it's doing a lot, so don't assume anything the page doesn't say. the details above are the whole story, iykyk π
and that's the page!! π brought to you straight outta ./kernel/power, dated October 2026 β mwah, go take a nap, you've earned it π΄ππ§
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms