fs/proc/task_mmu.c
Source file repositories/reference/linux-study-clean/fs/proc/task_mmu.c
File Facts
- System
- Linux kernel
- Corpus path
fs/proc/task_mmu.c- Extension
.c- Size
- 88455 bytes
- Lines
- 3573
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: operation-table or driver-model contract
- Status
- pattern 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 an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- 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/pagewalk.hlinux/mm_inline.hlinux/hugetlb.hlinux/huge_mm.hlinux/mount.hlinux/ksm.hlinux/seq_file.hlinux/highmem.hlinux/ptrace.hlinux/slab.hlinux/pagemap.hlinux/mempolicy.hlinux/rmap.hlinux/swap.hlinux/sched/mm.hlinux/leafops.hlinux/mmu_notifier.hlinux/page_idle.hlinux/shmem_fs.hlinux/uaccess.hlinux/pkeys.hlinux/minmax.hlinux/overflow.hlinux/buildid.hasm/elf.hasm/tlb.hasm/tlbflush.hinternal.h
Detected Declarations
struct mem_size_statsstruct clear_refs_privatestruct pagemapreadstruct pagemap_scan_privatestruct numa_mapsstruct numa_maps_privateenum clear_refs_typesfunction seq_put_decimal_ull_widthfunction task_vsizefunction task_statmfunction get_task_policyfunction release_task_mempolicyfunction hold_task_mempolicyfunction unlock_ctx_mmfunction reset_lock_ctxfunction unlock_ctx_vmafunction lock_vma_rangefunction unlock_vma_rangefunction fallback_to_mmap_lockfunction drop_rcufunction reacquire_rcufunction lock_ctx_mmfunction unlock_ctx_mmfunction lock_vma_rangefunction unlock_vma_rangefunction fallback_to_mmap_lockfunction drop_rcufunction m_stopfunction proc_maps_openfunction proc_map_releasefunction do_maps_openfunction get_vma_namefunction prctlfunction show_vma_header_prefixfunction show_map_vmafunction show_mapfunction pid_maps_openfunction query_vma_setupfunction query_vma_teardownfunction query_vma_setupfunction query_vma_teardownfunction do_procmap_queryfunction procfs_procmap_ioctlfunction smaps_page_accumulatefunction smaps_accountfunction smaps_pte_holefunction smaps_pte_hole_lookupfunction smaps_pte_entry
Annotated Snippet
const struct file_operations proc_pid_maps_operations = {
.open = pid_maps_open,
.read = seq_read,
.llseek = seq_lseek,
.release = proc_map_release,
.unlocked_ioctl = procfs_procmap_ioctl,
.compat_ioctl = compat_ptr_ioctl,
};
/*
* Proportional Set Size(PSS): my share of RSS.
*
* PSS of a process is the count of pages it has in memory, where each
* page is divided by the number of processes sharing it. So if a
* process has 1000 pages all to itself, and 1000 shared with one other
* process, its PSS will be 1500.
*
* To keep (accumulated) division errors low, we adopt a 64bit
* fixed-point pss counter to minimize division errors. So (pss >>
* PSS_SHIFT) would be the real byte count.
*
* A shift of 12 before division means (assuming 4K page size):
* - 1M 3-user-pages add up to 8KB errors;
* - supports mapcount up to 2^24, or 16M;
* - supports PSS up to 2^52 bytes, or 4PB.
*/
#define PSS_SHIFT 12
#ifdef CONFIG_PROC_PAGE_MONITOR
struct mem_size_stats {
unsigned long resident;
unsigned long shared_clean;
unsigned long shared_dirty;
unsigned long private_clean;
unsigned long private_dirty;
unsigned long referenced;
unsigned long anonymous;
unsigned long lazyfree;
unsigned long anonymous_thp;
unsigned long shmem_thp;
unsigned long file_thp;
unsigned long swap;
unsigned long shared_hugetlb;
unsigned long private_hugetlb;
unsigned long ksm;
u64 pss;
u64 pss_anon;
u64 pss_file;
u64 pss_shmem;
u64 pss_dirty;
u64 pss_locked;
u64 swap_pss;
};
static void smaps_page_accumulate(struct mem_size_stats *mss,
struct folio *folio, unsigned long size, unsigned long pss,
bool dirty, bool locked, bool private)
{
mss->pss += pss;
if (folio_test_anon(folio))
mss->pss_anon += pss;
else if (folio_test_swapbacked(folio))
mss->pss_shmem += pss;
else
mss->pss_file += pss;
if (locked)
mss->pss_locked += pss;
if (dirty || folio_test_dirty(folio)) {
mss->pss_dirty += pss;
if (private)
mss->private_dirty += size;
else
mss->shared_dirty += size;
} else {
if (private)
mss->private_clean += size;
else
mss->shared_clean += size;
}
}
static void smaps_account(struct mem_size_stats *mss, struct page *page,
bool compound, bool young, bool dirty, bool locked,
bool present)
{
struct folio *folio = page_folio(page);
int i, nr = compound ? compound_nr(page) : 1;
Annotation
- Immediate include surface: `linux/pagewalk.h`, `linux/mm_inline.h`, `linux/hugetlb.h`, `linux/huge_mm.h`, `linux/mount.h`, `linux/ksm.h`, `linux/seq_file.h`, `linux/highmem.h`.
- Detected declarations: `struct mem_size_stats`, `struct clear_refs_private`, `struct pagemapread`, `struct pagemap_scan_private`, `struct numa_maps`, `struct numa_maps_private`, `enum clear_refs_types`, `function seq_put_decimal_ull_width`, `function task_vsize`, `function task_statm`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: pattern 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.