Operating systems

Advanced page tables

Prashanth L.A.

2023-09-19

Lecture 21 (contd)

The crux

How to make page tables smaller

Why does size matter?

Simple solution: Bigger pages

Example

 

Problem with bigger pages?

What a waste!

A 16KB Address Space With 1KB Pages Page Table For 16KB Address Space

Hybrid Approach: Paging and Segments

Example: Hybrid approach

32-bit address space with 4KB pages

Seg value Content
00 unused segment
01 code
10 heap
11 stack

Three base/bounds pairs per process

TLB miss on Hybrid Approach

SN           = (VirtualAddress & SEG_MASK) >> SN_SHIFT
VPN          = (VirtualAddress & VPN_MASK) >> VPN_SHIFT
AddressOfPTE = Base[SN] + (VPN * sizeof(PTE))

Hybrid approach: pros and cons

Advantage over linear page table

Disadvantages

Lecture 22

Multi-level PT

Data structure

Page directory: To track whether a page of the PT is valid

Linear vs. multi-level PTs

Left Right
  • Linear PT
  • most of the middle regions of the address space are not valid
  • require PT space allocated for those regions
  • Multi-level PT
  • Page directory (PD) marks just two pages of PT as valid
  • PD: two-level table

Page directory entry (PDE)

Poll: Advantages and disadvantages of multi-level PTs

Multi-level PT

Advantages

Disadvantages

Detailed example

16-KB address space with 64-byte pages

Detailed example (contd)

Detailed example (contd)

Lecture 23

A Page Directory, And Pieces Of Page Table

Address translation in the detailed example

Two-level Page Table Control Flow

VPN = (VirtualAddress & VPN_MASK) >> SHIFT
(Success, TlbEntry) = TLB_Lookup(VPN)
if (Success == True)   // TLB Hit
  if (CanAccess(TlbEntry.ProtectBits) == True) 
    Offset = VirtualAddress & OFFSET_MASK 
    PhysAddr = (TlbEntry.PFN << SHIFT) | Offset 
    Register = AccessMemory(PhysAddr)
  else
      RaiseException(PROTECTION_FAULT)
else // TLB Miss
  // first, get page directory entry
PDIndex
PDEAddr
PDE
if (PDE.Valid == False)
= (VPN & PD_MASK) >> PD_SHIFT
= PDBR + (PDIndex * sizeof(PDE)) = AccessMemory(PDEAddr)
    RaiseException(SEGMENTATION_FAULT)
else
  // PDE is valid: now fetch PTE from page table
  PTIndex = (VPN & PT_MASK) >> PT_SHIFT
  PTEAddr = (PDE.PFN << SHIFT) + (PTIndex * sizeof(PTE)) 
  PTE = AccessMemory(PTEAddr)
  if (PTE.Valid == False)
    RaiseException(SEGMENTATION_FAULT)
  else if (CanAccess(PTE.ProtectBits) == False)
    RaiseException(PROTECTION_FAULT)
  else
      TLB_Insert(VPN, PTE.PFN, PTE.ProtectBits) 
      RetryInstruction()

Other things