prepare_image(9)
prepare_image(9) π the kernel api manual, bestie
okay so this is prepare_image from the prepare_image(9) manual page, and we're gonna get into it because ngl this function is lowkey doing a lot. β¨
NAME πΈ
prepare_image β make room for loading hibernation image. periodt.
SYNOPSIS π
int prepare_image (struct memory_bitmap *new_bm , struct memory_bitmap
*bm , struct memory_bitmap
*zero_bm );
ARGUMENTS π
new_bmβ uninitialized memory bitmap structure. it's giving blank canvas energy, not me about to fill it in.bmβ memory bitmap with unsafe pages marked. like, the pages that are gonna get overwritten? they're flagged here, bestie.zero_bmβ memory bitmap containing the zero pages. the zeros are living their best life in this one.
DESCRIPTION π¦
use bm to mark the pages that will be overwritten in the process of restoring the system memory state from the suspend image (the "unsafe" pages) and allocate memory for the image. no cap, that's the whole vibe check.
the idea is to allocate a new memory bitmap first and then allocate as many pages as needed for image data, but without specifying what those pages will be used for just yet β like, we're manifesting pages but not labeling them, iykyk. instead, we mark them all as allocated and create a lists of "safe" pages to be used later. on systems with high memory a list of "safe" highmem pages is created too. slay for highmem honestly.
because it was not known which pages were unsafe when zero_bm was created, make a copy of it and recreate it within safe pages. literally the glow-up of bitmaps, we love to see it. π«Ά
SEE ALSO π₯
bestie, the crossover episode is real. go check out:
- kernel file
./kernel/power/snapshot.c 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)hibernate_preallocate_memory(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)snapshot_write_next(9)restore_highmem(9)
and that's the page! gentle reminder this one lives in ./kernel/power, dated October 2026, and it's part of the kernel api manual. made with π for the kernel girlies. bye bestie, go mark some safe pages! π§ββοΈ
π¦ 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