diff --git a/blog/content/second-edition/posts/10-advanced-paging/index.md b/blog/content/second-edition/posts/10-advanced-paging/index.md index 5f86e003..16cd8d85 100644 --- a/blog/content/second-edition/posts/10-advanced-paging/index.md +++ b/blog/content/second-edition/posts/10-advanced-paging/index.md @@ -55,7 +55,7 @@ So in order to access page table frames, we need to map some virtual pages to th - Alternatively, we could **map the page tables frames only temporarily** when we need to access them. To be able to create the temporary mappings we only need a single identity-mapped level 1 table: - ![A virtual and a physical address space with an identity mapped level 1 table, which maps its 0th entry to the level 2 table frame, therey mapping that frame to page with address 0](temporarily-mapped-page-tables.svg) + ![A virtual and a physical address space with an identity mapped level 1 table, which maps its 0th entry to the level 2 table frame, therey mapping that frame to page with address 0](temporarily-mapped-page-tables.png) The level 1 table in this graphic controls the first 2 MiB of the virtual address space. This is because it is reachable by starting at the CR3 register and following the 0th entry in the level 4, level 3, and level 2 page tables. The entry with index `8` maps the virtual page at address `32 KiB` to the physical frame at address `32 KiB`, thereby identity mapping the level 1 table itself. The graphic shows this identity-mapping by the horizontal arrow at `32 KiB`. @@ -78,7 +78,7 @@ The idea behind this approach sounds simple: _Map some entry of the level 4 page Let's go through an example to understand how this all works: -![An example 4-level page hierarchy with each page table shown in physical memory. Entry 511 of the level 4 page is mapped to frame 4KiB, the frame of the level 4 table itself.](recursive-page-table.svg) +![An example 4-level page hierarchy with each page table shown in physical memory. Entry 511 of the level 4 page is mapped to frame 4KiB, the frame of the level 4 table itself.](recursive-page-table.png) The only difference to the [example at the beginning of this post] is the additional entry at index `511` in the level 4 table, which is mapped to physical frame `4 KiB`, the frame of the level 4 table itself. @@ -88,17 +88,17 @@ By letting the CPU follow this entry on a translation, it doesn't reach a level By following the recursive entry one or multiple times before we start the actual translation, we can effectively shorten the number of levels that the CPU traverses. For example, if we follow the recursive entry once and then proceed to the level 3 table, the CPU thinks that the level 3 table is a level 2 table. Going further, it treats the level 2 table as a level 1 table, and the level 1 table as the mapped frame. This means that we can now read and write the level 1 page table because the CPU thinks that it is the mapped frame. The graphic below illustrates the 5 translation steps: -![The above example 4-level page hierarchy with 5 arrows: "Step 0" from CR4 to level 4 table, "Step 1" from level 4 table to level 4 table, "Step 2" from level 4 table to level 3 table, "Step 3" from level 3 table to level 2 table, and "Step 4" from level 2 table to level 1 table.](recursive-page-table-access-level-1.svg) +![The above example 4-level page hierarchy with 5 arrows: "Step 0" from CR4 to level 4 table, "Step 1" from level 4 table to level 4 table, "Step 2" from level 4 table to level 3 table, "Step 3" from level 3 table to level 2 table, and "Step 4" from level 2 table to level 1 table.](recursive-page-table-access-level-1.png) Similarly, we can follow the recursive entry twice before starting the translation to reduce the number of traversed levels to two: -![The same 4-level page hierarchy with the following 4 arrows: "Step 0" from CR4 to level 4 table, "Steps 1&2" from level 4 table to level 4 table, "Step 3" from level 4 table to level 3 table, and "Step 4" from level 3 table to level 2 table.](recursive-page-table-access-level-2.svg) +![The same 4-level page hierarchy with the following 4 arrows: "Step 0" from CR4 to level 4 table, "Steps 1&2" from level 4 table to level 4 table, "Step 3" from level 4 table to level 3 table, and "Step 4" from level 3 table to level 2 table.](recursive-page-table-access-level-2.png) Let's go through it step by step: First the CPU follows the recursive entry on the level 4 table and thinks that it reaches a level 3 table. Then it follows the recursive entry again and thinks that it reaches a level 2 table. But in reality, it is still on the level 4 table. When the CPU now follows a different entry, it lands on a level 3 table, but thinks it is already on a level 1 table. So while the next entry points at a level 2 table, the CPU thinks that it points to the mapped frame, which allows us to read and write the level 2 table. Accessing the tables of levels 3 and 4 works in the same way. For accessing the level 3 table, we follow the recursive entry entry three times, tricking the CPU into thinking it is already on a level 1 table. Then we follow another entry and reach a level 3 table, which the CPU treats as a mapped frame. For accessing the level 4 table itself, we just follow the recursive entry four times until the CPU treats the level 4 table itself as mapped frame (in blue in the graphic below). -![The same 4-level page hierarchy with the following 3 arrows: "Step 0" from CR4 to level 4 table, "Steps 1,2,3" from level 4 table to level 4 table, and "Step 4" from level 4 table to level 3 table. In blue the alternative "Steps 1,2,3,4" arrow from level 4 table to level 4 table.](recursive-page-table-access-level-3.svg) +![The same 4-level page hierarchy with the following 3 arrows: "Step 0" from CR4 to level 4 table, "Steps 1,2,3" from level 4 table to level 4 table, and "Step 4" from level 4 table to level 3 table. In blue the alternative "Steps 1,2,3,4" arrow from level 4 table to level 4 table.](recursive-page-table-access-level-3.png) It might take some time to wrap your head around the concept, but it works quite well in practice. @@ -635,4 +635,4 @@ We're now able to map arbitrary pages and to allocate new physical frames when w TODO spellcheck TODO improve transition between sections TODO update post date -TODO check level 2 table diagram 24KiB -> 32KiB \ No newline at end of file +TODO use PNGs instead of SVGs? diff --git a/blog/content/second-edition/posts/10-advanced-paging/recursive-page-table-access-level-1.png b/blog/content/second-edition/posts/10-advanced-paging/recursive-page-table-access-level-1.png new file mode 100644 index 00000000..1c6662ab Binary files /dev/null and b/blog/content/second-edition/posts/10-advanced-paging/recursive-page-table-access-level-1.png differ diff --git a/blog/content/second-edition/posts/10-advanced-paging/recursive-page-table-access-level-1.svg b/blog/content/second-edition/posts/10-advanced-paging/recursive-page-table-access-level-1.svg deleted file mode 100644 index a151a767..00000000 --- a/blog/content/second-edition/posts/10-advanced-paging/recursive-page-table-access-level-1.svg +++ /dev/null @@ -1,2 +0,0 @@ - -
Physical Memory
Physical Memory
0KiB
[Not supported by viewer]
Level 4 Page Table
Level 4 Page Table
4KiB
[Not supported by viewer]
IndexFrameFlags
024KiB
r/w



