mm/page_alloc.c
Source file repositories/reference/linux-study-clean/mm/page_alloc.c
File Facts
- System
- Linux kernel
- Corpus path
mm/page_alloc.c- Extension
.c- Size
- 228221 bytes
- Lines
- 7967
- 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/highmem.hlinux/interrupt.hlinux/jiffies.hlinux/compiler.hlinux/kernel.hlinux/kasan.hlinux/kmsan.hlinux/module.hlinux/suspend.hlinux/ratelimit.hlinux/oom.hlinux/topology.hlinux/sysctl.hlinux/cpu.hlinux/cpuset.hlinux/folio_batch.hlinux/memory_hotplug.hlinux/nodemask.hlinux/vmstat.hlinux/fault-inject.hlinux/compaction.htrace/events/kmem.htrace/events/oom.hlinux/prefetch.hlinux/mm_inline.hlinux/mmu_notifier.hlinux/migrate.hlinux/sched/mm.hlinux/page_owner.hlinux/page_table_check.h
Detected Declarations
enum rmqueue_modefunction deferred_grow_zonefunction _deferred_grow_zonefunction pfn_to_bitidxfunction is_standalone_pb_bitfunction get_pfnblock_bitmap_bitidxfunction __get_pfnblock_flags_maskfunction get_pfnblock_bitfunction get_pfnblock_migratetypefunction __set_pfnblock_flags_maskfunction set_pfnblock_bitfunction clear_pfnblock_bitfunction set_pageblock_migratetypefunction init_pageblock_migratetypefunction page_outside_zone_boundariesfunction bad_rangefunction bad_rangefunction bad_pagefunction order_to_pindexfunction pindex_to_orderfunction pcp_allowed_orderfunction prep_compound_pagefunction set_buddy_orderfunction compaction_capturefunction compaction_capturefunction account_freepagesfunction __add_to_free_listfunction againfunction __del_page_from_free_listfunction del_page_from_free_listfunction buddy_merge_likelyfunction change_pageblock_rangefunction memoryfunction page_expected_statefunction free_page_is_badfunction is_check_pages_enabledfunction free_tail_page_preparefunction should_skip_kasan_poisonfunction clear_highpages_kasan_taggedfunction __clear_page_tag_reffunction __pgalloc_tag_addfunction pgalloc_tag_addfunction __pgalloc_tag_subfunction pgalloc_tag_subfunction pgalloc_tag_sub_pagesfunction pgalloc_tag_addfunction free_pages_preparefunction free_pcppages_bulk
Annotated Snippet
if (time_before(jiffies, resume)) {
nr_unshown++;
goto out;
}
if (nr_unshown) {
pr_alert(
"BUG: Bad page state: %lu messages suppressed\n",
nr_unshown);
nr_unshown = 0;
}
nr_shown = 0;
}
if (nr_shown++ == 0)
resume = jiffies + 60 * HZ;
pr_alert("BUG: Bad page state in process %s pfn:%05lx\n",
current->comm, page_to_pfn(page));
dump_page(page, reason);
print_modules();
dump_stack();
out:
/* Leave bad fields for debug, except PageBuddy could make trouble */
if (PageBuddy(page))
__ClearPageBuddy(page);
add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);
}
static inline unsigned int order_to_pindex(int migratetype, int order)
{
if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) {
bool movable = migratetype == MIGRATE_MOVABLE;
if (order > PAGE_ALLOC_COSTLY_ORDER)
return NR_LOWORDER_PCP_LISTS + movable;
}
return (MIGRATE_PCPTYPES * order) + migratetype;
}
static inline int pindex_to_order(unsigned int pindex)
{
int order = pindex / MIGRATE_PCPTYPES;
if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) {
if (pindex >= NR_LOWORDER_PCP_LISTS)
order = HPAGE_PMD_ORDER;
}
return order;
}
static inline bool pcp_allowed_order(unsigned int order)
{
if (order <= PAGE_ALLOC_COSTLY_ORDER)
return true;
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
if (is_pmd_order(order))
return true;
#endif
return false;
}
/*
* Higher-order pages are called "compound pages". They are structured thusly:
*
* The first PAGE_SIZE page is called the "head page" and have PG_head set.
*
* The remaining PAGE_SIZE pages are called "tail pages". PageTail() is encoded
* in bit 0 of page->compound_info. The rest of bits is pointer to head page.
*
* The first tail page's ->compound_order holds the order of allocation.
* This usage means that zero-order pages may not be compound.
*/
void prep_compound_page(struct page *page, unsigned int order)
{
int i;
int nr_pages = 1 << order;
__SetPageHead(page);
for (i = 1; i < nr_pages; i++)
prep_compound_tail(page + i, page, order);
prep_compound_head(page, order);
}
static inline void set_buddy_order(struct page *page, unsigned int order)
{
set_page_private(page, order);
Annotation
- Immediate include surface: `linux/stddef.h`, `linux/mm.h`, `linux/highmem.h`, `linux/interrupt.h`, `linux/jiffies.h`, `linux/compiler.h`, `linux/kernel.h`, `linux/kasan.h`.
- Detected declarations: `enum rmqueue_mode`, `function deferred_grow_zone`, `function _deferred_grow_zone`, `function pfn_to_bitidx`, `function is_standalone_pb_bit`, `function get_pfnblock_bitmap_bitidx`, `function __get_pfnblock_flags_mask`, `function get_pfnblock_bit`, `function get_pfnblock_migratetype`, `function __set_pfnblock_flags_mask`.
- 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.