diff --git a/content/call/index.md b/content/call/index.md index 2d3e173..8cbd097 100644 --- a/content/call/index.md +++ b/content/call/index.md @@ -157,7 +157,7 @@ The loader does several things to run a program. To learn more, we strongly reco **1. Load program into a newly created address space** in memory.[^vm] -[^vm]: We discuss virtual memory in a later chapter. +[^vm]: We discuss virtual memory in a [later chapter](#sec-virtual-memory). * Read `a.out` file header for sizes of text, data segments. * Create new address space for program large enough to hold **text and data segments**, along with a stack segment. diff --git a/content/vm/address-translation.md b/content/vm/address-translation.md index 29dbec2..80d0df2 100644 --- a/content/vm/address-translation.md +++ b/content/vm/address-translation.md @@ -1,13 +1,14 @@ --- title: "Address Translation" -subtitle: Coming soon. Thanks for your patience! --- - -(sec-memory-manager)= ::::{note} 🎥 Lecture Video :class: dropdown @@ -18,65 +19,120 @@ subtitle: Coming soon. Thanks for your patience! :::: - +[^demand-paging]: Read more on Wikipedia about [demand paging](https://en.wikipedia.org/wiki/Demand_paging) and its counterpart, [anticipatory paging](https://en.wikipedia.org/wiki/Memory_paging#Anticipatory_paging). diff --git a/content/vm/images/demand-paging.png b/content/vm/images/demand-paging.png new file mode 100644 index 0000000..aeeb461 Binary files /dev/null and b/content/vm/images/demand-paging.png differ diff --git a/content/vm/index.md b/content/vm/index.md index e93ce0a..65d3445 100644 --- a/content/vm/index.md +++ b/content/vm/index.md @@ -176,17 +176,51 @@ Each VPN maps to a PPN. Virtual pages and physical pages are the same size, so t * A physical address is decomposed into a **physical page number (PPN)** and a **page offset**. For a 48-bit physical address with 4 KiB pages, the PPN is the upper 28 bits and the page offset is the lower 12 bits. * As shown in @fig-vpn-to-ppn, the address translation mechanism of virtual memory works regardless of whether physical memory is smaller _or_ larger than the virtual address space capacity. -To translate a virtual address to a physical address: +:::{hint} Quick Check -1. First decompose the virtual address into VPN and page offset. -1. Then, lookup the PPN corresponding to this VPN. -1. Finally, construct the physical address by concatenating the PPN with the page offset. - a virtual page number to a physical page number. Keep the page offset the same. +Assume a 32-bit machine with 8GiB of RAM and 16KiB pages. +How many bits would there be for each of the following? -A **page table** keeps track of the VPN-to-PPN mappings for a given process (for Step 2 above). There is one page table per process. +1. Page offset +1. Virtual page number (VPN) +1. Physical page number (PPN) -:::{note} Pages are the memory unit of virtual memory +::: + +:::{note} Show Answer +:class: dropdown + +1. Page offset: = $\log_2$(16 KiB) = $\log_2(2^4 \times 2^{10})$ = 14 bits + +1. VPN = 32 - 14 = 18 bits + +1. PPN = $\log_2$(8 GiB) - 14 = $\log_2(2^3 \times 2^{30}) - 14$ = 33 - 14 = 19 bits + +::: + +:::{hint} Quick Check + +Suppose we have a 32-bit virtual address space with 16 GiB DRAM and 4 KiB pages. True or False? + +1. There are $2^{32}$ / $2^{12}$ = $2^{20}$ Virtual Page Numbers. +2. There are $2^{4} \times 2^{30} / 2^{12} = 2^{22}$ Physical Page Numbers. +3. Virtual addresses are 32-bits, where the bottom 12 bits are used to reference page offset. +4. Both the virtual page size and the physical page size are 4 KiB. +::: + +:::{note} Show Answers +:class: dropdown + +1. True +1. True +1. True +1. True +::: + +:::{warning} Pages are the memory unit of virtual memory On a given machine, virtual pages and physical pages are the **same size**. For a given virtual-physical address mapping, the virtual page number and physical page numbers may be different, but the virtual page offset and physical page offset are **identical**. ::: + +We discuss this virtual-to-physical address translation in the [next section](#sec-vm-address-translation). diff --git a/content/vm/page-table.md b/content/vm/page-table.md new file mode 100644 index 0000000..291a87b --- /dev/null +++ b/content/vm/page-table.md @@ -0,0 +1,37 @@ +--- +title: "Page Tables" +subtitle: Coming soon. Thanks for your patience! +--- + +(sec-page-table)= +## Learning Outcomes + +* TODO +* TODO + +::::{note} 🎥 Lecture Video +:class: dropdown + +:::{iframe} https://www.youtube.com/embed/Rc73MpGzZuM +:width: 100% +:title: "[CS61C FA20] Lecture 29.5 - Virtual Memory I: Page Faults" +::: + +:::: + + + diff --git a/content/vm/page-tables-hierarchical.md b/content/vm/page-tables-hierarchical.md index 42a25b6..46f57fa 100644 --- a/content/vm/page-tables-hierarchical.md +++ b/content/vm/page-tables-hierarchical.md @@ -8,6 +8,7 @@ subtitle: This content is not tested * TODO * TODO --> +(sec-hierarchical-page-table)= ::::{note} 🎥 Lecture Video :class: dropdown @@ -16,4 +17,4 @@ subtitle: This content is not tested :title: "[CS61C FA20] Lecture 30.1 - Virtual Memory II: Hierarchical Page Tables" ::: -:::: \ No newline at end of file +:::: diff --git a/myst.yml b/myst.yml index 4c336e0..9df7d84 100644 --- a/myst.yml +++ b/myst.yml @@ -253,7 +253,7 @@ project: children: - file: content/vm/index.md - file: content/vm/address-translation.md - - file: content/vm/page-faults.md + - file: content/vm/page-table.md - title: "L36: The TLB, Page Table Walks" children: - file: content/vm/tlb.md