Virtual memory is a technique that allows a system to use a limited amount of real memory to represent a much larger virtual address space. This larger address space must be addressable by the cpu. Current Pentium CPUs are capable of addressing 4Gig of memory or more eve though it both physically difficult and incredibly expensive to create a system having that much real memory.
The virtual memory mechanism divides both the virtual memory address space and real physical memory into evenly sized units called page frames. When a memory address in one of pages in virtual memory is accessed, the virtual page is moved to one of the physical page frames.
The primary feature of virtual memory is the use of a table, called the page table, to track which physical page frame contains a particular virtual page.
The page table contains 1 entry for each virtual address page. The number of entries in the page table is equal to the size of virtual memory divided by the size of a page.
Each page table entry has a 1 to 1 relation with a particular virtual address page, eg. page table slot 0 always handles the status of virtual page 0. Each page table entry has two fields, a present/absent field and the page id of physical memory where the virtual page resides if present.
The page id field must be large enough to specify any physical page id.
A particular virtual page may be loaded into any physical page frame and will function correctly.
Part 1. For this first part, you are working with a system that has 1K page frames, 4K of physical memory and 16K of virtual memory.
A program consisting of several subroutines and that accesses several blocks of memory containing arrays of numbers is described below. The address of each part of the program and of each data array is provided. Each part of the program fits in a page of memory.
You are to create a picture of the page table at various points during the execution of the program.
The following shows the layout of virtual memory when the program is running.
| Routine | Virtual Memory | Function |
| Start Address | ||
| Main | 0K | Driver program to invoke other routines |
| Init | 1K | Zeros out arrays passed to it |
| Load | 2K | Loads specified array with data from file |
| Add | 3K | Puts the sum of 2 arrays into a third |
| 4K | Prints the contents of an array |
| Data | VM Address |
| Num1 | 5K |
| Num2 | 6K |
| Total | 7K |
Assume the following program is loaded and run. When 1st started, it will load the Main routine into a page frame and each of the arrays in each of the other page frames in order of declaration.
The numbered lines indicate when to describe the contents of the page table for the assignment. Work though the program twice, 1st showing the table state using First In First Out (FIFO) for selecting which page to page out when all physical page frames are full.
Then repeat the exercise using Least Recently Used (LRU) for selecting which page to page out when all physical page frames are full.
To prepare, answer these two questions.
A. How many bits are needed to keep track of the physical pages? ____
B. How many page entries are there in the page table? ____
Hand draw each Page Table for you answers. Remember, the page table has only two fields per row, the Present/Absent field and the index of the physical (real) page frame
********************
Main() int Num1[256], Num2[256], Total[256]
1. Show page table
Init( Total )
3. Show page table
Load( Num1, File1 )
5. Show page table
Load( Num2, File2 )
7. Show page table
Add( Total, Num1, Num2 )
9. Show page table
Print( Total )
10. Show page table
Exit
********************
********************
Init( TArray )
For i = 0 to 255
2. Show page table
********************
********************
Load( Array, Fname )
I = 0
Open Fname
While ( Not = EOF )
4. & 6. Show page table (called twice from main)
********************
********************
Add( TArray, Array1, Array2 )
For i = 0 to 255
8. Show page table
********************
********************
Print( Array )
For i = 0 to 255
*******************