Β§13.1–13.3Early Systems … The Address Space

Part I OSTEP pp. 121–124 Β· ~6 min read

  • virtual address
  • physical address
  • code segment

Early on, building systems was easy β€” users didn’t expect much. It’s those darned users, with their demands of β€œease of use” and β€œhigh performance,” who caused all these headaches. (Thank one, next time you see one.) This chapter earns the memory arc’s vocabulary: what an address space actually is, and why it must be an illusion.

13.1 Early Systems

From memory’s perspective, early machines provided no abstraction at all:

Figure 13.1: the early days β€” one OS, one program, zero illusions
Operating System (code, data, etc.) β“˜0KBCurrent Program (code, data, etc.) β“˜64KB448KB

click a region marked β“˜ for details

13.2 Multiprogramming and Time Sharing

Machines cost hundreds of thousands of dollars, so people shared them: first multiprogramming (switch processes on I/O; raise utilization), then β€” because programmers were tired of agonizing batch debug cycles β€” time sharing and interactivity.

One crude implementation: give the running process all of memory (as in Figure 13.1), and on every switch save its entire memory to disk and load the next process’s. Correct β€” and brutally slow, ever slower as memories grow. Registers are cheap to save; megabytes are not. The fix that stuck: leave processes resident in memory and switch between them:

Figure 13.2: three processes sharing 512KB of physical memory β€” click around
Operating System β“˜0KB(free)64KBProcess C β“˜128KBProcess B β“˜192KB(free)256KBProcess A β“˜320KB(free)384KB(free)448KB512KB

click a region marked β“˜ for details

Residency changed the stakes. With multiple programs in memory at once, protection became critical: nobody should read β€” or worse, write β€” another process’s memory.

13.3 The Address Space

For the pesky users, the OS needs an easy-to-use abstraction of physical memory: the address space β€” the running program’s view of memory. It contains all the memory state of the program: the code (instructions), the heap (malloc/new data), and the stack (call chain, locals, parameters) β€” plus odds and ends like statically-initialized variables:

Figure 13.3: an example address space (a 16KB toy β€” we like simple math)
Program Code β“˜0KBHeap β–Ύ β“˜β–Ό1KB(free) β“˜2KBStack β–΄ β“˜β–²15KB16KB

click a region marked β“˜ for details

Code sits at the top (static, never grows). Heap and stack take the two ends of the remaining space and grow toward each other β€” that’s the convention that lets both expand freely (until threads ruin it, but that’s Part II’s problem).

Now the essential trick. The address space is the abstraction the OS provides β€” the program is not really at physical 0–16KB. Look back at Figure 13.2: process A believes it starts at address 0, but it lives at 320KB. When A loads from address 0, something must quietly redirect that load:

Process Aload from address 0 (virtual)OS + hardwaretranslate β€” invisibly,on every referencePhysical memory320KB (physical)the mantra, mechanized: every user address is virtual; only OS + hardware know the physical truth

A’s load of virtual address 0 lands at physical address 320KB β€” the key to memory virtualization, underlying every modern computer system.

The Crux: How To Virtualize Memory

How can the OS build this abstraction of a private, potentially large address space for multiple running processes (all sharing memory) on top of a single, physical memory?

When the OS pulls this off, it is virtualizing memory: the program thinks it’s loaded at some address (say 0) into a potentially huge space (32 or 64 bits’ worth); reality differs, quietly. The goals that β€œwith style” implies β€” and the tools you have as a user to peek at your own virtual space β€” are next.

Check yourself

1.Why did the save-ALL-of-memory-to-disk approach to time sharing die?

2.What exactly IS an address space?

3.Why are the heap and stack placed at opposite ends of the address space?

4.Process A 'starts at address 0' yet lives at physical 320KB. What must happen when A loads from address 0?

5.Residency (Figure 13.2) made time sharing fast. What problem did it create?

5 questions