Information Technology Reference
In-Depth Information
program might print \hello world". The kernel must copy the string out of the
application's memory region into the screen buer.
Although the base and bounds mechanism is sucient for implementing
protection, it is unable to provide some important features:
Expandable heap and stack. With a single base and bound per process,
the memory allocated to a process's heap and stack must be xed at the
time the program is loaded into physical memory.
Memory sharing. Base and bounds does not allow memory to be shared
between different processes, as would be useful for sharing code between
multiple processes running the same program.
Non-relative memory addresses. For base and bounds, the location
of procedures and data within a program are determined at runtime, when
the program is copied from disk to memory. Thus, any instruction with
an absolute physical address (such as a procedure call) would need to be
changed as part of loading a program into memory.
Memory fragmentation. Once a program has started, it becomes
nearly impossible to relocate it, as its physical addresses may be stored
in registers or on the program's execution stack, for example, as return
addresses. Over time, as applications start and finish at irregular times, if
memory cannot be re-compacted, it will become increasingly fragmented.
Potentially, memory fragmentation may reach a point where there is not
enough contiguous space to start a new process, even when there is enough
memory in aggregate.
For these reasons, most modern processors introduce a level of indirection,
called virtual addresses. With virtual addresses, every process's memory starts
Definition: virtual
addresses
at the same place, e.g., zero. Each process thinks that it has the entire machine
to itself, although obviously that is not the case in reality. The hardware trans-
lates these virtual addresses to the physical location of the process in memory,
e.g., by adding the base register to every virtual address.
In practice, systems provide even more complex algorithms for translating
between virtual and physical addresses. As we will see in later chapters, this
level of indirection provides an enormous amount of flexibility for the operating
system to eciently manage its physical memory. For example, virtual addresses
can allow the heap and the stack to start at separate ends of the virtual address
space, so that they can grow according to the particular needs of each program.
We illustrate this in Figure 2.6. Note that if the stack or heap grow beyond
their initially allocated regions, the operating system can assign them a larger
slot in physical memory, copy the stack or heap to the new location in physical
memory, but leaving them in the same location in virtual memory. The copy is
then completely transparently to the user process. We will discuss this in more
depth in a later chapter.
 
Search WWH ::




Custom Search