- The instructions being executed must be in physical memory.
- An examination of real programs shows us that, in many cases, the entire program (in memory) is not needed.
- Programs often have code to handle unusual error conditions (seldom used).
- Arrays, lists, and tables are often allocated more memory than they actually need.
- Certain options and features of a program may be used rarely.
- The ability to execute a program that is only partially in memory would offer many benefits:
- A program would no longer be constrained by the amount of physical memory that is available (simplifying the programming task).
- Because each user program could take less physical memory, more programs could be run at the same time, with a corresponding increase in CPU utilization and throughput but with no increase in response time or turnaround time.
- Less I/O would be needed to load or swap each user program into memory, so each user program would run faster.
- Virtual memory involves the separation of logical memory as perceived by users from physical memory. This separation allows an extremely large virtual memory to be provided for programmers when only a smaller physical memory is available (see Fig. 9.1).
Figure 9.1:
Diagram showing virtual memory that is larger than physical memory.
|
- The virtual address space of a process refers to the logical (or virtual) view of how a process is stored in memory. Typically, this view is that a process begins at a certain logical address-say, address O -and exists in contiguous memory, as shown in Fig. 9.2.
Figure 9.2:
Virtual address space.
|
- The large blank space (or hole) between the heap and the stack is part of the virtual address space but will require actual physical pages only if the heap or stack grows.
- heap to grow upward in memory as it is used for dynamic memory allocation
- stack to grow downward in memory through successive function calls
- Virtual address spaces that include holes are known as sparse address spaces. Using a sparse address space is beneficial because the holes can be filled as the stack or heap segments grow or if we wish to dynamically link libraries (or possibly other shared objects) during program execution.
- In addition to separating logical memory from physical memory, virtual memory also allows files and memory to be shared by two or more processes through page sharing. This leads to the following benefits:
Figure 9.3:
Shared library using virtual memory.
|
- System libraries can be shared by several processes through mapping of the shared object into a virtual address space. Actual pages where the libraries reside in physical memory are shared by all the processes (see Fig. 9.3).
- Similarly, virtual memory enables processes to share memory. Two or more processes can communicate through the use of shared memory (see Fig. 9.3).
- Virtual memory can allow pages to be shared during process creation with the system call, thus speeding up process creation.
Cem Ozdogan
2011-02-14