Virtual Memory
Giving every process its own private address space that the kernel maps onto physical memory page by page, on demand.
Virtual memory gives every Process its own private address space, which the kernel maps onto physical memory in fixed-size pages (usually 4 KB) through per-process page tables. A process sees one contiguous range of addresses. Behind it, the pages may sit anywhere in RAM, may be shared with other processes, may live on disk in Swap, or may not exist at all yet.
Most of a modern operating system's memory behavior follows from that indirection:
- Isolation. One process cannot address another's memory, because its page table has no entry for it. A stray pointer causes a fault rather than silent corruption elsewhere.
- Lazy allocation. Asking for memory reserves address space, not RAM. A page is backed by physical memory only when first touched, through a page fault the kernel handles invisibly. This is Lazy Evaluation at the hardware level.
- Sharing. Libraries, and a forked child's pages, map to the same physical frames until someone writes, which is Copy-on-Write.
- The page cache. File contents read from disk stay in otherwise unused RAM. That is why a healthy Linux machine shows almost no "free" memory: free RAM is wasted RAM, and the cache gives way when processes need the space.
The consequence that surprises people is overcommit. Since allocation reserves only address space, the kernel lets processes collectively allocate more than exists, betting that much of it will never be touched. The bet usually wins. When it loses, there is no allocation call left to fail gracefully, because the allocation succeeded long ago and the failure arrives at the moment a page is touched. The kernel's only recourse is the Out-of-Memory Killer. It also means "how much memory does this process use" has several honest answers (virtual size, resident set, proportional share of shared pages) and they can differ by orders of magnitude.
The same design appears wherever a fixed pool has to be shared among variable demands. Inference engines page a model's KV Cache into fixed blocks for exactly the reasons the kernel pages RAM: no fragmentation, and allocation on demand.
See also3
Inter-Process Communication
The channels separate processes use to exchange data and signals, from pipes and sockets to shared memory, a necessity because each process is walled off in its own memory and a frequent route for sandbox escapes.
Systems & Tooling13 connections
Pressure Stall Information
A kernel metric for how much time work spent waiting on CPU, memory, or I/O, which measures contention directly where utilization figures only hint at it.
Systems & Tooling13 connections
System Call
The doorway through which a program asks the operating system kernel to do anything privileged, from reading a file to starting a process.
Systems & Tooling16 connections
Linked from9
- Dynamic LinkingSystems & Tooling
Loading a program's libraries at run time from shared files instead of copying them into the executable, which saves space and eases patching at the cost of fragile dependencies.
- Dynamic Random-Access MemorySystems & Tooling
The main memory of nearly every computer, which stores each bit as charge in a tiny capacitor that leaks and must be refreshed many times a second, making it cheap and dense but slow next to the processor.
- Inter-Process CommunicationSystems & Tooling
The channels separate processes use to exchange data and signals, from pipes and sockets to shared memory, a necessity because each process is walled off in its own memory and a frequent route for sandbox escapes.
- KernelSystems & Tooling
The core of an operating system that runs with full hardware privileges, managing processes, memory, devices, and files on behalf of every other program.
- KV CacheAgents & Language Models
The stored attention keys and values for every token already processed, which lets a model generate each new token without re-reading the whole sequence.
- Out-of-Memory KillerSystems & Tooling
The kernel's last resort when memory is exhausted, killing a process chosen by heuristic, and the userspace daemons that act earlier with better judgment.
- Page CacheSystems & Tooling
The operating system's use of spare memory to hold recently read and written file data, which makes repeated disk access fast and makes "free memory" look alarmingly low.
- SwapSystems & Tooling
Somewhere to put memory pages that are not being used, so RAM can go to pages that are, whether that place is a disk or a compressed region of RAM itself.
- System CallSystems & Tooling
The doorway through which a program asks the operating system kernel to do anything privileged, from reading a file to starting a process.