Operating systems

Introduction to paging

Prashanth L.A.

2023-09-11

Lecture 18

So far

 

What’s wrong with segmentation?

 

Paging

Concept

Advantages of Paging

Disadvantages

Example

(Virtual Page 0 → Physical Frame 3), (VP 1 → PF 7), (VP 2 → PF 5), and (VP 3 → PF 2)

Address translation

movl <virtual address>, %eax

Address space \(= 64\) bytes, so \(6\) bits needed

Page size \(= 16\) bytes, so first two bits give VPN

VPN \(\rightarrow\) virtual page number, Offset: offset within the page

Address translation (contd)

movl 21, %eax

Size does matter

  • 32-bit address space, 4KB pages \(\Rightarrow\) 20-bit VPN and 12-bit offset

  • 20-bit VPN \(\Rightarrow 2^{20}\) translations

  • 4 bytes/page table entry (PTE) \(\Rightarrow 4MB\) of memory needed for each page table!

  • \(100\) processes would need 400MB of memory just for all those address translations!

Bottomline: Cannot store page tables in MMU of HW

Lecture 19

What is in the page table?

Common flags in a page table entry

Bit Description
Valid bit Indicating whether the particular translation is valid
Protection bit Indicating whether the page could be read from, written to, or executed from
Present bit Indicating whether this page is in physical memory or on disk
Dirty bit Indicating whether the page has been modified since it was brought into memory
Reference bit Indicating that a page has been accessed

Example: x86 Page Table Entry

P: present, R/W: read/write, U/S: supervisor, A: accessed bit, D: dirty bit, PFN: the page frame number

Accessing memory with paging

// Extract the VPN from the virtual address
VPN = (VirtualAddress & VPN_MASK) >> SHIFT

// Form the address of the page-table entry (PTE)
PTEAddr = PTBR + (VPN * sizeof(PTE))

// Fetch the PTE
PTE = AccessMemory(PTEAddr)

// Check if process can access the page
if (PTE.Valid == False)
    RaiseException(SEGMENTATION_FAULT)
else if (CanAccess(PTE.ProtectBits) == False)
    RaiseException(PROTECTION_FAULT)
else
    // Access is OK: form physical address and fetch it
offset = VirtualAddress & OFFSET_MASK
PhysAddr = (PTE.PFN << PFN_SHIFT) | offset
Register = AccessMemory(PhysAddr)

Problems that can be solved

Paging problems

Too slow

PT too big

A detailed example on address translation using paging

Done on the board