CSC 394 · Operating Systems
Our notes
2 min readBasics
- Logical (virtual) address: generated by the program. Physical address: the real location in RAM. The MMU (memory management unit) translates one to the other.
- Address binding can happen at compile time, load time or run time (run-time binding allows programs to move in memory).
- Swapping: moving a whole process out to disk and back.
Contiguous allocation
Each process gets one block of memory.
- Fixed partitions: memory divided in advance; wasted space inside a partition is internal fragmentation.
- Variable partitions: blocks made to fit; free holes appear between processes, external fragmentation. Compaction moves processes together to join holes (costly).
Placement strategies (worked)
Free holes: 100K, 500K, 200K, 300K, 600K (in that order). Requests: 212K, 417K, 112K, 426K.
| Strategy | 212K | 417K | 112K | 426K |
|---|---|---|---|---|
| First fit (first hole big enough) | 500K (288 left) | 600K (183 left) | 288K (176 left) | waits |
| Best fit (smallest hole big enough) | 300K (88 left) | 500K (83 left) | 200K (88 left) | 600K (174 left) |
| Worst fit (largest hole) | 600K (388 left) | 500K (83 left) | 388K (276 left) | waits |
Here best fit places all four.
Paging
Physical memory is cut into fixed-size frames, and logical memory into pages of the same size. A page table maps each page to a frame. No external fragmentation (a little internal fragmentation in each process's last page).
- Logical address = (page number p, offset d). With page size 2ⁿ, the low n bits are the offset.
Worked example. Page size 1 KB (1,024 bytes). Logical address 3,500: p = 3500 ÷ 1024 = 3 remainder 428, so d = 428. If the page table maps page 3 to frame 7, the physical address = 7 × 1024 + 428 = 7,596.
Worked example (bits). 32-bit addresses, 4 KB pages (2¹²): offset 12 bits, page number 20 bits → up to 2²⁰ (about a million) pages per process.
- TLB (translation look-aside buffer): a small fast cache of recent page-table entries. Effective access time = hit ratio × (TLB + memory) + miss ratio × (TLB + 2 × memory). With TLB 20 ns, memory 100 ns, hit ratio 80%: 0.8 × 120 + 0.2 × 220 = 96 + 44 = 140 ns.
- Large page tables are split up: multilevel (hierarchical) or inverted page tables.
Segmentation
Memory is divided into variable-size segments that match the program's logical parts (code, data, stack, functions). Address = (segment number, offset); the segment table holds base and limit for each. An offset ≥ limit is an error (trap). Matches the programmer's view, but causes external fragmentation.
Worked example. Segment 2 has base 4,300 and limit 400. Address (2, 53) → 4,300 + 53 = 4,353. Address (2, 500) → 500 ≥ 400 → trap (invalid).
Paging vs segmentation
| Paging | Segmentation |
|---|---|
| fixed-size pages | variable-size segments |
| invisible to the programmer | follows the program's structure |
| internal fragmentation | external fragmentation |
Many systems combine them (segmented paging).
Exams usually ask: logical vs physical addresses; internal vs external fragmentation; first/best/worst fit on given holes; page number and offset calculations; physical address from a page table; TLB effective access time; segmentation address translation.
Common mistake: in paging, adding the page number to the frame number. The physical address is frame number × page size + offset.
Written by the UniHive team in our own words. Spotted a mistake? Tell us on WhatsApp.
Read
-
Best pick OSTEP: Paging: Introduction
Free chapter PDF from the authors' site (114 KB).
(opens pages.cs.wisc.edu in a new tab)
-
OSTEP: The Abstraction: Address Spaces
Free chapter PDF from the authors' site (93 KB).
(opens pages.cs.wisc.edu in a new tab)
-
OSTEP: Paging: Faster Translations (TLBs)
Free chapter PDF from the authors' site (147 KB).
(opens pages.cs.wisc.edu in a new tab)
-
Introduction to Computer Science, 6.4 Memory Management
(opens openstax.org in a new tab)
OpenStax, Introduction to Computer Science, 6.4 Memory Management, CC BY-NC-SA 4.0 · licence
-
Memory paging
(opens en.wikipedia.org in a new tab)
Wikipedia, Memory paging, CC BY-SA 4.0 · licence
-
Memory segmentation
(opens en.wikipedia.org in a new tab)
Wikipedia, Memory segmentation, CC BY-SA 4.0 · licence
We link to free material and never copy it. Every link was opened by our team before it went up.