G27
Self-checkedTier 1 12 min reados.tlb-effective-access

TLB and effective access time

The translation lookaside buffer: why paging doubles memory accesses, how a small associative cache of recent translations fixes it, hits and misses, the effective access time with one or several page-table levels, the TLB reach, address-space identifiers and flushing, and the combination with page faults.

Why it exists

With the page table in main memory, every memory reference needs two accesses: one to read the page-table entry, one to read the data. That halves the speed of the machine. The cure is the same as for slow memory generally: cache the recent results. The translation lookaside buffer (TLB) is a small, very fast memory that holds recently used (page number, frame number) pairs. Most references find their translation there and cost almost nothing extra. GATE asks you, nearly every year, to compute the effective (average) memory access time from the hit ratio and the access times, with a TLB, with a multilevel table and sometimes with page faults.

Prerequisites

You need the page table and the translation from paging; the idea of a cache with a hit ratio comes from the memory hierarchy.

Precise definitions

TLB. A small associative (content-addressable) memory: it compares the page number of the address with the page numbers of all its entries at once, and on a match returns the frame number. Typical sizes are 32 to 1024 entries. Each entry holds the page number, the frame number and protection bits.

Translation with a TLB.

  1. The page number pp is presented to the TLB.
  2. TLB hit: the frame number is returned at once; the physical address is formed. Cost: the TLB lookup plus one memory access (the data).
  3. TLB miss: the page table in memory is consulted (one memory access for a single-level table, kk for a kk-level table); the translation is then copied into the TLB (replacing an entry, often the least recently used, if the TLB is full), and the data is accessed.

Hit ratio hh. The fraction of references whose translation is found in the TLB. A hit ratio of 98% means 2% of references take the slow path.

Effective access time (EAT). Let tt be the TLB access time, mm the memory access time and kk the number of page-table levels (1 for a single table). With the TLB searched first and the page table consulted only on a miss:

EAT=h (t+m)+(1−h) (t+k m+m)=h (t+m)+(1−h) (t+(k+1) m).\text{EAT} = h\,(t + m) + (1 - h)\,\bigl(t + k\,m + m\bigr) = h\,(t + m) + (1 - h)\,\bigl(t + (k + 1)\,m\bigr).

A hit costs t+mt + m; a miss costs the failed TLB lookup tt, the kk table accesses and the data access mm. Special cases:

  • TLB time negligible (t=0t = 0) and single level: EAT=h m+(1−h) 2m=m (2−h)\text{EAT} = h\,m + (1 - h)\,2m = m\,(2 - h).
  • Without a TLB: EAT=(k+1) m\text{EAT} = (k + 1)\,m, so 2m2m for a single table.
  • Perfect hit ratio h=1h = 1: t+mt + m.

If a question searches the TLB and the page table in parallel, the TLB lookup overlaps the start of the table walk, so a miss costs about (k+1) m(k + 1)\,m instead of t+(k+1) mt + (k + 1)\,m; read the wording. The default in textbooks, and in the formula above, is sequential.

With page faults too. If a fraction pp of references (after the translation) faults, with service time TfT_f:

EAT=(1−p) EATtranslation+access+p Tf,\text{EAT} = (1 - p)\,\text{EAT}_{translation + access} + p\,T_f,

where the first term is the time computed above. (Some questions write the page-table and fault parts together in one formula; derive it from the cases.)

TLB reach. The memory covered by the TLB: entries×page size\text{entries} \times \text{page size}. With 64 entries and 4 KB pages the reach is 256 KB; the hit ratio is high if the working set of the program fits in the reach. Larger pages (or several page sizes) enlarge the reach.

Address-space identifiers and flushing. The TLB's entries belong to one process's page table. On a context switch, either the TLB is flushed (all entries invalidated; the new process starts with all misses), or each entry carries an address-space identifier (ASID) (or process id) and an entry is used only if its ASID matches the running process, so entries can survive a context switch (context switch). When a page table entry changes (a page is replaced), the matching TLB entry must be invalidated.

