G27
Self-checkedTier 1 14 min reados.page-table-structures

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 2202^{20} 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

p1⏟outer indexp2⏟inner indexd⏟offset\underbrace{p_1}_{\text{outer index}} \quad \underbrace{p_2}_{\text{inner index}} \quad \underbrace{d}_{\text{offset}}

Translation: use p1p_1 to find the inner table in the outer table, use p2p_2 to find the frame in the inner table, then form f⋅2n+df \cdot 2^n + d. 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 2n2^n bytes and page-table entries of ee bytes, a table holds 2n/e2^n/e entries, so each level uses

b=log⁡2(2n/e) bits of the address.b = \log_2 (2^n / e) \text{ bits of the address.}

With mm-bit logical addresses the page number has m−nm - n bits, so the number of levels is

levels=⌈m−nb⌉.\text{levels} = \left\lceil \frac{m - n}{b} \right\rceil.

If the bits do not divide exactly, the top level uses the remainder (it is smaller than a page). Examples: m=32m = 32, 4 KB pages, 4-byte entries: b=10b = 10, levels =⌈20/10⌉=2= \lceil 20/10 \rceil = 2, split 10 + 10 + 12. m=64m = 64, 4 KB pages, 8-byte entries: b=9b = 9, levels =⌈52/9⌉=6= \lceil 52/9 \rceil = 6; with 48-bit addresses ⌈36/9⌉=4\lceil 36/9 \rceil = 4 (the usual four-level scheme). m=38m = 38: ⌈26/9⌉=3\lceil 26/9 \rceil = 3 levels, the top one with 26−18=826 - 18 = 8 bits.

Memory references. With a kk-level table and no TLB each reference costs k+1k + 1 memory accesses (kk table lookups and the data). The TLB caches the final translation to avoid most of them.

Size of the tables. A flat table has 2m−n2^{m-n} entries. A multilevel table needs the outer table plus one inner table for each region of the address space (one inner table covers 2b2^{b} pages) that contains at least one used page. A process using a contiguous part of UU pages needs ⌈U/2b⌉\lceil U/2^b \rceil 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 ii holds the process id and the page number currently stored in it. Translating (pid,p,d)(\text{pid}, p, d) means searching the table for the entry (pid,p)(\text{pid}, p); the position ii of the matching entry is the frame number, and the physical address is i⋅2n+di \cdot 2^n + d. A hash on (pid,p)(\text{pid}, p) speeds the search. Its size follows the physical memory (frames ×\times 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 (pid,page)(\text{pid}, \text{page})); 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.

StructureSizeLookupStrength
flat2m−n2^{m-n} entries per process1 accesssimplest; too big
multilevelgrows with the used regionskk accessesno table for unused regions; standard
hashedproportional to the mapped pageshash and chain walksparse 64-bit address spaces
invertedone entry per frame, whole systemhash and searchsmall; 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 p1=0,2,5p_1 = 0, 2, 5); the other five outer entries are empty. A flat table would need 64 entries; this structure stores 8+3×8=328 + 3 \times 8 = 32. 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
outer page table (8 entries)
p1inner table
0T0
1-
2T1
3-
4-
5T2
6-
7-
inner table T0 (for p1 = 0)
p2frame
0-
110
211
3-
4-
5-
640
7-
inner table T1 (for p1 = 2)
p2frame
0-
1-
2-
321
422
5-
6-
75
inner table T2 (for p1 = 5)
p2frame
033
1-
2-
3-
4-
5-
6-
78

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.

0 / 14
computed by script: the algorithm or the translation is executed, one event per step. python3 scripts/gen-os-mem-traces.py

The second animation is an inverted page table for a memory of 8 frames. The table is searched for the entry (pid,page)(\text{pid}, \text{page}); its position is the frame number.

Inverted page table: start

Translation computed, not typed
inverted page table: one entry per FRAME
framepidpage
0312
114
227
319
423
532
610
7215

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).

0 / 4
computed by script: the algorithm or the translation is executed, one event per step. python3 scripts/gen-os-mem-traces.py

Worked examples

