Multilevel, inverted and hashed page tables
Why a flat page table is too big and how to shrink it: hierarchical (multilevel) tables with the address bits split by level, how many levels are needed, the memory they save, hashed page tables for sparse large address spaces, and the inverted page table that has one entry per frame.
Why it exists
A flat page table has one entry for every page of the whole logical address space, whether the process uses it or not. For 32-bit addresses with 4 KB pages that is entries, about 4 MB per process; for 64-bit addresses the table would be larger than any memory. Most processes use only a small, scattered part of their address space (a little code and data at the bottom, a stack at the top), so most of the table would be empty. Three structures avoid storing it all: hierarchical (multilevel) tables, hashed tables and inverted tables. GATE asks for the number of levels, the bit split of the address, the size of the tables for a given process, and the number of memory accesses per translation.
Prerequisites
You need the page, frame, offset and page-table calculations of paging.
Precise definitions
Hierarchical (multilevel) paging. The page table itself is paged. The page number is split into several parts: an index into the outer (top-level) table, which points to an inner table, which holds (or points to the next level of tables that finally hold) the frame number. Inner tables are created only for the parts of the address space the process uses, so unused regions need no table.
For a two-level scheme the logical address is
Translation: use to find the inner table in the outer table, use to find the frame in the inner table, then form . Because the address is translated from the outside in, the scheme is also called a forward-mapped page table.
Choosing the bit split. Make every table fit exactly in one page (so tables can be allocated and swapped like any other page). With page size bytes and page-table entries of bytes, a table holds entries, so each level uses
With -bit logical addresses the page number has bits, so the number of levels is
If the bits do not divide exactly, the top level uses the remainder (it is smaller than a page). Examples: , 4 KB pages, 4-byte entries: , levels , split 10 + 10 + 12. , 4 KB pages, 8-byte entries: , levels ; with 48-bit addresses (the usual four-level scheme). : levels, the top one with bits.
Memory references. With a -level table and no TLB each reference costs memory accesses ( table lookups and the data). The TLB caches the final translation to avoid most of them.
Size of the tables. A flat table has entries. A multilevel table needs the outer table plus one inner table for each region of the address space (one inner table covers pages) that contains at least one used page. A process using a contiguous part of pages needs inner tables.
Hashed page tables (for address spaces larger than 32 bits). The virtual page number is hashed into a table; each entry is a chain of elements (virtual page number, frame number, pointer to the next). Translation hashes the page number, walks the chain comparing page numbers, and takes the frame of the matching element. Sparse address spaces cost only as many elements as there are mapped pages. Clustered page tables put several consecutive pages in one element.
Inverted page table. One table for the whole system, with one entry per physical frame: the entry for frame holds the process id and the page number currently stored in it. Translating means searching the table for the entry ; the position of the matching entry is the frame number, and the physical address is . A hash on speeds the search. Its size follows the physical memory (frames entry size), not the logical address spaces or the number of processes. The disadvantages: the lookup is a search; shared pages are awkward (a frame has one ); and it cannot say where a page is on disk (a separate per-process table is needed for pages that are not in memory).
Comparison.
| Structure | Size | Lookup | Strength |
|---|---|---|---|
| flat | entries per process | 1 access | simplest; too big |
| multilevel | grows with the used regions | accesses | no table for unused regions; standard |
| hashed | proportional to the mapped pages | hash and chain walk | sparse 64-bit address spaces |
| inverted | one entry per frame, whole system | hash and search | small; size independent of processes |
How it works
The first animation is a two-level translation in a toy 12-bit address space: page size 64 bytes (6-bit offset), a 6-bit page number split into 3 + 3 bits. The outer table has 8 entries; only three inner tables exist (for ); the other five outer entries are empty. A flat table would need 64 entries; this structure stores . Two addresses fault: one finds an empty outer entry (no inner table at all), the other an invalid inner entry.
Two-level page table: start
Translation computed, not typed| p1 | inner table |
|---|---|
| 0 | T0 |
| 1 | - |
| 2 | T1 |
| 3 | - |
| 4 | - |
| 5 | T2 |
| 6 | - |
| 7 | - |
| p2 | frame |
|---|---|
| 0 | - |
| 1 | 10 |
| 2 | 11 |
| 3 | - |
| 4 | - |
| 5 | - |
| 6 | 40 |
| 7 | - |
| p2 | frame |
|---|---|
| 0 | - |
| 1 | - |
| 2 | - |
| 3 | 21 |
| 4 | 22 |
| 5 | - |
| 6 | - |
| 7 | 5 |
| p2 | frame |
|---|---|
| 0 | 33 |
| 1 | - |
| 2 | - |
| 3 | - |
| 4 | - |
| 5 | - |
| 6 | - |
| 7 | 8 |
No address yet.
Step 0
Two-level paging in a toy 12-bit address space: page size 64 bytes (6-bit offset), so a 6-bit page number, which is split again into a 3-bit OUTER index p1 and a 3-bit INNER index p2. Instead of one table with 64 entries, there is one outer table (8 entries) and one small inner table for each used region. Only 3 inner tables exist here, so only 8 + 3 x 8 = 32 entries are stored instead of 64; unused regions need no inner table at all.
The second animation is an inverted page table for a memory of 8 frames. The table is searched for the entry ; its position is the frame number.
Inverted page table: start
Translation computed, not typed| frame | pid | page |
|---|---|---|
| 0 | 3 | 12 |
| 1 | 1 | 4 |
| 2 | 2 | 7 |
| 3 | 1 | 9 |
| 4 | 2 | 3 |
| 5 | 3 | 2 |
| 6 | 1 | 0 |
| 7 | 2 | 15 |
No address yet.
Step 0
An inverted page table has one entry for each physical FRAME (8 here), holding the process id and page number that occupy it, instead of one table per process. Translation SEARCHES the table for the entry (pid, page); the position of the match is the frame number. The page size is 256 bytes (8-bit offset). The table is small (its size follows the physical memory) but a lookup is a search, so real systems hash on (pid, page).
Worked examples
EX 1A two-level translation by hand
EasyLogical address 1233 in the toy space. In binary it is 010 011 010001: , , . The outer table entry 2 points to inner table T1. Entry 3 of T1 is frame 21. Physical address . Two table accesses and one data access. Address 1545 (p1 = 3) hits an empty outer entry: fault; address 1409 (p1 = 2, p2 = 6) finds an invalid inner entry: fault.
EX 2Do the nested tables really equal the flat table?
MediumA program builds both for the toy space, maps eight pages, and compares the translation of every one of the 4096 addresses; it also computes the table sizes and the level counts for real address widths.
#include <stdio.h>
#include <string.h>
/* a flat page table and a two-level one for a toy 12-bit address space: page size 64 (6-bit offset), 3 + 3 bits of page number */
static int flat[64];
static int outer[8]; /* index of the inner table, or -1 */
static int inner[8][8]; /* frame or -1 */
static int levels(int va_bits, int page, int entry) {
int offset = 0, per_table = page / entry, level_bits = 0;
while ((1 << offset) < page) offset++;
while ((1 << level_bits) < per_table) level_bits++;
return (va_bits - offset + level_bits - 1) / level_bits;
}
int main(void) {
memset(flat, -1, sizeof flat);
memset(outer, -1, sizeof outer);
memset(inner, -1, sizeof inner);
int mapped[8][2] = {{1, 10}, {2, 11}, {6, 40}, {19, 21}, {20, 22}, {23, 5}, {40, 33}, {47, 8}}; /* page -> frame */
int next_inner = 0;
for (int i = 0; i < 8; i++) {
int p = mapped[i][0], f = mapped[i][1];
flat[p] = f;
if (outer[p >> 3] < 0) outer[p >> 3] = next_inner++;
inner[outer[p >> 3]][p & 7] = f;
}
int agree = 0;
for (int L = 0; L < 4096; L++) {
int p = L >> 6, d = L & 63;
int a = flat[p] < 0 ? -1 : flat[p] * 64 + d;
int t = outer[p >> 3];
int f = t < 0 ? -1 : inner[t][p & 7];
int b = f < 0 ? -1 : f * 64 + d;
agree += a == b;
}
printf("flat table and two-level table agree on %d of 4096 addresses\n", agree);
printf("entries stored: flat 64, two-level 8 + %d x 8 = %d\n", next_inner, 8 + next_inner * 8);
printf("32-bit, 4 KB pages, 4-byte entries: %d levels, flat table %d KB\n", levels(32, 4096, 4), (1 << 20) * 4 / 1024);
int used_pages = 12 * 1024 * 1024 / 4096, per = 1024;
int inner_tables = (used_pages + per - 1) / per;
printf("a 12 MB process: %d pages, %d inner tables, %d KB of tables in all\n", used_pages, inner_tables, (1 + inner_tables) * 4);
printf("64-bit, 4 KB pages, 8-byte entries: %d levels; with 48-bit addresses: %d levels\n", levels(64, 4096, 8), levels(48, 4096, 8));
return 0;
}flat table and two-level table agree on 4096 of 4096 addresses
entries stored: flat 64, two-level 8 + 3 x 8 = 32
32-bit, 4 KB pages, 4-byte entries: 2 levels, flat table 4096 KB
a 12 MB process: 3072 pages, 3 inner tables, 16 KB of tables in all
64-bit, 4 KB pages, 8-byte entries: 6 levels; with 48-bit addresses: 4 levelsReading it. The two structures translate every address the same way, but the nested one stores half as many entries here. For a real process of 12 MB with 32-bit addresses: 3072 pages fill 3 inner tables (each covers pages = 4 MB), so the tables take pages = 16 KB, against 4 MB for the flat table. For 64-bit addresses with 8-byte entries 9 bits fit in a page-sized table, so a full 64-bit space needs levels; hardware with 48-bit addresses uses 4.
EX 3Splitting the address bits
MediumA system has 38-bit logical addresses, 4 KB pages and 8-byte page-table entries. A table that fits one page holds entries, so each level takes 9 bits. The page number has bits, so levels: the lowest two levels use 9 bits each and the top level uses the remaining 8 bits (256 entries, half a page). The address is split . Memory accesses per reference without a TLB: . If instead the table sizes were not tied to the page size, the split could be anything that adds up to 26; a question states what it requires.
EX 4The inverted table
MediumA machine has 1 GB of memory, 4 KB frames and an inverted table entry of 8 bytes. Frames: . Table size: MB, for the whole system, however many processes there are or how large their address spaces. Contrast: one flat table per process for 32-bit addresses is 4 MB each, so with 10 processes 40 MB. The price is the search: on average half the table (131072 entries) unless a hash on (pid, page) is used. In the second animation, the entry is found at position 3 after 4 comparisons and the physical address is .
EX 5Compare the structures
GATE levelWhich scheme's size depends on the physical memory rather than the logical address space? Inverted. Which can avoid allocating tables for unused regions? Multilevel (and hashed). Which is searched by hashing the page number? Hashed and (in practice) inverted. Which requires accesses per reference without a TLB? A -level table. Why is a flat table impossible for 64-bit addresses? It would need entries (with 4 KB pages), which is bytes petabytes per process. What is the drawback of the inverted table for sharing? A frame can hold only one (pid, page) pair, so a page shared by two processes cannot be represented simply.
Cheat box
Cheat box
- Flat table: entries per process (4 MB for 32-bit, 4 KB pages, 4-byte entries). Too big, mostly empty.
- Multilevel: each table fits one page; bits per level ; levels ; the top level takes the remainder bits.
- levels: memory accesses per reference without a TLB. Inner tables only where pages are used.
- Hashed: hash the virtual page number, chain of (page, frame, next); for sparse large spaces.
- Inverted: one entry per FRAME for the whole system; search ; position frame; size frames entry; hard to share pages.
- 32-bit, 4 KB: 10 + 10 + 12. 64-bit, 8-byte entries: 9 bits per level.
Traps and GATE patterns
Connections
Builds on
Across subjects
All of these refine the single table of paging. The extra accesses they cost are why a TLB is essential, and the valid bit in each entry is what virtual memory uses to mean "not in memory". A segment can have its own page table, giving segmentation with paging. A hashed lookup resembles a cache index: a short key chooses where to look.
PYQs
10 previous year questions from your book. I re-solved each one myself (8 by running or simulating, 2 by reasoning only); the book's key is shown next to my answer. All PYQs
A computer system supports a logical address space of 232bytes. It uses two-level hierarchical paging with a page size of 4096 bytes. A logical address is divided into a b-bit index to the outer page table, an offset within the page of the inner page table, and an offset within the desired page. Each entry of the inner page table uses eight bytes. All the pages in the system have the same size.The value of b is ______.
Consider a 32-bit system with 4 KB page size and page table entries of size 4 bytes each. Assume 1 KB = 210 bytes. The OS uses a 2-level page table for memory management, with the page table containing an outer page directory and an inner page table. The OS allocates a page for the outer page directory upon process creation. The OS uses demand paging when allocating memory for the inner page table, i.e., a page of the inner page table is allocated only if it contains at least one valid page table entry. An active process in this system accesses 2000 unique pages during its execution, and none of the pages are swapped out to disk. After it completes the page accesses, let X denote the minimum and Y denote the maximum number of pages across the two levels of the page table of the process. The value of X + Y is _____
Consider a computer system with 57-bit virtual addressing using multi-level tree-structured page tables with L levels for virtual to physical address translation. The page size is 4 KB (1 KB = 1024 B) and a page table entry at any of the levels occupies 8 bytes.The value of L is.........
Which one of the following statements is FALSE?
- (a)The TLB performs an associative search in parallel on all its valid entries using page number of incoming virtual address.
- (b)If the virtual address of a word given by CPU has a TLB hit, but the subsequent search for the word results in a cache miss, then the word will always be present in the main memory.
- (c)The memory access time using a given inverted page table is always same for all incoming virtual addresses.
- (d)In a system that uses hashed page tables, if two distinct virtual ddresses V1 and V2 map to the same value while hashing, then the memory access time of these addresses will not be the same.
Consider a three-level page table to translate a 39-bit virtual address to a physical address as shown below. The page size is 4KB (1KB = 210 bytes) and page table entry size at every level is 8 bytes. A process P is currently using 2GB (1GB = 230 bytes) virtual memory which is mapped to 2GB of physical memory. The minimum amount of memory required for the page table of P across all levels is _______ KB OPERATING SYSTEMS
Consider a computer system with 40-bit virtual addressing and page size of sixteen kilobytes. If the computer system has a one-level page table per process and each page table entry requires 48 bits, then the size of the per-process page table is __________ megabytes.
A computer system implements 8 kilobyte pages and a 32-bit physical address space. Each page table entry contains a valid bit, a dirty bit, three permission bits, and the translation. If the maximum size of the page table of a process is 24 megabytes, the length of the virtual address supported by the system is ________ bits.
A computer uses 46-bit virtual address, 32-bit physical address, and a three-level paged page table organization. The page table base register stores the base address of the first-level table (T1), which occupies exactly one page. Each entry of T1 stores the base address of a page of the second-level table (T2). Each entry of T2 stores the base address of a page of the third-level table (T3). Each entry of T3 stores a page table entry (PTE). The PTE is 32 bits in size. The processor used in the computer has a 1 MB 16- way set associative virtually indexed physically tagged cache. The cache block size is 64 bytes. What is the minimum number of page colors needed to guarantee that no two synonyms map to different sets in the processor cache of this computer?
- (a)2
- (b)4
- (c)8
- (d)16
A multilevel page table is preferred in comparison to a single level page table for translating virtual address to physical address because
- (a)it reduces the memory access time to read or write a memory location.
- (b)It helps to reduce the size of the page table needed to implement the virtual address space of a process.
- (c)it is required by the translation lookaside buffer.
- (d)it helps to reduce the number of page faults in page replacement algorithms
A processor uses: Physical address = 36 bits Virtual address = 32 bits Page size = 4 KB PTE size = 4 bytes Three-level page table with: ● bits 30–31 → 1st level index ● bits 21–29 → 2nd level index ● bits 12–20 → 3rd level index ● bits 0–11 → offset Find number of bits required in PTE to address the next level page table (or page frame) at first, second, and third levels respectively.
- (a)20, 20 and 20
- (b)24, 24 and 24
- (c)24, 24 and 20
- (d)25, 25 and 24 OPERATING SYSTEMS
Self-check
Question 1
32-bit logical addresses, 8 KB pages, 4-byte entries. How many bits per level and how many levels?
Show answerHide
Offset 13 bits; entries per table , so . Page number bits; levels, with 8 bits at the top and 11 at the second level.
Question 2
A process uses 6 MB of contiguous memory, 32-bit addresses, 4 KB pages, 4-byte entries, two levels. How much memory do its page tables take?
Show answerHide
6 MB pages; each inner table covers 1024 pages, so inner tables. Total tables of 4 KB KB.
Question 3
An inverted page table: 512 MB of memory, 4 KB frames, 8-byte entries. Table size?
Show answerHide
Frames ; size MB.
Question 4
With a three-level page table and no TLB, how many memory accesses does one data reference need?
Show answerHide
Three table accesses and one data access: 4.
Revision card
One-screen revision
- Flat table too big. Multilevel: tables page-sized, bits per level, levels , accesses.
- Hashed: chains keyed by page number. Inverted: one entry per frame, search (pid, page), frame = position.
- 32-bit/4 KB/4 B: 10 + 10 + 12; table of a 12 MB process: 16 KB vs 4 MB.
References
- ·Silberschatz, Galvin, Gagne, Operating System Concepts, Chapter 9 Main Memory (structure of the page table: hierarchical paging, hashed page tables, inverted page tables)
- ·Tanenbaum and Bos, Modern Operating Systems, Chapter 3 Memory Management (multilevel page tables, inverted page tables)
- ·Hennessy and Patterson, Computer Organization and Design, Chapter 5 (virtual memory: page tables)
Verification
The two-level and inverted translations in the animations are computed by a script (scripts/gen-os-mem-traces.py) and rechecked by tests/os-mem-traces.test.ts. scripts/enum-checks/os_mem.py checks on 300 random sparse mappings that the nested tables give exactly the translation of a flat table for every address, and that an inverted table lookup returns the same frame as the per-process tables; the C program on this page (npm run verify:c) builds a flat and a two-level table and compares them on all 4096 addresses of the toy space. The level counts and sizes (32-bit addresses with 4 KB pages and 4-byte entries: 2 levels, 4 MB flat against 16 KB for a 12 MB process; 64-bit addresses with 8-byte entries: 6 levels, 4 levels for 48 bits; 38-bit addresses: 3 levels with 8 bits at the top) are exact arithmetic checked in Python and C. Hashed tables are described but not simulated; real inverted tables hash on (pid, page) to avoid a linear search. Textbook chapter titles are from memory. SECOND PASS (2026-11-02, done by the assistant, not a human check): every Self-check question was solved before the printed answer was read and all agreed; the definitions, worked examples, cheat box and traps were read claim by claim and the numbers re-derived by hand. No defect found. Status raised to self-checked; verified needs a textbook or human check.
last verified: never
My notes (saved in this browser)