Who handles a miss. In most architectures the hardware walks the page table on a miss; in others (MIPS, SPARC) the miss traps to the operating system, which loads the entry (a software-managed TLB).

How it works

The animation sends ten references through a TLB of four entries (replacement: least recently used). The TLB table (top left) shows its current entries; the page table is below it. A hit costs 10+100=11010 + 100 = 110 ns. A miss costs 10+100+100=21010 + 100 + 100 = 210 ns: the TLB lookup, the page-table access (the page-table row is highlighted) and the data access, after which the entry is copied into the TLB. With this stream five of the ten references hit, so the hit ratio is 0.5 and the average time is exactly the formula's: 0.5×110+0.5×210=1600.5 \times 110 + 0.5 \times 210 = 160 ns.

A TLB in front of the page table: start

Translation computed, not typed
TLB (4 entries, LRU)
slotpageframe
0--
1--
2--
3--
page table (in memory)
pageframe
03
16
21
39
44
50
67
72

No address yet.

Step 0

The page table is in main memory, so every reference would need TWO memory accesses (one for the entry, one for the data). The TLB is a small, fast associative memory holding the most recent (page, frame) pairs. Access times: TLB 10 ns, memory 100 ns. A TLB HIT costs 10 + 100 = 110 ns; a MISS costs 10 + 100 + 100 = 210 ns (look in the TLB, read the page table, read the data). The TLB has 4 entries and replaces the least recently used.

0 / 15
computed by script: the algorithm is executed on the reference string, one reference per step. python3 scripts/gen-os-vm-traces.py

Worked examples

EX 1The same stream, by program

Easy

A program runs the ten references through a 4-entry LRU TLB and prints the average time and the formula's value; it also tabulates the effective access time for several hit ratios, for a one-level and a two-level page table.

#include <stdio.h>
 
#define SIZE 4
 
int main(void) {
    int stream[10] = {1, 2, 1, 1, 3, 2, 2, 4, 1, 5};
    int tlb[SIZE], used[SIZE], count = 0, hits = 0;
    double total = 0, t_tlb = 10, t_mem = 100;
    for (int t = 0; t < 10; t++) {
        int slot = -1;
        for (int i = 0; i < count; i++) if (tlb[i] == stream[t]) slot = i;
        if (slot >= 0) { hits++; total += t_tlb + t_mem; }
        else {
            total += t_tlb + 2 * t_mem;
            if (count < SIZE) slot = count++;
            else { slot = 0; for (int i = 1; i < SIZE; i++) if (used[i] < used[slot]) slot = i; }
            tlb[slot] = stream[t];
        }
        used[slot] = t;
    }
    double h = hits / 10.0;
    printf("TLB of %d entries: %d hits in 10 references, h = %.1f, average time %.1f ns\n", SIZE, hits, h, total / 10);
    printf("formula h(t + m) + (1 - h)(t + 2m) = %.1f ns\n", h * (t_tlb + t_mem) + (1 - h) * (t_tlb + 2 * t_mem));
    /* effective access time for several hit ratios: one-level and two-level page tables, TLB 10 ns, memory 100 ns */
    for (double hr = 0.5; hr <= 1.0001; hr += 0.1) {
        double one = hr * (t_tlb + t_mem) + (1 - hr) * (t_tlb + 2 * t_mem);
        double two = hr * (t_tlb + t_mem) + (1 - hr) * (t_tlb + 3 * t_mem);
        printf("h = %.1f: one-level %.1f ns, two-level %.1f ns\n", hr, one, two);
    }
    printf("TLB reach with 64 entries and 4 KB pages: %d KB\n", 64 * 4);
    return 0;
}
TLB of 4 entries: 5 hits in 10 references, h = 0.5, average time 160.0 ns
formula h(t + m) + (1 - h)(t + 2m) = 160.0 ns
h = 0.5: one-level 160.0 ns, two-level 210.0 ns
h = 0.6: one-level 150.0 ns, two-level 190.0 ns
h = 0.7: one-level 140.0 ns, two-level 170.0 ns
h = 0.8: one-level 130.0 ns, two-level 150.0 ns
h = 0.9: one-level 120.0 ns, two-level 130.0 ns
h = 1.0: one-level 110.0 ns, two-level 110.0 ns
TLB reach with 64 entries and 4 KB pages: 256 KB

