Skip to content
IT glossary
ProgrammingUpdated December 3, 2026

Virtual memory

Виртуальная память

Virtual memory gives each running program its own view of memory. The program uses virtual addresses, and the processor and operating system work together to map those addresses to locations in physical memory.

Also known as: страничная память, swap

What problem does it solve?

Two processes can both use the address 0x1000 without sharing any data. The address is meaningful within each process's address space; it is not a location in RAM by itself. The operating system controls what each address refers to and whether the process can read, write, or execute the memory there. It can also deliberately share physical memory, as when several processes use the same read-only library code.

This separation lets a program see a continuous range of addresses even when the underlying memory is scattered across RAM. It also lets the OS set up a range before any physical memory is needed for it.

How address translation works

Most modern systems divide virtual memory into fixed-size chunks called pages and physical memory into page frames. A common page size is 4 KiB. The OS maintains page tables that record mappings and access permissions. The CPU's memory management unit (MMU) translates the virtual page number to a physical frame number and keeps the offset within the page unchanged. A small cache called the translation lookaside buffer (TLB) stores recent translations so the CPU need not consult the page tables for every access.

If the translation is not in the TLB, the CPU can usually find it in the page tables. If the tables say the page is not present or the requested access is disallowed, the CPU raises a page fault and hands control to the kernel. The kernel may resolve the fault and retry the instruction, or report an error if the access is invalid.

Example: allocating a large buffer

Suppose a program on Linux uses mmap to create a 256 MiB anonymous mapping, then writes one byte to the first page. The mapping takes up 256 MiB of virtual address space, but with ordinary demand paging, the first write only needs a frame for the page it touches. That write can trigger a page fault that the kernel resolves by supplying a zero-initialized page. No disk read is needed, and the untouched portion of the buffer need not occupy RAM.

What to look for in production

A process's virtual memory size counts mapped address ranges, while its resident set size (RSS) measures how much of its mapped memory is currently in RAM. RSS includes shared pages, so adding up RSS across processes can count the same physical memory more than once. A large virtual size alone doesn't show how much RAM the process is actually using.

Swap is not another name for virtual memory. It's an optional backing store that can hold evicted pages such as those used by a program's heap. A system without swap still has address translation, protection, and demand paging. For example, it can discard clean file-backed pages and read them from their original files again when needed.

How it comes up in interviews

A common question is: “Does a page fault mean the application crashed or had to read from disk?” Neither is necessarily true. A first write can be handled entirely in RAM, a nonresident file page may need storage I/O, and an invalid address may cause the OS to signal an error. Keep a TLB miss separate: it means the translation wasn't cached, not that the page was absent from RAM.