Virtual Memory Operating System
- OS takes care of all aspects of address translation
- gives the user process the illusion that it has its own address space starting from 0
- the user process address space can be larger than main memory
- thus, the actual size of the user process ( 7 pages in our previous example) can be larger than
main memory
- load the pieces of the process that are needed immmediately during execution
- other parts of the process can be stored in the swap space (backing store)
Assumptions:
- instructions being used must be in main memory
- operands must be in main memory
- swap space (disk) must be large enough to hold all parts of all processes currently in execution
Disadvantages:
- can be slow because the running process stops whenever a required page is in the swap space
Advantages:
- can have processes larger than available memory
- OS, not the programmer, manages the details
- performance is satisfactory when we have "locality of reference"
Locality
- Two types: spatial locality and temporal locality
- Real programs in execution tend to display both types of locality
Spatial Locality:
- references to addresses close to the current address (in the virtual address space)
- natural occurrence in our programs
- e.g. may be using instructions within a few pages and data from
a few pages for a relatively long time
- to deal with slowly changing spatial locality,
the OS may to use prediction (prepaging)
Temporal Locality
- next address will be one that has been used recently
(use some instructions over and over)
- loops have both types of locality
- paging takes care of most of the temporal locality problems (pages in 4k blocks)
Reference String (Address String)
- sequence of addresses generated by a process
Simple Address Translation
P = V + B
where P is the physical address,
V is the virtual address, and
B is the base address of a contiguous chunk of memory.
Virtual and Physical Addressing
Address Binding
- apply the address translation function to a program or process
- also called the address mapping function
Ways to do this:
1. Static binding (old scheme)
- bind before execution time
- process must execute in the same area of memory (loader loads it into this area)
i) Absolute code - compiler generates code with the physical address
ii) Relocatable code - loader translates the address in the object module into the physical address
2. Dynamic Binding
- delay address binding until execution time
- use relocation registers (called segment base registers ;
based on the beginning of the program or page)
- binds a unit of code every time it re-enters main memory
- sets the base register
- all addresses have the value from the base register added on before being used
A good scheme:
- more flexible (OS can move the process around)
- needs hardware assistance
- adds base register to every address before usage
i) Dynamic loading
- subprograms are loaded when they are called
- stored on disk in relocatable format (code to use a base register)
- advantage: unused routines are not loaded
- loaded on basis of segments (or pages)
- subprograms are all present in the load module
ii) Dynamic linking
- link the system library functions when called at execution time rather than
at load time
- library subprograms are not present in the load module
Table of Contents