![]() |
Faculty of Engineering and Information Technology (FEIT)
Department of Computer Science
|
COMP2300Tutorial / Laboratory 08 - Virtual Memory in PeANUt
Semester 1, 2008 Week 10 (12 -- 16 May)
Note that for this session, there are some Preparation Exercises. Also for this session, there is a submitable laboratory exercise which is due by 10 am Tuesday 20 May (week 11), which will contribute up to 1% of your assessment (in the Tute/Lab mark). ObjectivesThere are several objectives in this exercise:
PreparationNOTE: This laboratory requires you to read the detailed description of the operation of PeANUt Virtual Memory that appears in Section 3 of the PeANUt Specification. It is highly desirable that you read this in advance of your laboratory. Reading the rest of this document in advance will be helpful too. You will waste your lab time and miss out on opportunities to ask your tutor relevant questions if you do not prepare adequately.
Tutorial Exercises
Laboratory ExercisesIt is expected that you work through Part 1 as well as Part 2 (up to at least Part 2a) in the supervised lab for this session, and that you continue with Parts 2 and 3 in your own time. Preliminaries
Part 1: Experimenting with PeANUt Virtual Memory
Part 2: Further ExperimentsThe page fault service routine in vmfifo.ass is rather simplistic in a number of ways. There are a number of steps that can be taken to improve the page fault service routine.
Part 2a: Locking in Further PagesAs explained earlier, the page fault service routine of vmfifo.ass ensures that pages 0 and 1 are never swapped out (see definition of FstULPg). This is very important, because if either of those pages were swapped out, the PeANUt would not be able to either access the page table or call the page fault service routine, and so would come to a grinding halt very quickly. If you are unsure about this, try redefining SwCtOPr to have the same value as SwPrMsk, and FstULPg to 1 (or 0), and then see what happens.One of the limitations of the page fault service routine of vmfifo.ass is that it only has 26 memory cells of page one to fit into (the first six cells of page one are used to store registers and the number of the page to be swapped in). This space restriction means that the routine must be kept simple.
Part 2b: Using the Dirty BitYou may have noticed that the Dirty bit has been largely ignored until now. In the <swap out page XR>; code, the page to be removed is copied from main memory to secondary memory (trap #13). This is necessary because something may have been written to that page since it was swapped in and that information should not just be thrown away. In fact, often pages are swapped out that have not had anything written to them. Remembering that on real systems, reading and writing between main memory and secondary memory is very slow, a lot of time could be saved if pages were only written back to main memory when really necessary.The dirty bit is provided for just this reason. If a page is dirty it should be written back to main memory, otherwise it can be discarded (because the copy in main memory is identical). Now that page three is locked in, you should have enough space to add lines to the page fault service routine that check the dirty bit before writing the page back.
Part 2c: Different Paging PoliciesSo far you have only looked at the FIFO paging policy. The program vmlru.ass is very similar to vmfifo.ass, except that it relies on the LRU (Least Recently Used) strategy and so uses the Last Used field of the page table entries. Note that it initializes the poage tbale so that page 0 is least-recently used.
Code for vmfifo.ass
; vmfifo.ass: PeANUt assembler file for COMP2300 Lab 8, 2007
;
; This file demonstrates PeANUt Virtual Memory in operation. The paging
; algorithm here is a *basic* FIFO algorithm. This algorithm has the following
; weaknesses:
; i) It relies on all page frames being pre-loaded.
; ii) It always writes back (no Dirty bit check).
; The program included here accesses each page in memory.
; As it accesses pages not swapped in, page faults occur.
; As each page fault occurs, two characters are printed, a character corres-
; ponding to the page to be swapped out, and a character corresponding to the
; page to be swapped in. Page 0 is represented by "A", Page 1 "B" and
; Page 31 by "`".
;
; The page-fault handling routine starts at a46 (as it must). The test program
; starts at page 2.
; /* Define initial page table contents (pages 0-7 swapped in, remainder out) */
; /* PT must be at address 0 */
; volatile short int PT[] = {
PT: data %00000 000 111 0 1 000 ; 0x00e8,
data %00000 000 110 0 1 001 ; 0x00c9,
data %00000 000 101 0 1 010 ; 0x00aa,
data %00000 000 100 0 1 011 ; 0x008b,
data %00000 000 011 0 1 100 ; 0x006c,
data %00000 000 010 0 1 101 ; 0x004d,
data %00000 000 001 0 1 110 ; 0x002e,
data %00000 000 000 0 1 111 ; 0x000f,
;
block 24 ; 0,0,0,0, 0,0,0,0, 0,0,0,0,
; 0,0,0,0, 0,0,0,0, 0,0,0,0
; } /* PT */
; /* next 6 memory loc. are reserved for the OS*/
block 5 ; /* for saving registers on page faults*/
; /* PgFtNum must be at address 37 = a45*/
PgFtNum:block 1 ; volatile short int PgFtNum;
; /*on trap #11, OS puts # of page causing fault*/
; /* VM-related macros for PeANUt */
PageSz = 32 ; #define PageSz 32 /* page size */
LastPg = 31 ; #define LastPg 31 /* number of last page*/
SwapOut = 13 ; #define SwapOut 13 /* trap # to swap out */
SwapIn = 12 ; #define SwapIn 12 /* trap # to swap in */
; /* FIFOPgSwap() must be at address 38 = a46 */
FIFOPgSwap: ; void FIFOPgSwap(void) {
; /* post: implements a FIFO page swap algorithm */
FstULPg = 2 ; #define FstULPg 2 /* # of 1st unlocked page */
setxr #FstULPg; short int XR = FstULPg;
FIFOwh: load *PT ; while ( (PT[XR]
and SwPrMsk ; & SwPrMsk)
cmp SwCtOPr ; != SwCtOPr ) {
beq FIFOewh ; /* seek PT entry with Swap Count=5 & Present=1 */
incxr #1 ; XR = XR + 1;
load #LastPg ; if (XR > LastPg)
cmpxr ; break; /* an error, to be trapped later;... */
ble FIFOwh ; /* ... prevents an inf. loop here */
FIFOewh: ; } /* while */
load *PT ; PT[PgFtNum] = (PT[XR] & FramMsk);
and FramMsk ; /* fill in frame # of PT entry for new page */
store @PgFtNum; /* new page goes to same frame as page to be swapped out */
loadxr ; <swap out page XR>;
trap #SwapOut;
add #'A' ; putchar('A'+XR);
trap #3 ; /*letter corresp. to this page*/
load PgFtNum ; <swap in page PgFtNum>;
trap #SwapIn ;
add #'A' ; putchar('A'+PgFtNum);
trap #3 ;
load #'\n' ; putchar("\n');
trap #3 ;
ret ; } /* FIFOPgSw() */
; Bit masks used in page fault service routine.
SwPrMsk:data %00000 000 111 0 1 000 ; const short int SwPrMsk = 0x00e8,
; /*Swap count & Present bit mask*/
SwCtOPr:data %00000 000 101 0 1 000 ; SwCtOPr = 0x00a8,
; /*Swap count=5 (Oldest), Present=1 */
FramMsk:data %00000 000 000 0 0 111 ; FramMsk = 0x0007;
; /* frame number mask */
LstPg: data 991 ; const int LstPg = 991; /*addr. of start last page-1*/
; int main() {
main: setxr #0 ; short int *XR = NULL; /* implement via XR*/
; do {
mloop: load *0 ; <access *XR>;
incxr #PageSz ; XR += PageSz;
load LstPg ;
cmpxr ; } while (XR <= (int *) LstPg);
ble mloop ;
trap #1 ; exit(0);
end main ; } /* main() */
Last modified: 19/05/2008, 17:49
|
Please direct all enquiries to:
Page authorised by: Head of Department, DCS |
| The Australian National University — CRICOS Provider Number 00120C |