Reading it. The simulated average (160 ns) equals the formula, as it must: the formula is just the average of the two possible costs weighted by how often each occurs. The table shows the value of a good hit ratio: without a TLB a one-level table would cost 2×100=2002 \times 100 = 200 ns per reference, and at h=0.9h = 0.9 the average is 120 ns, close to the 110 ns floor. A two-level table suffers more from misses: 210 ns at h=0.5h = 0.5 against 160 ns for one level.

EX 2The classic question

Medium

A system has a TLB with access time 20 ns and a two-level page table; each memory access takes 100 ns; the TLB hit ratio is 90%. A hit costs 20+100=12020 + 100 = 120 ns. A miss costs 2020 (TLB) +2×100+ 2 \times 100 (two table levels) +100+ 100 (data) =320= 320 ns. EAT=0.9×120+0.1×320=108+32=140\text{EAT} = 0.9 \times 120 + 0.1 \times 320 = 108 + 32 = 140 ns. If the question had said the TLB lookup is negligible, the numbers would be 0.9×100+0.1×300=1200.9 \times 100 + 0.1 \times 300 = 120 ns. Always check whether the TLB time is given and whether the table has one, two or more levels.

EX 3What hit ratio is needed?

Medium

Memory time is 100 ns and the TLB time 10 ns, single-level table. For an average of at most 130130 ns: 110 h+210 (1−h)≤130110\,h + 210\,(1 - h) \le 130, so 210−100 h≤130210 - 100\,h \le 130 and h≥0.8h \ge 0.8. If the TLB time is ignored, the formula 100 (2−h)≤120100\,(2 - h) \le 120 (20% over the minimum) gives h≥0.8h \ge 0.8 too. The method: write EAT as hit cost+(1−h)×extra cost of a miss\text{hit cost} + (1 - h) \times \text{extra cost of a miss}, set it at most the target and solve for hh.

EX 4TLB reach and page size

Medium

A TLB has 64 entries. With 4 KB pages its reach is 64×4=25664 \times 4 = 256 KB; a program whose working set is larger will keep missing. With 2 MB pages the reach is 64×2=12864 \times 2 = 128 MB: the same TLB covers 512 times more memory, which is why large pages ("huge pages") are used for big data sets. The price is more internal fragmentation and coarser protection and sharing.

EX 5TLB and page faults together

GATE level

Memory access 100 ns, TLB 10 ns, TLB hit ratio 0.9, single-level table. After translation, 1 reference in 10 000 causes a page fault costing 8 ms. Translation and access: 0.9×110+0.1×210=1200.9 \times 110 + 0.1 \times 210 = 120 ns. EAT =(1−10−4)×120+10−4×8 000 000=119.988+800=919.988= (1 - 10^{-4}) \times 120 + 10^{-4} \times 8\,000\,000 = 119.988 + 800 = 919.988 ns. The page faults, though rare, dominate: this is the point of keeping the fault rate tiny (virtual memory and demand paging). A question might also say a fault costs the 8 ms plus a retry that hits the TLB; add that retry to TfT_f if stated.

Cheat box