[Not supported by viewer]
Level 3 Page Table
Level 3 Page Table
16KiB
<div>16KiB</div>
24KiB
<div>24KiB</div>
8KiB
[Not supported by viewer]
IndexFrameFlags



511
24KiB
r/w
[Not supported by viewer]
Level 2 Page Table
Level 2 Page Table
Level 1 Page Table
Level 1 Page Table
32KiB
<div>32KiB</div>
IndexFrameFlags
036KiB
r/w



127
12KiBr


[Not supported by viewer]
4KiB
4KiB
CR3 Register
CR3 Register
IndexFrameFlags
0-
-
1
16KiB
r/w



511
4KiB
r/w
[Not supported by viewer]
Step 0
Step 0
Step 1
Step 1
Step 2
Step 2
Step 3
Step 3
Step 4
Step 4
\ No newline at end of file diff --git a/blog/content/second-edition/posts/10-advanced-paging/recursive-page-table-access-level-2.png b/blog/content/second-edition/posts/10-advanced-paging/recursive-page-table-access-level-2.png new file mode 100644 index 00000000..8fed681a Binary files /dev/null and b/blog/content/second-edition/posts/10-advanced-paging/recursive-page-table-access-level-2.png differ diff --git a/blog/content/second-edition/posts/10-advanced-paging/recursive-page-table-access-level-2.svg b/blog/content/second-edition/posts/10-advanced-paging/recursive-page-table-access-level-2.svg deleted file mode 100644 index e28ab42d..00000000 --- a/blog/content/second-edition/posts/10-advanced-paging/recursive-page-table-access-level-2.svg +++ /dev/null @@ -1,2 +0,0 @@ - -
Physical Memory
Physical Memory
0KiB
[Not supported by viewer]
Level 4 Page Table
Level 4 Page Table
4KiB
[Not supported by viewer]
IndexFrameFlags
024KiB
r/w



[Not supported by viewer]
Level 3 Page Table
Level 3 Page Table
16KiB
<div>16KiB</div>
24KiB
<div>24KiB</div>
8KiB
[Not supported by viewer]
IndexFrameFlags



511
24KiB
r/w
[Not supported by viewer]
Level 2 Page Table
Level 2 Page Table
Level 1 Page Table
Level 1 Page Table
32KiB
<div>32KiB</div>
IndexFrameFlags
036KiB
r/w



127
12KiBr


[Not supported by viewer]
4KiB
4KiB
CR3 Register
CR3 Register
IndexFrameFlags
0-
-
1
16KiB
r/w



511
4KiB
r/w
[Not supported by viewer]
Step 0
Step 0
Steps 1&2
Steps 1&2
Step 3
Step 3
Step 4
Step 4
\ No newline at end of file diff --git a/blog/content/second-edition/posts/10-advanced-paging/recursive-page-table-access-level-3.png b/blog/content/second-edition/posts/10-advanced-paging/recursive-page-table-access-level-3.png new file mode 100644 index 00000000..aaf54f22 Binary files /dev/null and b/blog/content/second-edition/posts/10-advanced-paging/recursive-page-table-access-level-3.png differ diff --git a/blog/content/second-edition/posts/10-advanced-paging/recursive-page-table-access-level-3.svg b/blog/content/second-edition/posts/10-advanced-paging/recursive-page-table-access-level-3.svg deleted file mode 100644 index 50a32a4e..00000000 --- a/blog/content/second-edition/posts/10-advanced-paging/recursive-page-table-access-level-3.svg +++ /dev/null @@ -1,2 +0,0 @@ - -
Physical Memory
Physical Memory
0KiB
[Not supported by viewer]
Level 4 Page Table
Level 4 Page Table
4KiB
[Not supported by viewer]
IndexFrameFlags
024KiB
r/w



