- memory management
- memory paging
- memory management unit (MMU)
- virutal memory
- page replacement
- local and global replacement
- page replacement algorithm
- theoretically optimal (OPT)
- not recently used (NRU)
- (referenced, modified)
- (0,0), (0,1), (1,0), (1,1)
- FIFO
- Second-chance
- least recently used (LRU)
- Evict the page that has not been used for the longest time in the past. (“temporal locality”)
- Clock
- not frequently used (NFU)
- aging
- working set
- w(k,t)= pages referenced by the k most recent memory references up to time t.
- approximation for k references:
- w(τ,t)= pages referenced in the past τ time units of virtual time (the amount of CPU time a process actually uses) up to the current time t.
- algorithm:
- in a page fault:
- for each page in memory:
- if R=1, then set τ←t and R←0
- if R=0
- age←t−τ
- if age>τ, then evict the page
- if age≤τ, then keep the page
- if no page is evicted, then evict the page with the largest age
- if all pages have R=1, then evict a page at random
- page fault frequency (PFF)
- reference string R=(r1,r2,…,rk)
- PageFaults(R,n)=∣{ri∈R:ri∈/Frames(i,n)}∣
- n is the number of frames allocated to the process
- Frames(i,n) is the set of pages in memory after processing ri
- distance string
- D=(d1,d2,…,dk)
- di=min{j:ri=ri−j∧j<i}
- if no such j exists, then di=∞
- Bélády’s anomaly
- ∃R,n,m:n<m∧PageFaults(R,n)>PageFaults(R,m)
- thrashing
- fragmentation
- external fragmentation
- internal fragmentation
- buddy memory allocation
- Memory segmentation
- swapping
- allocation algorithms
- first fit - first hole that is big enough to hold the process
- next fit - similar to ‘first fit’ but it starts searching from where the last allocation ended
- best fit - smallest hole that is still big enough for the process
- pros:
- cons: external fragmentation
- worse fit - largest available hole
- quick fit -
- mapping
- bitmap
- linked lists
- free list
- quick fit
- locality of reference (aka the principle of locality)
- Temporal locality
- Spatial locality
- Memory locality (or data locality)
\text{Page frame number} && \text{if present bit = 1}\\
\text{``on disk''} && \text{if present bit = 0}
\end{cases}$$
- virutal memory
- paging
- $\text{page-table}(\text{virtual page number}) = \text{page frame number}$
- **page frame number** (PFN) (which is the physical page number)
- page frame
- dirty bit
- $\# \text{pages} =\# \text{page-table entries} = \frac{\text{virtual memory size}}{\text{page size}}$
- $\text{page size} = 2^{\text{offset bits}}$
- $\text{virtual memory size} = 2^{\text{virtual address bits}}$ (set by the ISA)
- $\text{virtual address bits}= \text{VPN bits} + \text{offset bits}$
- $\text{virtual address} = [\text{VPN}, \text{page offset}]$
- $\text{VPN}= \left\lfloor \frac{\text{virtual address}}{\text{page size}} \right\rfloor$
- $\text{page offset} =\text{virtual address} - \text{VPN} \times \text{page size}$
- $\text{physical memory address} = (\text{page frame number}, \text{page offset})$
- $\text{physical address} = \text{PFN} \times \text{page size} + \text{page offset}$
- $\# \text{page frames} = \frac{\text{physical memory size}}{\text{page size}}$
- $\text{physical memory size} = 2^{\text{physical address bits}}$ (set by the actual RAM installed)
- $\text{physical address bits}= \text{PFN bits} + \text{offset bits}$
- page table entry (PTE) contains:
- page frame number
- present/absent bit
- 1 = in memory
- 0 = on disk (then CPU generates a **page fault** exception)
- protection bits
- read/write/execute permissions
- reference bit
- modified bit
- caching disabled/enabled
- translation lookaside buffer (TLB)
- hard miss
- page walk
- page fault
- Minor page fault
- Major page fault
- segmentation fault
- multilevel page table
- inverted page table (IPT)
- $\mathrm{IPT}(\text{physical frame}) = \text{(process id, virtual page number)}$
- demand paging
# Linux
- address space:
- text segement
- data segment
- initialized data
- uninitialized data, which is called the **block starting symbol** (abbreviated to `.bss` or `bss`. origin: **BSS** from **Block Started by Symbol**)
- initialized to zero after loading
- stack