Cheat box

  • Without a TLB: (k+1) m(k + 1)\,m per reference (2m2m for one level).
  • TLB (searched first): EAT=h (t+m)+(1−h) (t+(k+1) m)\text{EAT} = h\,(t + m) + (1 - h)\,(t + (k + 1)\,m).
  • t=0t = 0, one level: m (2−h)m\,(2 - h). h=1h = 1: t+mt + m.
  • TLB reach == entries ×\times page size.
  • Context switch: flush the TLB, or tag entries with an ASID.
  • With page faults: (1−p)×EAT+p Tf(1 - p) \times \text{EAT} + p\,T_f.
  • Parallel search of TLB and table: read the question; the sequential formula is the default.

Traps and GATE patterns

Connections

The TLB fixes the doubled cost of paging, and matters even more for the multilevel tables of page table structures, where a miss costs several accesses. It is a cache like the ones in cache performance, with the same hit-ratio arithmetic. It interacts with context switching (flush or ASID) and with the page faults of virtual memory.

PYQs

10 previous year questions from your book. I re-solved each one myself (7 by running or simulating, 3 by reasoning only); the book's key is shown next to my answer. All PYQs

GATE 2026 · NATQ2 · page 340 of the book
A system has a Translation Lookaside Buffer
(TLB) that has a reach of 1 MB. TLB reach is
defined as the total amount of physical memory that
can be accessed through the TLB entries.

The paging system uses pages of size 4 KB. The
virtual address space is 64 GB and physical address
space is 1 GB.

If each TLB entry stores:
●
a 4-bit process id
●
page number
●
frame number
●
a 2-bit control field

then the size of the TLB (in bytes) is ______.

Note:
1K = 210, 1M = 220, 1G = 230.
GATE 2026 · MSQQ3 · page 340 of the book
Consider a system that has a cache memory unit and
a memory management unit (MMU). The address
input to the cache memory is a physical address. The
MMU has a Translation Lookaside Buffer (TLB).
Assume that when a page is evicted from main
memory, the corresponding blocks in the cache are
marked invalid.

For a given memory reference, which of the following
sequences of events can NEVER happen?
  • (a)TLB miss, Page table hit, Cache hit
  • (b)TLB hit, Page table miss, Cache hit
  • (c)TLB miss, Page table miss, Cache hit
  • (d)TLB miss, Page table miss, Cache miss
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 2020 · NATQ19 · page 343 of the book
Consider a paging system that uses a 1-level page
table residing in main memory and a TLB for
address translation. Each main memory access
takes 100 ns and TLB lookup takes 20 ns. Each
page transfer to/from the disk takes 5000 ns.
Assume that the TLB hit ratio is 95%, page fault
rate is 10%. Assume that for 20% of the total page
faults, a dirty page has to be written back to disk
before the required page is read in from disk. TLB
update time is negligible. The average memory
access time in ns (round off to 1 decimal place) is
______.
GATE 2019 · MCQ · 2 marksQ20 · page 343 of the book
Assume that in a certain computer, the virtual
addresses are 64 bits long and the physical
addresses are 48 bits long. The memory is word
addressable. The page size is 8 kB and the word
size is 4 bytes. The Translation Look-aside Buffer
(TLB) in the address translation path has 128 valid
entries. At most how many distinct virtual
addresses can be translated without any TLB miss?
  • (a)8×220
  • (b)4×220
  • (c)16×210
  • (d)256×210
year not read yetQ21 · page 343 of the book
Consider a process executing on an operating system
that uses demand paging. The average time for a
memory access in the system is M units if the
corresponding memory page is available in memory
and D units if the memory access causes a page fault.
It has been experimentally measured that the average
time taken for a memory access in the process is X
units.

Which one of the following is the correct expression
for the page fault rate experienced by the process?
  • (a)(D-M)/(X-M)
  • (b)(X-M)/(D-M)
  • (c)(D-X)/(D-M)
  • (d)(X-M)/(D-X)
