Modern computers run many processes simultaneously, but physical RAM is finite. The OS must manage how RAM is shared between processes, prevent one process corrupting another's memory, and extend apparent memory capacity using disk storage. Three key techniques: paging, segmentation, and virtual memory.
Paging divides physical memory (RAM) and logical process memory (virtual address space) into fixed-size blocks:
Advantages of paging: eliminates external fragmentation (pages fit exactly into frames); simple allocation algorithm (any free frame will do).
Disadvantages: internal fragmentation (the last page may not be full); overhead of maintaining page tables.
Segmentation divides a process's memory into variable-size logical segments corresponding to the program's structure (code segment, data segment, stack segment, heap segment).
Advantages: reflects natural program structure; segments can grow independently; easier to share code segments between processes.
Disadvantages: variable sizes cause external fragmentation (gaps in memory that are too small to use); more complex allocation than paging.
| Feature | Paging | Segmentation |
|---|---|---|
| Block size | Fixed (e.g. 4 KB) | Variable (based on program structure) |
| Fragmentation | Internal (wasted space within a page) | External (gaps between segments) |
| Logical meaning | None — arbitrary division | Reflects logical program units (code, stack, data) |
| Contiguous? | Pages can be non-contiguous in RAM | Each segment must be contiguous |
| Lookup table | Page table (one per process) | Segment table (one per process) |
Virtual memory is a memory management technique that allows processes to use more memory than is physically available in RAM, by using a portion of secondary storage (hard drive or SSD) as an extension of RAM.
| Algorithm | Description | Notes |
|---|---|---|
| FIFO (First In, First Out) | Replace the page that has been in memory the longest | Simple; can evict frequently used pages |
| LRU (Least Recently Used) | Replace the page that was used least recently | More complex; better performance than FIFO |
| Optimal (OPT) | Replace the page that won't be used for the longest time in the future | Theoretical best; impossible in practice (requires knowing the future) |
Thrashing occurs when the OS spends more time swapping pages in and out of RAM than actually executing process instructions. It happens when a process or set of processes requires more frames than available, causing a constant cycle of page faults. Thrashing severely degrades system performance. Solutions: add more RAM; reduce the number of running processes; use a working set model.
8 questions · 20 marks · instantly marked
| Term | Definition |
|---|