Next, due to the TLB, best time is always: 1ns (TLB) + 30ns (physical addr) = 31ns. The TLB has an associative memory of <page#, frame#> pairs, not page directory, so the pages can be found instantly.
Direct paging
Time for page fault: 1ns (TLB) + 30ns (page table, page fault) + 5ms (write) + 5ms (locate and load from swap) $\approx$ 10ms
Motivation: With $M$ processes, we have $M$ page tables, but only $N$ memory frames can be occupied ($N < M$ overhead).
Inverted PT : frame $\mapsto$ <pid, page#>. [PHYSICAL $\mapsto$ VIRTUAL]. Then lookup with the VIRTUAL memory.
Input: <pid, page#, D>: pid to O(n) lookup IPT for page#. Once found, the index $i$ is the frame.
Pros: huge memory savings (all pages for all processes in one table)
Cons: very slow translation (O(n) lookup for IPT for correct PID.)
Time and Memory space
Suppose each entry is 8B, bigger than the PTE due to PID.
Time: Going through every frame i.e. $2^{20}(30)$ns.
Memory Space:
Number of frames: $2^{32-12} = 2^{20}$
Size of table: $2^{20} (8)$ = 8MB
Page Replacement Algorithms
When a page must be evicted:
Identify the process and page number in the chosen frame
If no IPT: Scan through every process’s page table.
Mark old process as non-memory resident.
Mark new process as memory resident.
Memory references are modelled as memory reference strings, a sequence of page numbers. $p_0, p_1, \dots$
$T_\text{access} = (1 - p)T_\text{mem} + pT_\text{page fault}$: a good algo minimizes page faults i.e. $p$, and thus $T_\text{access}$.
Optimal Page Replacement (OPT)
Replaces the page that won’t be used for the longest time
i.e. CRITERIA: Time of Next Usage
Prediction necessary
Theoretically unfeasible
First in First out (FIFO)
Evicts the oldest memory page created
i.e. CRITERIA: Time of Page Creation
Simple queue maintained by OS, dequeue and enqueue during page fault
Pros: HW support not needed
Cons:
Belady’s anomaly: As frames increase, so do page faults.
Increased frame count means the changes the order of item removal (different set of last N frames created)
Least Recently Used (LRU)
CRITERIA: Time of last usage
Pros:
Temporal locality
No Belady’s anomaly (same for all stack algorithms, because top N frames order are always the same)
Approximates OPT
Cons:
Needs substantial HW support
Implementation A: use a counter.
Search through all pages in table for least recently used frame
Logical time is forever increasing (overflow)
Implementation B: stack.
If frame X in stack is reference, it is removed from where it is and pushed to the top.
Replace page at stack bottom as needed
Hard to do HW support
Second-Change Page Replacement (CLOCK)
Modified FIFO.
If reference bit = 0: page is replaced
If reference bit = 1: page ref bit set to 0
Degenerates into FIFO once all pages are 1 or 0.
Reference bit marking
Circular nature
Frame Allocation Policies
$M$ policies and $N$ frames.
Equal allocation: each process gets $N/M$
Proportional allocation: each process gets $\frac{x_i}{X} (N)$ frames for $X$ memory space, $x_i$ being size of process $i$.
Global Replacement: Process A can steal a frame from Process B
Pros: Dynamic adjustment of memory usage
Cons: Cascading Thrashing (Process A steals B’s frame, leading to B stealing C’s frame…)
Local replacement:
Pros: Performance is stable (frames/process remains constant throughout), limits thrashing to that process.
Cons: If not enough frames allocated, hinder progress
Thrashing: Heavy I/O to bring pages into RAM means a single process can hog I/O and degrade other processes’ performance
Working Set
Set of pages in the virtual address space of the process that are currently resident in physical memory.
Observation: Set of pages currently used typically remains constant in a short period (locality).
Set changes gradually over time
Working set window $\Delta$: one interval of logical time
W(t, $\Delta$ ): active pages within $\Delta$ of time t. Allocate just enough frames for pages in W(t, \Delta) for each time t
MMU - Hardware component
CPU needs page 2
Memory management unit (MMU) checks TLB
If in TLB, then MMU can just access the frame directly
Not in TLB, MMU accesses the page table (in memory space of OS)
Not in page, MMU signals a page fault and control passed to OS.
The MMU may also generate illegal access error/invalid page faults leading to segfaults/bus errors.
OS brings from secondary storage to the physical memory.
The page table is not in the PCB. Rather it is connected by links, and held in a register (page directory register) which is populated at the context switch