mm/nommu.c
Source file repositories/reference/linux-study-clean/mm/nommu.c
File Facts
- System
- Linux kernel
- Corpus path
mm/nommu.c- Extension
.c- Size
- 47551 bytes
- Lines
- 1904
- Domain
- Core OS
- Bucket
- Memory Management
- Inferred role
- Core OS: syscall or user/kernel boundary
- Status
- core 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.
- Defines or participates in a user/kernel boundary; inspect argument validation, copy_from_user/copy_to_user, credentials, and dispatch target.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/export.hlinux/mm.hlinux/sched/mm.hlinux/mman.hlinux/swap.hlinux/file.hlinux/highmem.hlinux/pagemap.hlinux/slab.hlinux/vmalloc.hlinux/backing-dev.hlinux/compiler.hlinux/mount.hlinux/personality.hlinux/security.hlinux/syscalls.hlinux/audit.hlinux/printk.hlinux/uaccess.hlinux/uio.hasm/tlb.hasm/tlbflush.hasm/mmu_context.hinternal.h
Detected Declarations
syscall brksyscall mmap_pgoffsyscall old_mmapsyscall munmapsyscall mremapstruct mmap_arg_structfunction kobjsizefunction vfreefunction vmalloc_to_pfnfunction vread_iterfunction __vmallocfunction __vmallocfunction __vmallocfunction __vmallocfunction remap_vmalloc_rangefunction vunmapfunction vm_unmap_ramfunction vm_unmap_aliasesfunction free_vm_areafunction vm_insert_pagefunction vm_insert_pagesfunction vm_map_pagesfunction vm_map_pages_zerofunction sys_brkfunction mmap_initfunction validate_nommu_regionsfunction validate_nommu_regionsfunction delete_nommu_regionfunction free_page_seriesfunction __put_nommu_regionfunction put_nommu_regionfunction setup_vma_to_mmfunction cleanup_vma_from_mmfunction delete_vma_from_mmfunction delete_vmafunction expand_stack_lockedfunction validate_mmap_requestfunction determine_vm_flagsfunction filefunction do_mmap_privatefunction do_mmapfunction mmapfunction ksys_mmap_pgofffunction split_vmafunction vmi_shrink_vmafunction do_munmapfunction vm_munmapfunction exit_mmap
Annotated Snippet
SYSCALL_DEFINE1(brk, unsigned long, brk)
{
struct mm_struct *mm = current->mm;
if (brk < mm->start_brk || brk > mm->context.end_brk)
return mm->brk;
if (mm->brk == brk)
return mm->brk;
/*
* Always allow shrinking brk
*/
if (brk <= mm->brk) {
mm->brk = brk;
return brk;
}
/*
* Ok, looks good - let it rip.
*/
flush_icache_user_range(mm->brk, brk);
return mm->brk = brk;
}
static int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
static const struct ctl_table nommu_table[] = {
{
.procname = "nr_trim_pages",
.data = &sysctl_nr_trim_pages,
.maxlen = sizeof(sysctl_nr_trim_pages),
.mode = 0644,
.proc_handler = proc_dointvec_minmax,
.extra1 = SYSCTL_ZERO,
},
};
/*
* initialise the percpu counter for VM and region record slabs, initialise VMA
* state.
*/
void __init mmap_init(void)
{
int ret;
ret = percpu_counter_init(&vm_committed_as, 0, GFP_KERNEL);
VM_BUG_ON(ret);
vm_region_jar = KMEM_CACHE(vm_region, SLAB_PANIC|SLAB_ACCOUNT);
register_sysctl_init("vm", nommu_table);
vma_state_init();
}
/*
* validate the region tree
* - the caller must hold the region lock
*/
#ifdef CONFIG_DEBUG_NOMMU_REGIONS
static noinline void validate_nommu_regions(void)
{
struct vm_region *region, *last;
struct rb_node *p, *lastp;
lastp = rb_first(&nommu_region_tree);
if (!lastp)
return;
last = rb_entry(lastp, struct vm_region, vm_rb);
BUG_ON(last->vm_end <= last->vm_start);
BUG_ON(last->vm_top < last->vm_end);
while ((p = rb_next(lastp))) {
region = rb_entry(p, struct vm_region, vm_rb);
last = rb_entry(lastp, struct vm_region, vm_rb);
BUG_ON(region->vm_end <= region->vm_start);
BUG_ON(region->vm_top < region->vm_end);
BUG_ON(region->vm_start < last->vm_top);
lastp = p;
}
}
#else
static void validate_nommu_regions(void)
{
}
#endif
/*
* add a region into the global tree
Annotation
- Immediate include surface: `linux/export.h`, `linux/mm.h`, `linux/sched/mm.h`, `linux/mman.h`, `linux/swap.h`, `linux/file.h`, `linux/highmem.h`, `linux/pagemap.h`.
- Detected declarations: `syscall brk`, `syscall mmap_pgoff`, `syscall old_mmap`, `syscall munmap`, `syscall mremap`, `struct mmap_arg_struct`, `function kobjsize`, `function vfree`, `function vmalloc_to_pfn`, `function vread_iter`.
- Atlas domain: Core OS / Memory Management.
- Implementation status: core implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.