Skip to content

Commit

Permalink
Correct minimum number of page table entries needed for multilevel ta…
Browse files Browse the repository at this point in the history
…bles

A page table that needs to map virtual addresses up to 1_000_150 when the page size is 50 bytes needs 1_000_150 ÷ 50 = 20_003 entries.
  • Loading branch information
dariuswiles authored Nov 21, 2024
1 parent b797cc8 commit 37869df
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions blog/content/edition-2/posts/08-paging-introduction/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ The simple page tables we just saw have a problem in larger address spaces: they

![Page 0 mapped to frame 0 and pages `1_000_000``1_000_150` mapped to frames 100–250](single-level-page-table.svg)

It only needs 4 physical frames, but the page table has over a million entries. We can't omit the empty entries because then the CPU would no longer be able to jump directly to the correct entry in the translation process (e.g., it is no longer guaranteed that the fourth page uses the fourth entry).
It only needs 4 physical frames, but the page table has over twenty thousand entries. We can't omit the empty entries because then the CPU would no longer be able to jump directly to the correct entry in the translation process (e.g., it is no longer guaranteed that the fourth page uses the fourth entry).

To reduce the wasted memory, we can use a **two-level page table**. The idea is that we use different page tables for different address regions. An additional table called _level 2_ page table contains the mapping between address regions and (level 1) page tables.

Expand All @@ -130,7 +130,7 @@ Page 0 falls into the first `10_000` byte region, so it uses the first entry of

The pages `1_000_000`, `1_000_050`, and `1_000_100` all fall into the 100th `10_000` byte region, so they use the 100th entry of the level 2 page table. This entry points to a different level 1 page table T2, which maps the three pages to frames `100`, `150`, and `200`. Note that the page address in level 1 tables does not include the region offset. For example, the entry for page `1_000_050` is just `50`.

We still have 100 empty entries in the level 2 table, but much fewer than the million empty entries before. The reason for these savings is that we don't need to create level 1 page tables for the unmapped memory regions between `10_000` and `1_000_000`.
We still have 100 empty entries in the level 2 table, but much fewer than the twenty thousand empty entries before. The reason for these savings is that we don't need to create level 1 page tables for the unmapped memory regions between `10_000` and `1_000_000`.

The principle of two-level page tables can be extended to three, four, or more levels. Then the page table register points to the highest level table, which points to the next lower level table, which points to the next lower level, and so on. The level 1 page table then points to the mapped frame. The principle in general is called a _multilevel_ or _hierarchical_ page table.

Expand Down

0 comments on commit 37869df

Please sign in to comment.