mm/sparse.c
Source file repositories/reference/linux-study-clean/mm/sparse.c
File Facts
- System
- Linux kernel
- Corpus path
mm/sparse.c- Extension
.c- Size
- 10585 bytes
- Lines
- 392
- 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.
- 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/mm.hlinux/slab.hlinux/mmzone.hlinux/memblock.hlinux/compiler.hlinux/highmem.hlinux/export.hlinux/spinlock.hlinux/vmalloc.hlinux/swap.hlinux/swapops.hlinux/bootmem_info.hlinux/vmstat.hinternal.hasm/dma.h
Detected Declarations
function memdesc_nidfunction set_section_nidfunction set_section_nidfunction sparse_index_initfunction sparse_index_initfunction sparse_encode_early_nidfunction sparse_early_nidfunction mminit_validate_memmodel_limitsfunction first_present_section_nrfunction memory_presentfunction memory_presentfunction usemap_sizefunction mem_section_usage_sizefunction section_map_sizefunction section_map_sizefunction vmemmap_populate_print_lastfunction sparse_init_early_sectionfunction sparse_usage_initfunction sparse_usage_finifunction sparse_init_nidfunction for_each_present_section_nrfunction sparse_initfunction for_each_present_section_nrexport mem_sectionexport memdesc_nid
Annotated Snippet
if (!ms->section_mem_map) {
ms->section_mem_map = sparse_encode_early_nid(nid) |
SECTION_IS_ONLINE;
__section_mark_present(ms, section_nr);
}
}
}
/*
* Mark all memblocks as present using memory_present().
* This is a convenience function that is useful to mark all of the systems
* memory as present during initialization.
*/
static void __init memblocks_present(void)
{
unsigned long start, end;
int i, nid;
#ifdef CONFIG_SPARSEMEM_EXTREME
unsigned long size, align;
size = sizeof(struct mem_section *) * NR_SECTION_ROOTS;
align = 1 << (INTERNODE_CACHE_SHIFT);
mem_section = memblock_alloc_or_panic(size, align);
#endif
for_each_mem_pfn_range(i, MAX_NUMNODES, &start, &end, &nid)
memory_present(nid, start, end);
}
static unsigned long usemap_size(void)
{
return BITS_TO_LONGS(SECTION_BLOCKFLAGS_BITS) * sizeof(unsigned long);
}
size_t mem_section_usage_size(void)
{
return sizeof(struct mem_section_usage) + usemap_size();
}
#ifdef CONFIG_SPARSEMEM_VMEMMAP
unsigned long __init section_map_size(void)
{
return ALIGN(sizeof(struct page) * PAGES_PER_SECTION, PMD_SIZE);
}
#else
unsigned long __init section_map_size(void)
{
return PAGE_ALIGN(sizeof(struct page) * PAGES_PER_SECTION);
}
struct page __init *__populate_section_memmap(unsigned long pfn,
unsigned long nr_pages, int nid, struct vmem_altmap *altmap,
struct dev_pagemap *pgmap)
{
unsigned long size = section_map_size();
struct page *map;
phys_addr_t addr = __pa(MAX_DMA_ADDRESS);
map = memmap_alloc(size, size, addr, nid, false);
if (!map)
panic("%s: Failed to allocate %lu bytes align=0x%lx nid=%d from=%pa\n",
__func__, size, PAGE_SIZE, nid, &addr);
return map;
}
#endif /* !CONFIG_SPARSEMEM_VMEMMAP */
void __weak __meminit vmemmap_populate_print_last(void)
{
}
static void *sparse_usagebuf __meminitdata;
static void *sparse_usagebuf_end __meminitdata;
/*
* Helper function that is used for generic section initialization, and
* can also be used by any hooks added above.
*/
void __init sparse_init_early_section(int nid, struct page *map,
unsigned long pnum, unsigned long flags)
{
BUG_ON(!sparse_usagebuf || sparse_usagebuf >= sparse_usagebuf_end);
sparse_init_one_section(__nr_to_section(pnum), pnum, map,
sparse_usagebuf, SECTION_IS_EARLY | flags);
sparse_usagebuf = (void *)sparse_usagebuf + mem_section_usage_size();
}
static int __init sparse_usage_init(int nid, unsigned long map_count)
Annotation
- Immediate include surface: `linux/mm.h`, `linux/slab.h`, `linux/mmzone.h`, `linux/memblock.h`, `linux/compiler.h`, `linux/highmem.h`, `linux/export.h`, `linux/spinlock.h`.
- Detected declarations: `function memdesc_nid`, `function set_section_nid`, `function set_section_nid`, `function sparse_index_init`, `function sparse_index_init`, `function sparse_encode_early_nid`, `function sparse_early_nid`, `function mminit_validate_memmodel_limits`, `function first_present_section_nr`, `function memory_present`.
- Atlas domain: Core OS / Memory Management.
- Implementation status: integration implementation candidate.
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.