mm/hugetlb_vmemmap.c
Source file repositories/reference/linux-study-clean/mm/hugetlb_vmemmap.c
File Facts
- System
- Linux kernel
- Corpus path
mm/hugetlb_vmemmap.c- Extension
.c- Size
- 25305 bytes
- Lines
- 903
- Domain
- Core OS
- Bucket
- Memory Management
- 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/pgtable.hlinux/moduleparam.hlinux/bootmem_info.hlinux/mmdebug.hlinux/pagewalk.hlinux/pgalloc.hasm/tlbflush.hhugetlb_vmemmap.hinternal.h
Detected Declarations
struct vmemmap_remap_walkfunction vmemmap_split_pmdfunction vmemmap_pmd_entryfunction vmemmap_pte_entryfunction vmemmap_remap_rangefunction free_bootmem_pagefunction free_vmemmap_page_listfunction vmemmap_remap_ptefunction vmemmap_restore_ptefunction vmemmap_remap_splitfunction vmemmap_remap_freefunction vmemmap_remap_rangefunction alloc_vmemmap_page_listfunction vmemmap_remap_allocfunction hugetlb_vmemmap_optimize_paramfunction __hugetlb_vmemmap_restore_foliofunction hugetlb_vmemmap_optimize_foliofunction hugetlb_vmemmap_restore_foliosfunction list_for_each_entry_safefunction vmemmap_should_optimize_foliofunction __hugetlb_vmemmap_optimize_foliofunction folio_test_hugetlb_vmemmap_optimizedfunction hugetlb_vmemmap_split_foliofunction __hugetlb_vmemmap_optimize_foliosfunction list_for_each_entryfunction __hugetlb_vmemmap_optimize_foliofunction hugetlb_vmemmap_optimize_foliosfunction hugetlb_vmemmap_optimize_bootmem_foliosfunction vmemmap_should_optimize_bootmem_pagefunction hugetlb_vmemmap_init_earlyfunction list_for_each_entryfunction hugetlb_vmemmap_init_latefunction list_for_each_entry_safefunction hugetlb_vmemmap_initfunction for_each_zonefunction for_each_hstate
Annotated Snippet
struct vmemmap_remap_walk {
void (*remap_pte)(pte_t *pte, unsigned long addr,
struct vmemmap_remap_walk *walk);
unsigned long nr_walked;
struct page *vmemmap_head;
struct page *vmemmap_tail;
struct list_head *vmemmap_pages;
/* Skip the TLB flush when we split the PMD */
#define VMEMMAP_SPLIT_NO_TLB_FLUSH BIT(0)
/* Skip the TLB flush when we remap the PTE */
#define VMEMMAP_REMAP_NO_TLB_FLUSH BIT(1)
unsigned long flags;
};
static int vmemmap_split_pmd(pmd_t *pmd, struct page *head, unsigned long start,
struct vmemmap_remap_walk *walk)
{
pmd_t __pmd;
int i;
unsigned long addr = start;
pte_t *pgtable;
pgtable = pte_alloc_one_kernel(&init_mm);
if (!pgtable)
return -ENOMEM;
pmd_populate_kernel(&init_mm, &__pmd, pgtable);
for (i = 0; i < PTRS_PER_PTE; i++, addr += PAGE_SIZE) {
pte_t entry, *pte;
pgprot_t pgprot = PAGE_KERNEL;
entry = mk_pte(head + i, pgprot);
pte = pte_offset_kernel(&__pmd, addr);
set_pte_at(&init_mm, addr, pte, entry);
}
spin_lock(&init_mm.page_table_lock);
if (likely(pmd_leaf(*pmd))) {
/*
* Higher order allocations from buddy allocator must be able to
* be treated as independent small pages (as they can be freed
* individually).
*/
if (!PageReserved(head))
split_page(head, get_order(PMD_SIZE));
/* Make pte visible before pmd. See comment in pmd_install(). */
smp_wmb();
pmd_populate_kernel(&init_mm, pmd, pgtable);
if (!(walk->flags & VMEMMAP_SPLIT_NO_TLB_FLUSH))
flush_tlb_kernel_range(start, start + PMD_SIZE);
} else {
pte_free_kernel(&init_mm, pgtable);
}
spin_unlock(&init_mm.page_table_lock);
return 0;
}
static int vmemmap_pmd_entry(pmd_t *pmd, unsigned long addr,
unsigned long next, struct mm_walk *walk)
{
int ret = 0;
struct page *head;
struct vmemmap_remap_walk *vmemmap_walk = walk->private;
/* Only splitting, not remapping the vmemmap pages. */
if (!vmemmap_walk->remap_pte)
walk->action = ACTION_CONTINUE;
spin_lock(&init_mm.page_table_lock);
head = pmd_leaf(*pmd) ? pmd_page(*pmd) : NULL;
/*
* Due to HugeTLB alignment requirements and the vmemmap
* pages being at the start of the hotplugged memory
* region in memory_hotplug.memmap_on_memory case. Checking
* the vmemmap page associated with the first vmemmap page
* if it is self-hosted is sufficient.
*
* [ hotplugged memory ]
* [ section ][...][ section ]
* [ vmemmap ][ usable memory ]
* ^ | ^ |
* +--+ | |
* +------------------------+
*/
Annotation
- Immediate include surface: `linux/pgtable.h`, `linux/moduleparam.h`, `linux/bootmem_info.h`, `linux/mmdebug.h`, `linux/pagewalk.h`, `linux/pgalloc.h`, `asm/tlbflush.h`, `hugetlb_vmemmap.h`.
- Detected declarations: `struct vmemmap_remap_walk`, `function vmemmap_split_pmd`, `function vmemmap_pmd_entry`, `function vmemmap_pte_entry`, `function vmemmap_remap_range`, `function free_bootmem_page`, `function free_vmemmap_page_list`, `function vmemmap_remap_pte`, `function vmemmap_restore_pte`, `function vmemmap_remap_split`.
- Atlas domain: Core OS / Memory Management.
- 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.