目录 ← 首页
CS61C

Address Translation

Learning Outcomes

  • Use a pre-populated page table to translate virtual addresses into physical addresses.
  • Define a page fault and identify when an address translation scenario triggers a page fault.

In this section we discuss:

  • How to do address translation when the data requested is in memory, i.e., no page fault occurs.
  • How to do address translation when the data requested is not in memory, i.e., a page fault occurs.

We leave the description of the system performs address translation to this section.

#block-page-table

We discuss the fine-grained details of page tables in another section.

Address Translation, Conceptually

Case I: Page Is In Memory

Consider a scenario where a process has a 32-bit virtual address space, and physical memory is 16 KiB and paged into four 4 KiB pages. There are four steps to address translation, as shown by #fig-address-translation-i’s animation. Fow now, conceptually, a page table entry is valid if it has a physical page number (PPN) and invalid if it is labeled “disk”.

Address Translation, Case I: The target page is in memory.

This case is predicated on our page table entry being valid. A valid page table entry means that the virtual page has a corresponding physical page number, and therefore the page is in memory. Next, let’s explore when the page is not in memory.

Case II: Page Fault

We continue our scenario with the same process. Now, suppose that the next memory access triggers a page fault, as shown in #fig-address-translation-ii’s animation.

Address Translation, Case II: The target page is not in memory, triggering a page fault. With demand paging, a page fault means the page is fetched from disk.

Revisiting the Library Analogy

Let’s understand virtual memory using our library analogy of the memory hierarchy.

  • The book title is like a virtual address, and the Library of Congress call number is like a physical address. We usually remember a book by its title (VA), and not its call number (PA).
  • The card catalog is like a page table, which maps from book title to call number. If we went straight to the bookshelves to find a book number without the call number, we likely wouldn’t find the book. So the card catalog (page table) is important.
  • The corresponding card entry in the catalog has useful information:
    • Valid bit: Does the book exist in this library? (Is the page in memory?) Or do you need to request a hold and be notified when the book is available in the library? (Trigger a page fault and notify when page is loaded from disk into memory?)
    • Access bit: Can you check out this book, or is it reference-only? (We discuss memory page access rights more in this section.)

This analogy breaks down slightly because the page table is a page number lookup, not an address lookup. But we hope the weak analogy helps.

Practice

Footnotes

  1. Jim Gray’s analogy figure for your reference.