mm/memory_hotplug.c
Source file repositories/reference/linux-study-clean/mm/memory_hotplug.c
File Facts
- System
- Linux kernel
- Corpus path
mm/memory_hotplug.c- Extension
.c- Size
- 68918 bytes
- Lines
- 2437
- Domain
- Core OS
- Bucket
- Memory Management
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/stddef.hlinux/mm.hlinux/sched/signal.hlinux/swap.hlinux/interrupt.hlinux/pagemap.hlinux/compiler.hlinux/export.hlinux/writeback.hlinux/slab.hlinux/sysctl.hlinux/cpu.hlinux/memory.hlinux/memremap.hlinux/memory_hotplug.hlinux/vmalloc.hlinux/ioport.hlinux/delay.hlinux/migrate.hlinux/page-isolation.hlinux/pfn.hlinux/suspend.hlinux/mm_inline.hlinux/firmware-map.hlinux/stop_machine.hlinux/hugetlb.hlinux/memblock.hlinux/compaction.hlinux/rmap.hlinux/module.hlinux/node.hasm/tlbflush.h
Detected Declarations
struct auto_movable_statsstruct auto_movable_group_statsfunction memory_block_memmap_sizefunction memory_block_memmap_on_memory_pagesfunction set_memmap_modefunction get_memmap_modefunction mhp_memmap_on_memoryfunction mhp_memmap_on_memoryfunction set_online_policyfunction get_online_policyfunction get_online_memsfunction put_online_memsfunction mhp_get_default_online_typefunction mhp_set_default_online_typefunction setup_memhp_default_statefunction mem_hotplug_beginfunction mem_hotplug_donefunction release_memory_resourcefunction check_pfn_spanfunction __add_pagesfunction find_smallest_section_pfnfunction find_biggest_section_pfnfunction shrink_zone_spanfunction update_pgdat_spanfunction remove_pfn_range_from_zonefunction __remove_pagesfunction set_online_page_callbackfunction restore_online_page_callbackfunction generic_online_pagefunction online_pages_rangefunction resize_zone_rangefunction resize_pgdat_rangefunction section_taint_zone_devicefunction section_taint_zone_devicefunction pfn_to_online_pagefunction auto_movable_stats_account_zonefunction auto_movable_stats_account_groupfunction auto_movable_can_online_movablefunction againfunction adjust_present_page_countfunction mhp_init_memmap_on_memoryfunction mhp_deinit_memmap_on_memoryfunction online_pagesfunction cpu_upfunction try_online_nodefunction check_hotplug_memory_rangefunction online_memory_blockfunction arch_supports_memmap_on_memory
Annotated Snippet
struct auto_movable_stats {
unsigned long kernel_early_pages;
unsigned long movable_pages;
};
static void auto_movable_stats_account_zone(struct auto_movable_stats *stats,
struct zone *zone)
{
if (zone_idx(zone) == ZONE_MOVABLE) {
stats->movable_pages += zone->present_pages;
} else {
stats->kernel_early_pages += zone->present_early_pages;
#ifdef CONFIG_CMA
/*
* CMA pages (never on hotplugged memory) behave like
* ZONE_MOVABLE.
*/
stats->movable_pages += zone->cma_pages;
stats->kernel_early_pages -= zone->cma_pages;
#endif /* CONFIG_CMA */
}
}
struct auto_movable_group_stats {
unsigned long movable_pages;
unsigned long req_kernel_early_pages;
};
static int auto_movable_stats_account_group(struct memory_group *group,
void *arg)
{
const int ratio = READ_ONCE(auto_movable_ratio);
struct auto_movable_group_stats *stats = arg;
long pages;
/*
* We don't support modifying the config while the auto-movable online
* policy is already enabled. Just avoid the division by zero below.
*/
if (!ratio)
return 0;
/*
* Calculate how many early kernel pages this group requires to
* satisfy the configured zone ratio.
*/
pages = group->present_movable_pages * 100 / ratio;
pages -= group->present_kernel_pages;
if (pages > 0)
stats->req_kernel_early_pages += pages;
stats->movable_pages += group->present_movable_pages;
return 0;
}
static bool auto_movable_can_online_movable(int nid, struct memory_group *group,
unsigned long nr_pages)
{
unsigned long kernel_early_pages, movable_pages;
struct auto_movable_group_stats group_stats = {};
struct auto_movable_stats stats = {};
struct zone *zone;
int i;
/* Walk all relevant zones and collect MOVABLE vs. KERNEL stats. */
if (nid == NUMA_NO_NODE) {
/* TODO: cache values */
for_each_populated_zone(zone)
auto_movable_stats_account_zone(&stats, zone);
} else {
for (i = 0; i < MAX_NR_ZONES; i++) {
pg_data_t *pgdat = NODE_DATA(nid);
zone = pgdat->node_zones + i;
if (populated_zone(zone))
auto_movable_stats_account_zone(&stats, zone);
}
}
kernel_early_pages = stats.kernel_early_pages;
movable_pages = stats.movable_pages;
/*
* Kernel memory inside dynamic memory group allows for more MOVABLE
* memory within the same group. Remove the effect of all but the
* current group from the stats.
*/
walk_dynamic_memory_groups(nid, auto_movable_stats_account_group,
group, &group_stats);
if (kernel_early_pages <= group_stats.req_kernel_early_pages)
return false;
Annotation
- Immediate include surface: `linux/stddef.h`, `linux/mm.h`, `linux/sched/signal.h`, `linux/swap.h`, `linux/interrupt.h`, `linux/pagemap.h`, `linux/compiler.h`, `linux/export.h`.
- Detected declarations: `struct auto_movable_stats`, `struct auto_movable_group_stats`, `function memory_block_memmap_size`, `function memory_block_memmap_on_memory_pages`, `function set_memmap_mode`, `function get_memmap_mode`, `function mhp_memmap_on_memory`, `function mhp_memmap_on_memory`, `function set_online_policy`, `function get_online_policy`.
- Atlas domain: Core OS / Memory Management.
- Implementation status: integration 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.