What is Virtual memory?
A system in which the OS and hardware map the addresses a program uses (virtual addresses) to physical memory addresses. Each program gets a large, independent address space.
Japanese name: 仮想記憶
A system in which the OS and hardware map the addresses a program uses (virtual addresses) to physical memory addresses. Each program gets a large, independent address space.
Japanese name: 仮想記憶
Memory is divided into fixed-size pages, commonly 4 KB. A virtual address splits into a virtual page number and an offset within the page, 12 bits for 4 KB pages. The memory management unit (MMU) looks up the virtual page number in the page table, which supplies the physical frame number plus permission bits such as present, writable, executable and user-accessible. The offset is copied unchanged. To keep tables compact, they are organized as a tree: x86-64 with 48-bit virtual addresses uses four levels, each indexed by 9 address bits.
Walking a four-level table could cost four memory accesses per load, so the translation lookaside buffer (TLB) caches recent translations and most accesses hit in it. TLBs hold only tens to a few thousand entries, and their reach is entries times page size: about 1000 entries of 4 KB cover only 4 MB. Programs with larger working sets miss often, which is why operating systems offer huge pages, such as 2 MB, that extend the same entries to cover gigabytes. Address-space identifiers let the TLB keep entries from several processes at once.
If an entry is marked not present, the access raises a page fault and the operating system takes over. It may allocate a fresh zeroed page, read the page from a file or swap space, or detect an illegal access and terminate the program with a segmentation fault. This allows demand paging, where pages are loaded only when touched, memory-mapped files, and copy-on-write, where processes share pages until one writes. When the working set far exceeds physical memory, constant swapping, called thrashing, makes the system crawl.
Caches and virtual memory are often confused because both involve memory hierarchy, but their jobs differ. A cache is a hardware-managed copy of recently used data that exists purely for speed and is invisible to software. Virtual memory is a mapping managed by the operating system that gives each process its own address space, enforces protection between processes and the kernel, and lets physical pages be shared, as with common libraries. In everyday usage, virtual memory sometimes refers only to the swap file, which is just one feature it enables.
Answer: B. TLB (translation lookaside buffer)
Virtual memory must translate the virtual addresses programs use into physical addresses, and since page tables live in memory, walking them each time would cost several memory accesses. The TLB caches recent translations. With only tens to thousands of entries, it misses more as working sets grow, so large pages (huge pages, such as 2 MB) are used to extend its reach.
The page table is the complete mapping from virtual to physical pages, stored in memory and maintained by the OS. The TLB is a small hardware cache inside the CPU that holds recently used entries so most translations avoid a table walk.
The CPU stops the faulting instruction and hands control to the operating system, which either maps a valid page, for example by loading it from disk, and retries the instruction, or kills the process if the access was illegal.
Each TLB entry then covers much more memory, so programs with large working sets suffer fewer TLB misses and table walks. Databases and virtual machines commonly use them.
As an Amazon Associate I earn from qualifying purchases.
This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.