ยง15.5โ€“15.6Operating System Issues โ€ฆ Summary

Part I OSTEP pp. 149โ€“152 ยท ~6 min read

  • internal fragmentation

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

Figure 15.4: Dynamic relocation โ€” operating system responsibilities
what the OS must do
Memory managementallocate at creation, reclaim at exit, run the free list
Base/bounds managementsave + restore the pair on every context switch
Exception handlinginstall handlers at boot; react to violations
Dotted-underlined cells have explanations โ€” click one.

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:

Figures 15.5 + 15.6: limited direct execution, now with dynamic relocation โ€” bold-badged steps are privileged
OS(kernel mode)
Hardware
Program(user mode)
Phase 1 โ€” at boot
Phase 2 โ€” running
step 1 / 20 ยท time flows downward

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:

The cost of the simple approach: internal fragmentation inside the 16KB slot
code32KBheap33KBallocated but UNUSED โ€” pure waste โ“˜34KBstack46KB48KB

click a region marked โ“˜ for details

That waste โ€” unused space inside the allocated unit โ€” is internal fragmentation , 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?

4 questions