mm/vma.c
Source file repositories/reference/linux-study-clean/mm/vma.c
File Facts
- System
- Linux kernel
- Corpus path
mm/vma.c- Extension
.c- Size
- 93796 bytes
- Lines
- 3357
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
vma_internal.hvma.h
Detected Declarations
struct mmap_statefunction vma_is_fork_childfunction is_mergeable_vmafunction is_mergeable_anon_vmafunction init_multi_vma_prepfunction thisfunction thisfunction __vma_link_filefunction __remove_shared_vm_structfunction anon_vma_interval_tree_pre_update_vmafunction anon_vma_interval_tree_post_update_vmafunction vma_preparefunction vma_completefunction init_vma_prepfunction leftfunction rightfunction remove_vmafunction unmap_regionfunction __split_vmafunction split_vmafunction dup_anon_vmafunction validate_mmfunction vmg_adjust_set_rangefunction commit_mergefunction can_merge_remove_vmafunction middlefunction VMAfunction mremapfunction vma_expandfunction vma_shrinkfunction vms_clear_ptesfunction vms_clean_up_areafunction vms_complete_munmap_vmasfunction reattach_vmasfunction vms_gather_munmap_vmasfunction for_each_vma_rangefunction init_vma_munmapfunction do_vmi_align_munmapfunction do_vmi_munmapfunction unlink_file_vma_batch_initfunction unlink_file_vma_batch_processfunction unlink_file_vma_batch_addfunction unlink_file_vma_batch_finalfunction vma_link_filefunction vma_linkfunction anon_vma_compatiblefunction READ_ONCEfunction vm_ops_needs_writenotify
Annotated Snippet
* indices (16TB on ia32) because do_mmap() does not permit mmap's which
* wrap, nor mmaps which cover the final page at index -1UL.
*
* We assume the vma may be removed as part of the merge.
*/
static bool can_vma_merge_before(struct vma_merge_struct *vmg)
{
pgoff_t pglen = PHYS_PFN(vmg->end - vmg->start);
if (is_mergeable_vma(vmg, /* merge_next = */ true) &&
is_mergeable_anon_vma(vmg, /* merge_next = */ true)) {
if (vmg->next->vm_pgoff == vmg->pgoff + pglen)
return true;
}
return false;
}
/*
* Return true if we can merge this (vma_flags,anon_vma,file,vm_pgoff)
* beyond (at a higher virtual address and file offset than) the vma.
*
* We cannot merge two vmas if they have differently assigned (non-NULL)
* anon_vmas, nor if same anon_vma is assigned but offsets incompatible.
*
* We assume that vma is not removed as part of the merge.
*/
static bool can_vma_merge_after(struct vma_merge_struct *vmg)
{
if (is_mergeable_vma(vmg, /* merge_next = */ false) &&
is_mergeable_anon_vma(vmg, /* merge_next = */ false)) {
if (vmg->prev->vm_pgoff + vma_pages(vmg->prev) == vmg->pgoff)
return true;
}
return false;
}
static void __vma_link_file(struct vm_area_struct *vma,
struct address_space *mapping)
{
if (vma_is_shared_maywrite(vma))
mapping_allow_writable(mapping);
flush_dcache_mmap_lock(mapping);
vma_interval_tree_insert(vma, &mapping->i_mmap);
flush_dcache_mmap_unlock(mapping);
}
/*
* Requires inode->i_mapping->i_mmap_rwsem
*/
static void __remove_shared_vm_struct(struct vm_area_struct *vma,
struct address_space *mapping)
{
if (vma_is_shared_maywrite(vma))
mapping_unmap_writable(mapping);
flush_dcache_mmap_lock(mapping);
vma_interval_tree_remove(vma, &mapping->i_mmap);
flush_dcache_mmap_unlock(mapping);
}
/*
* vma has some anon_vma assigned, and is already inserted on that
* anon_vma's interval trees.
*
* Before updating the vma's vm_start / vm_end / vm_pgoff fields, the
* vma must be removed from the anon_vma's interval trees using
* anon_vma_interval_tree_pre_update_vma().
*
* After the update, the vma will be reinserted using
* anon_vma_interval_tree_post_update_vma().
*
* The entire update must be protected by exclusive mmap_lock and by
* the root anon_vma's mutex.
*/
static void
anon_vma_interval_tree_pre_update_vma(struct vm_area_struct *vma)
{
struct anon_vma_chain *avc;
list_for_each_entry(avc, &vma->anon_vma_chain, same_vma)
anon_vma_interval_tree_remove(avc, &avc->anon_vma->rb_root);
}
static void
anon_vma_interval_tree_post_update_vma(struct vm_area_struct *vma)
{
struct anon_vma_chain *avc;
Annotation
- Immediate include surface: `vma_internal.h`, `vma.h`.
- Detected declarations: `struct mmap_state`, `function vma_is_fork_child`, `function is_mergeable_vma`, `function is_mergeable_anon_vma`, `function init_multi_vma_prep`, `function this`, `function this`, `function __vma_link_file`, `function __remove_shared_vm_struct`, `function anon_vma_interval_tree_pre_update_vma`.
- 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.