mm/vmalloc.c
Source file repositories/reference/linux-study-clean/mm/vmalloc.c
File Facts
- System
- Linux kernel
- Corpus path
mm/vmalloc.c- Extension
.c- Size
- 147687 bytes
- Lines
- 5571
- 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/vmalloc.hlinux/mm.hlinux/module.hlinux/highmem.hlinux/sched/signal.hlinux/slab.hlinux/spinlock.hlinux/interrupt.hlinux/proc_fs.hlinux/seq_file.hlinux/set_memory.hlinux/debugobjects.hlinux/kallsyms.hlinux/list.hlinux/notifier.hlinux/rbtree.hlinux/xarray.hlinux/io.hlinux/rcupdate.hlinux/pfn.hlinux/kmemleak.hlinux/atomic.hlinux/compiler.hlinux/memcontrol.hlinux/llist.hlinux/uio.hlinux/bitops.hlinux/rbtree_augmented.hlinux/overflow.hlinux/pgtable.hlinux/hugetlb.hlinux/sched/mm.h
Detected Declarations
struct vfree_deferredstruct rb_liststruct vmap_poolstruct vmap_block_queuestruct vmap_blockstruct vmap_pfn_dataenum fit_typefunction set_nohugeiomapfunction set_nohugevmallocfunction is_vmalloc_addrfunction vmap_pte_rangefunction vmap_try_huge_pmdfunction vmap_pmd_rangefunction vmap_try_huge_pudfunction vmap_pud_rangefunction vmap_try_huge_p4dfunction vmap_p4d_rangefunction vmap_range_noflushfunction vmap_page_rangefunction ioremap_page_rangefunction vunmap_pte_rangefunction vunmap_pmd_rangefunction vunmap_pud_rangefunction vunmap_p4d_rangefunction flush_cache_vmapfunction vunmap_range_noflushfunction vunmap_rangefunction vmap_pages_pte_rangefunction vmap_pages_pmd_rangefunction vmap_pages_pud_rangefunction vmap_pages_p4d_rangefunction vmap_small_pages_range_noflushfunction flush_cache_vmapfunction vmap_pages_range_noflushfunction __vmap_pages_rangefunction vmap_pages_rangefunction check_sparse_vm_areafunction vm_area_map_pagesfunction vm_area_unmap_pagesfunction is_vmalloc_or_module_addrfunction vmallocfunction addr_to_node_idfunction addr_to_nodefunction id_to_nodefunction node_to_idfunction encode_vn_idfunction decode_vn_idfunction is_vn_id_valid
Annotated Snippet
module_init(proc_vmalloc_init);
#endif
static void __init vmap_init_free_space(void)
{
unsigned long vmap_start = 1;
const unsigned long vmap_end = ULONG_MAX;
struct vmap_area *free;
struct vm_struct *busy;
/*
* B F B B B F
* -|-----|.....|-----|-----|-----|.....|-
* | The KVA space |
* |<--------------------------------->|
*/
for (busy = vmlist; busy; busy = busy->next) {
if ((unsigned long) busy->addr - vmap_start > 0) {
free = kmem_cache_zalloc(vmap_area_cachep, GFP_NOWAIT);
if (!WARN_ON_ONCE(!free)) {
free->va_start = vmap_start;
free->va_end = (unsigned long) busy->addr;
insert_vmap_area_augment(free, NULL,
&free_vmap_area_root,
&free_vmap_area_list);
}
}
vmap_start = (unsigned long) busy->addr + busy->size;
}
if (vmap_end - vmap_start > 0) {
free = kmem_cache_zalloc(vmap_area_cachep, GFP_NOWAIT);
if (!WARN_ON_ONCE(!free)) {
free->va_start = vmap_start;
free->va_end = vmap_end;
insert_vmap_area_augment(free, NULL,
&free_vmap_area_root,
&free_vmap_area_list);
}
}
}
static void vmap_init_nodes(void)
{
struct vmap_node *vn;
int i;
#if BITS_PER_LONG == 64
/*
* A high threshold of max nodes is fixed and bound to 128,
* thus a scale factor is 1 for systems where number of cores
* are less or equal to specified threshold.
*
* As for NUMA-aware notes. For bigger systems, for example
* NUMA with multi-sockets, where we can end-up with thousands
* of cores in total, a "sub-numa-clustering" should be added.
*
* In this case a NUMA domain is considered as a single entity
* with dedicated sub-nodes in it which describe one group or
* set of cores. Therefore a per-domain purging is supposed to
* be added as well as a per-domain balancing.
*/
int n = clamp_t(unsigned int, num_possible_cpus(), 1, 128);
if (n > 1) {
vn = kmalloc_objs(*vn, n, GFP_NOWAIT);
if (vn) {
/* Node partition is 16 pages. */
vmap_zone_size = (1 << 4) * PAGE_SIZE;
nr_vmap_nodes = n;
vmap_nodes = vn;
} else {
pr_err("Failed to allocate an array. Disable a node layer\n");
}
}
#endif
for_each_vmap_node(vn) {
vn->busy.root = RB_ROOT;
INIT_LIST_HEAD(&vn->busy.head);
spin_lock_init(&vn->busy.lock);
vn->lazy.root = RB_ROOT;
INIT_LIST_HEAD(&vn->lazy.head);
spin_lock_init(&vn->lazy.lock);
Annotation
- Immediate include surface: `linux/vmalloc.h`, `linux/mm.h`, `linux/module.h`, `linux/highmem.h`, `linux/sched/signal.h`, `linux/slab.h`, `linux/spinlock.h`, `linux/interrupt.h`.
- Detected declarations: `struct vfree_deferred`, `struct rb_list`, `struct vmap_pool`, `struct vmap_block_queue`, `struct vmap_block`, `struct vmap_pfn_data`, `enum fit_type`, `function set_nohugeiomap`, `function set_nohugevmalloc`, `function is_vmalloc_addr`.
- 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.