gemini-2.5-pro| input-price: 1.25 output-price: 10 max-context-length: 200_000 (cost: $0.03) Β· Anfrage: 2025-11-04T09:53:09.333121
Generated by rs-summarizer Version unbekannt
Abstract:
This article provides a comprehensive tour of process memory management on Linux, demystifying how the operating system creates the illusion of a simple, contiguous address space for applications. It explains the fundamental concepts of virtual memory, including the distinction between virtual addresses and physical RAM frames, the role of page tables for translation, and the structure of a process's address space as a collection of Virtual Memory Areas (VMAs).
The author details the lazy allocation mechanism, where physical memory is only assigned on the "first touch" via a page fault. Key related concepts like copy-on-write (CoW) for fork() and MAP_PRIVATE mappings are explained through this lens. The article also covers memory permissions (mprotect), the performance implications of Transparent Huge Pages (THP), and the security-driven architecture of Page Table Isolation (PTI) used to mitigate the Meltdown vulnerability. Finally, it offers practical guidance on how to inspect a process's memory layout using the /proc filesystem and troubleshoot common memory-related errors.
A Guided Tour of Linux Process Memory
Intro: The Floor Plan You Never See
mmap, mprotect, and munmap are used to manipulate these VMAs. Physical memory is not allocated until it is first accessed.mmap: Drawing a Promise
mmap system call doesn't allocate physical memory. It only reserves a virtual address range and records a "promise" to provide memory when needed.MAP_SHARED mappings write changes back to the source file, while MAP_PRIVATE mappings create a private copy on the first write.The First Touch: Lazy Allocation in Action
SIGSEGV signal (segmentation fault).Copy on Write (CoW): Efficient Forking
fork(), the child process doesn't get a full copy of the parent's memory. Instead, they share the same physical pages, which are temporarily marked as read-only.Seeing What's Mapped: The /proc Filesystem
/proc filesystem./proc/<pid>/maps: Shows the address ranges, permissions, and backing files for all VMAs./proc/<pid>/smaps: Provides detailed memory accounting per VMA, including Resident Set Size (RSS), private vs. shared pages, and huge page usage./proc/<pid>/pagemap: An advanced tool (requiring privileges) that provides per-page information, including whether a page is in RAM and its physical address (Page Frame Number).Transparent Huge Pages (THP): Gaining Performance
khugepaged, can merge smaller pages into huge pages. Usage can be monitored via the AnonHugePages field in /proc/<pid>/smaps.Meltdown: A Tale of Two Page Tables
Troubleshooting Common Issues
mmap returning EINVAL: Often caused by a file offset that is not page-aligned.SIGBUS: Typically happens when accessing a file mapping beyond the actual end of the file.fork(): This is the expected result of copy-on-write as the processes modify their shared memory.