CS 208 w20 lecture 24 outline

1 Review

Using this diagram, fill in the steps for a page hit and a page fault:

page-hit.png

  1. processor sends virtual address to MMU
  2. MMU requests page table entry (PTE) from page table in cache/memory
    • using page table base register (PTBR) to find beginning of page table for current process
  3. PTE sent to MMU
  4. MMU send physical address to cache/memory requesting data
  5. cache/memory sends data to processor

page-fault.png

  1. processor sends virtual address to MMU
  2. MMU requests page table entry (PTE) from page table in cache/memory
  3. PTE sent to MMU
  4. valid bit is zero, MMU triggers page fault exception
  5. handler identifies page to evict
    • if modified (dirty) write out (page out) to disk
  6. handler loads (pages in) new page, updates PTE in memory
  7. handler returns to original process, restarting faulting instruction

2 Protection

  • want to enforce things like read-only code and kernel-only memory
  • page table permission bits natural way to do this
    • extend page table to include read/write/execute bits
    • MMU checks them on every memory access
    • if violated, raises exception and kernel sends SIGSEGV (segmentation fault) signal to process

page-table-permissions.png

2.1 Permissions Review

Section Read Write Execute
Stack 1 1 0
Heap 1 1 0
Static Data 1 1 0
Literals 1 0 0
Instructions 1 0 1

3 Improving Performance

3.1 Translation Lookaside Buffer (TLB)

  • MMU has to access memory twice: once to get the PTE, and again for the actual memory request
    • we can speed up address translation via a small cache of page table entries (called a translation lookaside buffer (TLB)
      • VPN split into tag and index for this cache
      • modern Intel processors have 128 or 256 entries in TLB

tlb-hit.png

tlb-miss.png

3.1.1 Bringing It All Together

address-translation.png

address-manipulation.png

  • Basic Parameters
    • \(N=2^n\) — Number of addresses in virtual address space
    • \(M=2^m\) — Number of addresses in physical address space
    • \(P=2^p\) — Page size (bytes)
  • Components of the virtual address (VA)
    • VPO — Virtual page offset
    • VPN — Virtual page number
    • TLBI — TLB index
    • TLBT — TLB tag
  • Components of the physical address (PA)
    • PPO — Physical page offset (same as VPO)
    • PPN — Physical page number

3.1.2 Extended Example

  • addressing:
    • 14-bit virtual addresses
    • 12-bit physical addresses
    • 64-byte pages
    • how will virtual and physical addresses be used?

ataddr.png

  • page table
    • only showing first 16 entries (out of how many? one for every virtual page = \(2^{n-p} = 2^8 = 256\))
    • using 2 hex digits for PPN even though it's only 6 bits
    • other management bits not shown

atpt.png

  • translation lookaside buffer
    • 16 entries
    • 4-way associative
    • VPN split into TLB tag (TLBT) and TLB index (TLBI)

attlb.png

  • cache
    • direct-mapped with 4-byte blocks
    • total capacity of 64 bytes (16 blocks)
    • physically addressed
    • physical address split into cache tag (CT), cache index (CI) and cache offset (CO)
    • just a coincidence that PPN is the same width as the cache tag

atcache.png

Request VPN TLBT TLBI TLB hit? page fault? PPN CT CI CO cache hit? data (byte)
0x03d4 0x0f 0x03 3 yes no 0x0d 0x0d 5 0 yes 0x36
0x038f 0x0e 0x03 2 no yes - - - - - -
0x0020 0x00 0x00 0 no no 0x28 0x28 8 0 no -
0x036b 0x0d 0x03 1 yes no 0x2d 0x2d a 3 yes 0x3b