EX 1A two-level translation by hand

Easy

Logical address 1233 in the toy space. In binary it is 010 011 010001: p1=2p_1 = 2, p2=3p_2 = 3, d=17d = 17. The outer table entry 2 points to inner table T1. Entry 3 of T1 is frame 21. Physical address =21×64+17=1361= 21 \times 64 + 17 = 1361. 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?

Medium

A 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 levels

Reading 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 210=10242^{10} = 1024 pages = 4 MB), so the tables take 1+3=41 + 3 = 4 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 ⌈52/9⌉=6\lceil 52/9 \rceil = 6 levels; hardware with 48-bit addresses uses 4.

EX 3Splitting the address bits

Medium

A system has 38-bit logical addresses, 4 KB pages and 8-byte page-table entries. A table that fits one page holds 4096/8=512=294096/8 = 512 = 2^9 entries, so each level takes 9 bits. The page number has 38−12=2638 - 12 = 26 bits, so ⌈26/9⌉=3\lceil 26/9 \rceil = 3 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 8+9+9+128 + 9 + 9 + 12. Memory accesses per reference without a TLB: 3+1=43 + 1 = 4. 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

Medium

A machine has 1 GB of memory, 4 KB frames and an inverted table entry of 8 bytes. Frames: 230/212=218=2621442^{30}/2^{12} = 2^{18} = 262144. Table size: 218×8=22^{18} \times 8 = 2 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 (1,9)(1, 9) is found at position 3 after 4 comparisons and the physical address is 3×256+100=8683 \times 256 + 100 = 868.

EX 5Compare the structures

GATE level

Which 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 k+1k + 1 accesses per reference without a TLB? A kk-level table. Why is a flat table impossible for 64-bit addresses? It would need 2522^{52} entries (with 4 KB pages), which is 252×82^{52} \times 8 bytes =32= 32 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: 2m−n2^{m-n} 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 b=log⁡2(page/e)b = \log_2(\text{page}/e); levels =⌈(m−n)/b⌉= \lceil (m - n)/b \rceil; the top level takes the remainder bits.
  • kk levels: k+1k + 1 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 (pid,page)(\text{pid}, \text{page}); position == frame; size == frames ×\times 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

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

GATE 2025 · NATQ4 · page 340 of the book
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 ______.
GATE 2024 · NATQ9 · page 341 of the book
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 _____
GATE 2023 · NATQ13 · page 342 of the book
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.........
GATE 2022 · MCQ · 2 marksQ14 · page 342 of the book
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.
GATE 2021 · NATQ17 · page 342 of the book
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
GATE 2016 · NATQ25 · page 344 of the book
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.
GATE 2015 · NATQ30 · page 344 of the book
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.
year not read yetQ36 · page 345 of the book
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
year not read yetQ42 · page 346 of the book
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
GATE 2008 · MCQQ43 · page 346 of the book
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 answer

Offset 13 bits; entries per table 8192/4=2048=2118192/4 = 2048 = 2^{11}, so b=11b = 11. Page number 32−13=1932 - 13 = 19 bits; ⌈19/11⌉=2\lceil 19/11 \rceil = 2 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 answer

6 MB =1536= 1536 pages; each inner table covers 1024 pages, so ⌈1536/1024⌉=2\lceil 1536/1024 \rceil = 2 inner tables. Total 1+2=31 + 2 = 3 tables of 4 KB =12= 12 KB.

Question 3

An inverted page table: 512 MB of memory, 4 KB frames, 8-byte entries. Table size?

Show answer

Frames =229/212=217=131072= 2^{29}/2^{12} = 2^{17} = 131072; size =217×8=1= 2^{17} \times 8 = 1 MB.

Question 4

With a three-level page table and no TLB, how many memory accesses does one data reference need?

Show answer

Three table accesses and one data access: 4.

Revision card

One-screen revision

  • Flat table too big. Multilevel: tables page-sized, b=log⁡2(page/e)b = \log_2(\text{page}/e) bits per level, levels =⌈(m−n)/b⌉= \lceil (m-n)/b \rceil, k+1k + 1 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