hibernate_pr...ocate_memory(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’€ 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_size divided by PAGE_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:


πŸ’œ 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