kernel/power/snapshot.c
Source file repositories/reference/linux-study-clean/kernel/power/snapshot.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/power/snapshot.c- Extension
.c- Size
- 79690 bytes
- Lines
- 2931
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/version.hlinux/module.hlinux/mm.hlinux/suspend.hlinux/delay.hlinux/bitops.hlinux/spinlock.hlinux/kernel.hlinux/pm.hlinux/device.hlinux/init.hlinux/memblock.hlinux/nmi.hlinux/syscalls.hlinux/console.hlinux/highmem.hlinux/list.hlinux/slab.hlinux/compiler.hlinux/ktime.hlinux/set_memory.hlinux/uaccess.hasm/mmu_context.hasm/tlbflush.hasm/io.hpower.h
Detected Declarations
struct linked_pagestruct chain_allocatorstruct rtree_nodestruct mem_zone_bm_rtreestruct bm_positionstruct memory_bitmapstruct mem_extentstruct nosave_regionstruct highmem_pbefunction enable_restore_image_protectionfunction hibernate_restore_protection_beginfunction hibernate_restore_protection_endfunction hibernate_restore_protect_pagefunction hibernate_restore_unprotect_pagefunction hibernate_restore_protection_beginfunction hibernate_restore_unprotect_pagefunction hibernate_map_pagefunction hibernate_unmap_pagefunction hibernate_reserved_size_initfunction hibernate_image_size_initfunction swsusp_freefunction get_safe_pagefunction recycle_safe_pagefunction get_image_pagefunction free_list_of_pagesfunction chain_initfunction add_rtree_blockfunction free_zone_bm_rtreefunction memory_bm_position_resetfunction free_mem_extentsfunction list_for_each_entry_safefunction create_mem_extentsfunction for_each_populated_zonefunction list_for_each_entry_safe_continuefunction memory_bm_createfunction list_for_each_entryfunction memory_bm_freefunction memory_bm_find_bitfunction memory_bm_set_bitfunction mem_bm_set_bit_checkfunction memory_bm_clear_bitfunction memory_bm_clear_currentfunction memory_bm_get_currentfunction memory_bm_test_bitfunction memory_bm_pfn_presentfunction rtree_next_nodefunction memory_bm_position_resetfunction recycle_zone_bm_rtree
Annotated Snippet
struct linked_page {
struct linked_page *next;
char data[LINKED_PAGE_DATA_SIZE];
} __packed;
/*
* List of "safe" pages (ie. pages that were not used by the image kernel
* before hibernation) that may be used as temporary storage for image kernel
* memory contents.
*/
static struct linked_page *safe_pages_list;
/* Pointer to an auxiliary buffer (1 page) */
static void *buffer;
#define PG_ANY 0
#define PG_SAFE 1
#define PG_UNSAFE_CLEAR 1
#define PG_UNSAFE_KEEP 0
static unsigned int allocated_unsafe_pages;
/**
* get_image_page - Allocate a page for a hibernation image.
* @gfp_mask: GFP mask for the allocation.
* @safe_needed: Get pages that were not used before hibernation (restore only)
*
* During image restoration, for storing the PBE list and the image data, we can
* only use memory pages that do not conflict with the pages used before
* hibernation. The "unsafe" pages have PageNosaveFree set and we count them
* using allocated_unsafe_pages.
*
* Each allocated image page is marked as PageNosave and PageNosaveFree so that
* swsusp_free() can release it.
*/
static void *get_image_page(gfp_t gfp_mask, int safe_needed)
{
void *res;
res = (void *)get_zeroed_page(gfp_mask);
if (safe_needed)
while (res && swsusp_page_is_free(virt_to_page(res))) {
/* The page is unsafe, mark it for swsusp_free() */
swsusp_set_page_forbidden(virt_to_page(res));
allocated_unsafe_pages++;
res = (void *)get_zeroed_page(gfp_mask);
}
if (res) {
swsusp_set_page_forbidden(virt_to_page(res));
swsusp_set_page_free(virt_to_page(res));
}
return res;
}
static void *__get_safe_page(gfp_t gfp_mask)
{
if (safe_pages_list) {
void *ret = safe_pages_list;
safe_pages_list = safe_pages_list->next;
memset(ret, 0, PAGE_SIZE);
return ret;
}
return get_image_page(gfp_mask, PG_SAFE);
}
unsigned long get_safe_page(gfp_t gfp_mask)
{
return (unsigned long)__get_safe_page(gfp_mask);
}
static struct page *alloc_image_page(gfp_t gfp_mask)
{
struct page *page;
page = alloc_page(gfp_mask);
if (page) {
swsusp_set_page_forbidden(page);
swsusp_set_page_free(page);
}
return page;
}
static void recycle_safe_page(void *page_address)
{
struct linked_page *lp = page_address;
lp->next = safe_pages_list;
safe_pages_list = lp;
}
Annotation
- Immediate include surface: `linux/version.h`, `linux/module.h`, `linux/mm.h`, `linux/suspend.h`, `linux/delay.h`, `linux/bitops.h`, `linux/spinlock.h`, `linux/kernel.h`.
- Detected declarations: `struct linked_page`, `struct chain_allocator`, `struct rtree_node`, `struct mem_zone_bm_rtree`, `struct bm_position`, `struct memory_bitmap`, `struct mem_extent`, `struct nosave_region`, `struct highmem_pbe`, `function enable_restore_image_protection`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.