A 2 MiB page uses a 21-bit offset, and a 1 GiB page uses a 30-bit offset. The leftover VPN bits need fewer table levels.
A 2 MiB mapping skips the leaf level, so its walk reads three tables. A 1 GiB mapping skips two levels and reads two tables.
Page size | Offset bits | Walk reads | PTEs per 1 GiB |
|---|---|---|---|
4 KiB | 12 | 4 | 262144 |
2 MiB | 21 | 3 | 512 |
1 GiB | 30 | 2 | 1 |
Each huge-page TLB entry maps far more memory. A small set of huge entries can cover a large buffer that thousands of 4 KiB entries could not.
1 GiB region: 2^30 B
4 KiB PTEs: 2^30 / 2^12 = 2^18 = 262144
2 MiB PTEs: 2^30 / 2^21 = 2^9 = 512
1 GiB PTEs: 2^30 / 2^30 = 1
TLB reach: 32 entries x 2 MiB = 32 x 2097152 B = 67108864 B = 64 MiBHuge pages need large contiguous, aligned physical blocks. After long uptime the allocator may fail to find one, and the mapping falls back to 4 KiB pages.
A 10 KiB structure in a 2 MiB page wastes nearly the whole page. That internal fragmentation is the price of the extra reach.
Benefit | Cost |
|---|---|
Larger reach per TLB entry | Needs contiguous aligned physical memory. |
Shorter walks and fewer PTEs | Internal fragmentation for small mappings. |
Fewer TLB misses for big buffers | Mixed sizes complicate replacement and shootdowns. |
512 pages. Three reads, since the leaf level is skipped.
64 MiB. Each entry maps 2 MiB, so 32 times 2 MiB is 64 MiB.