GATE 2015 · NATQ28 · page 344 of the book
A computer system implements a 40-bit virtual
address, page size of 8 kilobytes, and a 128-entry
translation look-aside buffer (TLB organized into 32
sets each having four ways. Assume that the TLB tag
does not store any process id. The minimum length of
the TLB tag in bits is _________.
GATE 2014 · NATQ35 · page 345 of the book
Consider a paging hardware with a TLB. Assume
that the entire page table and all the pages are in the
physical memory. It takes 10 ms to search the TLB
and 80 ms to access the physical memory. If the
TLB hit ratio is 0.6, the effective memory access
time (in milliseconds) is ______
GATE 2011 · MCQ · 1 markQ38 · page 346 of the book
Let the page fault service time to 10 ms in a
computer with average memory access time being
20 ns. If one page fault is generated for every 106
memory accesses, what is the effective access time
for the memory?
  • (a)21 ns
  • (b)30 ns
  • (c)23 ns
  • (d)25ns
year not read yetQ47 · page 347 of the book
A CPU generates 32-bit virtual addresses. The page
size is 4 KB. The processor has a translation look-
aside buffer (TLB) which can hold a total of 128 page
table entries and is 4-way set associative. The
minimum size of the TLB tag is
  • (a)11 bits
  • (b)13 bits
  • (c)15 bits
  • (d)20 bits

Self-check

Question 1

TLB 10 ns, memory 80 ns, hit ratio 0.95, single-level table. EAT?

Show answer

Hit: 10+80=9010 + 80 = 90 ns. Miss: 10+80+80=17010 + 80 + 80 = 170 ns. 0.95×90+0.05×170=85.5+8.5=940.95 \times 90 + 0.05 \times 170 = 85.5 + 8.5 = 94 ns.

Question 2

Same machine, two-level table.

Show answer

Miss =10+2×80+80=250= 10 + 2 \times 80 + 80 = 250 ns. EAT =0.95×90+0.05×250=85.5+12.5=98= 0.95 \times 90 + 0.05 \times 250 = 85.5 + 12.5 = 98 ns.

Question 3

TLB with 128 entries and 8 KB pages. Reach?

Show answer

128×8128 \times 8 KB =1024= 1024 KB =1= 1 MB.

Question 4

Why must a TLB entry be invalidated when a page is replaced in memory?

Show answer

Otherwise the TLB would still map the page to the old frame, which now holds a different page: the process would read or write the wrong data.

Revision card

One-screen revision

  • Hit: t+mt + m. Miss: t+(k+1) mt + (k + 1)\,m. EAT=h (t+m)+(1−h) (t+(k+1) m)\text{EAT} = h\,(t + m) + (1 - h)\,(t + (k + 1)\,m).
  • Without a TLB (k+1) m(k + 1)\,m. Reach == entries ×\times page size.
  • Flush or ASID on a context switch; invalidate on page replacement. Add page faults separately.

References

  • ·Silberschatz, Galvin, Gagne, Operating System Concepts, Chapter 9 Main Memory (hardware support: the translation look-aside buffer)
  • ·Tanenbaum and Bos, Modern Operating Systems, Chapter 3 Memory Management (speeding up paging: translation lookaside buffers)
  • ·Hennessy and Patterson, Computer Organization and Design, Chapter 5 (virtual memory: making address translation fast, the TLB)

Verification

The TLB animation is a reference-by-reference simulation (scripts/gen-os-vm-traces.py) that accumulates the time of every reference and asserts that the average equals the effective-access-time formula; scripts/enum-checks/os_vm.py confirms the formula on 300 random reference streams with an independent TLB, and tests/os-vm-traces.test.ts re-simulates the TLB and rechecks every physical address. The C program on this page (npm run verify:c) gives the same hit count, average and table of effective access times. The access times (TLB 10 ns, memory 100 ns) are illustrative. The formulas assume that the TLB is searched first and the page table only on a miss (the sequential model used by most textbook questions); some questions search both in parallel, which changes the miss time, and the page says how to recognise it. 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. The sentence on parallel search of TLB and page table was rewritten (the old formula was vague). Status raised to self-checked; verified needs a textbook or human check.

last verified: never