Virtual Memory
Virtual Memory
Intro
In previous chapter, it tackles about memory-management strategies, and all that strategies have the
same goal; to keep many processes in main memory to allow multi-programming, but it requires that an
entire process be in the memory before it can execute.
Background
The requirement that instructions must be in physical memory to be executed seems both necessary and
reasonable; but it is also unfortunate, since it limits the size of a program to the size of physical memory.
In fact, an examination of real programs shows us that, in many cases, the entire program is not needed.
For instance, consider the following:
• Programs often have code to handle unusual error conditions. Since these errors seldom, if ever, occur
in practice, this code is almost never executed.
• Arrays, lists, and tables are often allocated more memory than they actually need. An array may be
declared 100 by 100 elements, even though it is seldom larger than 10 by 10 elements.
The ability to execute a program that is only partially in memory would confer many benefits:
• A program would no longer be constrained by the amount of physical memory that is available. Users
would be able to write programs for an extremely large virtual address space, 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 user programs 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.
- makes the task of programming much easier, because the programmer no longer needs to worry
about the amount of physical memory available; she can concentrate instead on the problem to
be programmed.
Virtual address space - refers to the logical (or virtual) view of how a process is stored in memory.
- this view is that a process begins at a certain logical address 0 exists in contiguous memory
- physical memory may be organized in page frames and that the physical page frames assigned to
a process may not be contiguous.
- It is up to the memory management unit (MMU) to map logical pages to physical page frames in
memory.
We allow the heap to grow upward in memory as it is used for dynamic memory allocation. Similarly, we
allow for the stack to grow downward in memory through successive function calls.
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.
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 allows files and memory
to be shared by two or more processes through page sharing (Section 8.5.4). This leads to the following
benefits:
System libraries can be shared by many processes through mapping of the shared objects into virtual
address space.
Processes can share memory by mapping readwrite pages into virtual address space
Pages can be shared during process creation with the fork(); speeding up process creation