|
|
COMP2300 - TuteLab 08
COMP2300 / COMP6300
Tutorial / Laboratory 08 - Virtual Memory in PeANUt
Semester 1, 2009
Week 10 (11 -- 15 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 09 am Tuesday 19 May (week 11), which
will contribute up to 1% of your assessment (in the Tute/Lab mark).
Objectives
There are several objectives in this exercise:
- To deepen your understanding of procedures, traps and bit operations
in PeANUt.
- To improve your understanding of how virtual memory (paging)
is implemented on the PeANUt machine.
- To improve your understanding of how the LRU and FIFO paging
policies can be implemented, and of the paging characteristics
of each.
Preparation
NOTE: 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.
Preparation Exercises
Complete the following questions on a separate sheet of paper, with your
name and student number clearly written. Please ensure your writing is
legible. Hand in to your tutor at the beginning of your tutorial /
laboratory session.
- What is meant by the terms page and page frame?
- What is a page fault? When does it happen?
- What is the role of the dirty bit? Where is it found?
- What is thrashing?
Tutorial Exercises
- What sequence of paging events take place when a program is first
being run (on a real machine)?
- What are the possible (worst-case) chain of events that can happen in the
PeANUt machine during a load instruction between an address
being loaded into the MAR and the data appearing in the
MDR?
- It is said that the LRU page replacement policy is far better than
the FIFO. What does this statement mean? Why would we expect it to be
so?
- On the PeANUt machine,
suppose page 810 is present in physical memory
page frame 5 and a store to address a401 has
just been executed. Suppose also that 3 page faults have occurred since
it was first loaded into physical memory. Write the corresponding page
table entry for the page, in terms of a diagram and in terms of binary
and hexadecimal numbers.
- What is the largest working set (in number of pages as well as
number of cells) possible for a PeANUt program before the system starts
thrashing? Hint: how many pages must be reserved for VM?
Laboratory Exercises
It 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
- In your comp2300 folder, create a new directory called
lab8.
- Copy the files /dept/dcs/comp2300/public/lab8/* into
your lab8 folder.
Part 1: Experimenting with PeANUt Virtual Memory
Part 2: Further Experiments
The 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 Pages
As 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.
- Make a copy of vmfifo.ass and call it vmfifoa.ass.
Open vmfifoa.ass with your favorite text editor.
- Modify the page fault service routine so that it never
swaps out page 2 (as well as pages 0 and 1). Note that you will
probably have to redefine the data for SwCtOPr,
as now the maximum value of the Swap Count will be reduced.
- Test vmfifoa.ass. You should find that page 2 never gets
swapped out. What is the advantage, what is the disadvantage in
locking in three pages rather than two?
Hint: run both programs and compare VMMStats
at the end of each run.
Part 2b: Using the Dirty Bit
You 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.
- Make a copy of vmfifoa.ass and call it vmfifob.ass.
Open vmfifob.ass with your favorite text editor.
- Modify the page fault service routine to check the dirty
bit (this should involve adding a few lines, including an
if statement guarding the call to trap #13).
Insert code to implement putchar('*'); in this
if statement, to signify when the trap #13 was
called.
Your routine should not write pages back unless it is dirty.
Note that a loadxr instruction may now be needed in the
code before putchar('A'+XR);. Note also that if the page is
dirty, the putchar('*'); occurs before this.
Also note that if trap #13 is not called,
PT[XR] must be
explicitly zeroed by the handler (to signify it has been
swapped out).
- Modify the main program so it writes values back into even numbered pages
4, 6, 8, 10, ..., 30.
(so the dirty bits get set for these pages only).
Make sure you don't write into
pages 0, 1 or 2, as you would overwrite the page table, page
fault handler or the main program!
Note that it does not matter what values you write or where
in the page you write them (for the purpose of this exercise
or its automated marking). It is important though
that only the hander routine produces any output (trap #3).
However, you need to ensrure that your main program does not
spill over into the 4th page; oterwise this could alter them
pageing behaviour.
- Test your program. Check that pages 4, 6, 8, etc have been updated
(these pages start at addresses a400, a600,
a800 etc in Secondary VMMStats
that only 11 pages have been written out.
- Once working, do a final correctness check on it and the previous
program with the command:
previewAutoMark lab8 vmfifoa.ass vmfifob.ass
When satisfied, submit it using the submit command:
submit comp2300 lab8 vmfifoa.ass vmfifob.ass
submit comp6300 lab8 vmfifoa.ass vmfifob.ass
This is due by 09 am Tuesday May 19 (the deadline is strict)
and will contribute up to 1% of your Tute/Lab mark.
Part 2c: Different Paging Policies
So 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 page table so that page 0 is least-recently used.
- Experiment with vmlru.ass. This 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. Compare the operation (and resulting performance)
of the LRU algorithm with FIFO.
- For this example, redefining FstULPg to 1 (or 0) alone is
sufficient to allow page 1 (or 0) to be swapped out. However, for
vmfifo.ass, we needed to change SwCtOPr as well. Why
is this?
Code for vmfifo.ass
Click here
for the code.
Last modified: 20/05/2009, 10:43
|