Monday, January 26, 2009

Address Space

The address space of a process contains all of the memory state of the running program. For example, the code of the program (the instructions) have to live in memory somewhere, and thus they are in the address space. The program, while it is running, uses a stack to keep track of where it is in the function call chain as well as to allocate local variables and pass parameters and return values to and from routines. Finally, the heap is used for dynamically-allocated, user-managed memory.

0    |---------------------|
4 | program code | all the instructions
... | | live up in this part
| |
1K |---------------------|
| heap | the heap contains all
| | malloc(new) data
| | structures
2K |---------------------| [it grows downward]
| | |
| v |
| |
| |
| |
| |
| |
| free |
| |
| |
| |
| |
| |
| |
| ^ |
| | | [it grows upward]
15k |---------------------| stack contains local
| stack |stack-alloc variables,
| |arguments to routines,
16k |---------------------| return variables, etc.

FIGURE: ADDRESS SPACE
--
0    |---------------------|
4 | Operating System |
... | (code, data, etc.) |
| |
64k |---------------------|
| process A |
| (code, data, etc.) |
| |
| |
128k|---------------------|
| process B |
| (code, data, etc.) |
196k|---------------------|
| |
| (free) |
256k|---------------------|
| process C |
| (code, data, etc.) |
| |
322k|---------------------|
| |
| (free) |
| |
| |
| |
512k|---------------------|

FIGURE: SHARING 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 does this, we say the OS is virtualizing memory
How done? Base + Bound registers, Base:start location, Bound: max location
On every memory, compare logical address (virtual address) and bound. if LA > Bound --> error. (the processor will first add the base to the virtual address to get the desired physical address, but then it will check if the physical address is within the base and bounds. If not, the processor will signal some kind of fault and the process will likely be terminated. The point of the bounds is thus to make sure that all addresses generated by the process are legal and within the "bounds" of the process).

Physical address = virtual address + Base
The process generates a virtual address; the hardware in turn adds the contents of the base register to this address and the result is a real physical address that can be issued to the memory system. This entire process is called address translation
The base and bounds registers are hardware structures kept on the chip and managed by the CPU. the processor that helps with this type of address translation the memory management unit (MMU:run-time mapping from virtual to physical address).

Segmentation: Instead of having just one base and bounds pair in our MMU, divide Address Space into 'logical' segments, each has Base/Bound per segment.

No comments:

Post a Comment