[Not supported by viewer]
Level 3 Page Table
Level 3 Page Table
16KiB
<div>16KiB</div>
24KiB
<div>24KiB</div>
8KiB
[Not supported by viewer]
IndexFrameFlags



511
24KiB
r/w
[Not supported by viewer]
Level 2 Page Table
Level 2 Page Table
Level 1 Page Table
Level 1 Page Table
32KiB
<div>32KiB</div>
IndexFrameFlags
036KiB
r/w



127
12KiBr


[Not supported by viewer]
4KiB
4KiB
CR3 Register
CR3 Register
IndexFrameFlags
0-
-
1
16KiB
r/w



511
4KiB
r/w
[Not supported by viewer]
Step 0
Step 0
Steps 1,2,3
Steps 1,2,3
Step 4
Step 4
Steps 1,2,3,4
Steps 1,2,3,4
\ No newline at end of file diff --git a/blog/content/second-edition/posts/10-advanced-paging/recursive-page-table.png b/blog/content/second-edition/posts/10-advanced-paging/recursive-page-table.png new file mode 100644 index 00000000..f5f3b999 Binary files /dev/null and b/blog/content/second-edition/posts/10-advanced-paging/recursive-page-table.png differ diff --git a/blog/content/second-edition/posts/10-advanced-paging/recursive-page-table.svg b/blog/content/second-edition/posts/10-advanced-paging/recursive-page-table.svg deleted file mode 100644 index 1325ae5f..00000000 --- a/blog/content/second-edition/posts/10-advanced-paging/recursive-page-table.svg +++ /dev/null @@ -1,2 +0,0 @@ - -
Physical Memory
Physical Memory
0KiB
[Not supported by viewer]
Level 4 Page Table
Level 4 Page Table
4KiB
[Not supported by viewer]
IndexFrameFlags
024KiB
r/w



[Not supported by viewer]
Level 3 Page Table
Level 3 Page Table
16KiB
<div>16KiB</div>
24KiB
<div>24KiB</div>
8KiB
[Not supported by viewer]
IndexFrameFlags



511
24KiB
r/w
[Not supported by viewer]
Level 2 Page Table
Level 2 Page Table
Level 1 Page Table
Level 1 Page Table
32KiB
<div>32KiB</div>
IndexFrameFlags
036KiB
r/w



127
12KiBr


[Not supported by viewer]
4KiB
4KiB
CR3 Register
CR3 Register
IndexFrameFlags
0-
-
1
16KiB
r/w



511
4KiB
r/w
[Not supported by viewer]
\ No newline at end of file diff --git a/blog/content/second-edition/posts/10-advanced-paging/temporarily-mapped-page-tables.png b/blog/content/second-edition/posts/10-advanced-paging/temporarily-mapped-page-tables.png new file mode 100644 index 00000000..3caca134 Binary files /dev/null and b/blog/content/second-edition/posts/10-advanced-paging/temporarily-mapped-page-tables.png differ diff --git a/blog/content/second-edition/posts/10-advanced-paging/temporarily-mapped-page-tables.svg b/blog/content/second-edition/posts/10-advanced-paging/temporarily-mapped-page-tables.svg deleted file mode 100644 index 8b1e67e5..00000000 --- a/blog/content/second-edition/posts/10-advanced-paging/temporarily-mapped-page-tables.svg +++ /dev/null @@ -1,2 +0,0 @@ - -
Physical Memory
Physical Memory
0KiB
[Not supported by viewer]
Level 4 Page Table
Level 4 Page Table
4KiB
[Not supported by viewer]
IndexFrameFlags
024KiB
r/w



[Not supported by viewer]
Level 3 Page Table
Level 3 Page Table
16KiB
<div>16KiB</div>
24KiB
<div>24KiB</div>
8KiB
[Not supported by viewer]
IndexFrameFlags
0
14KiB
r/w



[Not supported by viewer]
Level 2 Page Table
Level 2 Page Table
Level 1 Page Table
Level 1 Page Table
32KiB
<div>32KiB</div>
IndexFrameFlags
024KiB
r/w



8
32KiBr/w


[Not supported by viewer]
4KiB
4KiB
CR3 Register
CR3 Register
IndexFrameFlags
016KiB
r/w



[Not supported by viewer]
Virtual Memory
Virtual Memory
0KiB
[Not supported by viewer]
4KiB
[Not supported by viewer]
16KiB
<div>16KiB</div>
24KiB
<div>24KiB</div>
8KiB
[Not supported by viewer]
32KiB
<div>32KiB</div>
\ No newline at end of file