Address space, mappings, page faults và memory accounting

Virtual size không phải physical usage; heap, stacks, files, shared libraries và anonymous/direct mappings cùng tạo process memory footprint.

Virtual Memory

Address space

Per-process virtual addresses map qua page tables đến physical pages hoặc backing storage. Typical regions: executable/text, data/BSS, heap, thread stacks, shared libraries, anonymous/file mmap, VDSO. ASLR randomizes locations; permissions R/W/X enforce protection.

Pages and faults

Demand paging maps/allocates on access. Minor fault không cần disk I/O, major fault cần backing storage; faults bình thường nhưng high major fault/working-set churn gây latency. Huge pages giảm TLB pressure nhưng allocation/fragmentation/GC trade-offs.

Copy-on-write và shared memory

fork/shared mappings reuse pages until write; MAP_SHARED changes visible to peers/backing file, MAP_PRIVATE COW. Shared memory requires synchronization/protocol; process isolation không bảo vệ shared region misuse.

Accounting

VSZ là mapped virtual range; RSS resident pages đếm shared ở mỗi process; PSS chia shared proportionally; USS private resident; dirty/anonymous/file/swap reveal composition. /proc/PID/smaps(_rollup), cgroup memory.stat/current/events và runtime metrics answer different scopes.

Allocation, reclaim và OOM

malloc arenas/caches may retain freed memory; RSS not fall immediately. Kernel page cache is reclaimable, not automatically leak. Overcommit allows reservations beyond immediate physical; allocation/access can fail later. OOM killer chooses task by score within scope; cgroup OOM can kill without runtime exception.

Debugging

Separate heap retained growth, native/direct buffers, stacks/thread count, mmap/file cache, allocator fragmentation and shared pages. Compare after-GC with NMT/smaps/cgroup; capture heap/native evidence before restart only when storage/privacy/safety permit.

proc PID smaps · mmap(2) · Linux Memory Concepts · Linux OOM
← LifecycleThreads →