The hardware brought registers and exceptions; now the OS must hold up its end. Four duties, at four critical junctures:
15.5 Operating System Issues
| what the OS must do | |
|---|---|
| Memory management | allocate at creation, reclaim at exit, run the free list |
| Base/bounds management | save + restore the pair on every context switch |
| Exception handling | install handlers at boot; react to violations |
Creation: search the free list for a slot, mark it used, set up the space. Termination: put the memory back on the free list, clean the process structures. Context switch: save and restore the base/bounds pair via the PCB โ and, while a process is descheduled, the OS may even move its whole address space (copy, update saved base, resume; the process never knows). Exceptions: install handlers at boot; when a process strays out of bounds, terminate it with prejudice.
Here is the whole dance โ chapter 6โs LDE protocol, upgraded with translation. Watch for the rows where the OS column is empty:
Four handlers now: system call, timer, illegal memory access, illegal instruction. The memory handlers are the new arrivals.
The shape is unmistakably limited direct execution: the OS sets up the hardware and gets out of the way; processes run at full speed with per-reference translation done silently by the MMU; the OS reappears only at interrupts, at switches, and when someone misbehaves.
15.6 Summary
Address translation gives the OS control over every memory access while keeping the illusion โ and the speed โ intact. Base and bounds is its simplest form: one addition, one comparison, real protection (without which a process could overwrite the trap table and own the machine).
But look at what the fixed slot costs us:
click a region marked โ for details
That waste โ unused space inside the allocated unit โ is internal fragmentation internal fragmentation Wasted space INSIDE an allocated unit โ e.g., the unused gap between heap and stack in a fixed base/bounds slot. defined in ch. 15 โ open in glossary , and itโs baked into the fixed-slot design. (A fixed-size stack region would limit recursion; not appealing either.) We need machinery that allocates closer to whatโs actually used. The first attempt: generalize base and bounds into segmentation โ and finally learn why itโs called a segmentation fault.
Homework: relocation.py
Translate by hand, then check: run seeds 1โ3 and compute each virtual addressโs fate (in bounds โ translation; out โ fault); find the bounds value that makes ALL of a runโs addresses legal; find the maximum base that still fits the space in physical memory; then graph the fraction of valid addresses as the bounds grows. Get it at ostep-homework.Check yourself
1.In the runtime protocol, which party performs the address translations while Process A runs normally โ and how often does the OS participate?
2.What did the context switch gain in this chapter?
3.Process B executes a load that's out of bounds. Trace the machinery.
4.Why does base-and-bounds inevitably produce internal fragmentation?