6: Virtual Memory
- Page ID
- 88899
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)
- 6.1: What Virtual Memory isn't
- Virtual memory is often naively discussed as a way to extended your RAM by using the hard drive as extra, slower, system memory. That is, once your system runs out of memory, it flows over onto the hard drive which is used as "virtual" memory.
- 6.2: What virtual memory is
- Virtual memory is all about making use of address space. The address space of a processor refers the range of possible addresses that it can use when loading and storing to memory. The address space is limited by the width of the registers, since as we know to load an address we need to issue a load instruction with the address to load from stored in a register.
- 6.3: Pages
- The total address-space is divided into individual pages. Pages can be many different sizes; generally they are around 4 KiB, but this is not a hard and fast rule and they can be much larger but generally not any smaller. The page is the smallest unit of memory that the operating system and hardware can deal with.
- 6.4: Physical Memory
- Just as the operating system divides the possible address space up into pages, it divides the available physical memory up into frames. A frame is just the conventional name for a hunk of physical memory the same size as the system page size.
- 6.5: Pages + Frames = Page Tables
- It is the job of the operating system is to keep track of which of virtual-page points to which physical frame. This information is kept in a page-table which, in its simplest form, could simply be a table where each row contains its associated frame — this is termed a linear page-table.
- 6.6: Virtual Addresses
- When a program accesses memory, it does not know or care where the physical memory backing the address is stored. It knows it is up to the operating system and hardware to work together to map locate the right physical address and thus provide access to the data it wants. Thus we term the address a program is using to access memory a virtual address. A virtual address consists of two parts; the page and an offset into that page.
- 6.7: Consequences of virtual addresses, pages and page tables
- Virtual addressing, pages and page-tables are the basis of every modern operating system. It under-pins most of the things we use our systems for.
- 6.8: Hardware Support
- So far, we have only mentioned that hardware works with the operating system to implement virtual memory. However we have glossed over the details of exactly how this happens. Virtual memory is necessarily quite dependent on the hardware architecture, and each architecture has its own subtleties. However, there are are a few universal elements to virtual memory in hardware.
- 6.9: Linux Specifics
- Although the basic concepts of virtual memory remain constant, the specifics of implementations are highly dependent on the operating system and hardware.
- 6.10: Hardware support for virtual memory
- As covered in the section called “The TLB”, the processor hardware provides a lookup-table that links virtual addresses to physical addresses. Each processor architecture defines different ways to manage the TLB with various advantages and disadvantages. The part of the processor that deals with virtual memory is generally referred to as the Memory Management Unit or MMU .