Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 10

CSC468/2204 TUTORIAL WEEK 8

by Tristan Miller -- Updated 7 November 2000

OVERVIEW OF TODAYS TUTORIAL announcements regarding A2Q1 page replacement overview of A2Q2 page replacement algorithms questions & answers

ANNOUNCEMENTS REGARDING A2Q1 clarifications regarding previous tutorial (briefly): o for FCFS tie-breaking rule, select the process that has been in the system the longest o job service and interarrival times are figured as real numbers, not integers after you generate the random numbers, do not round off to the nearest integer o except for round-robin, preemptions should be performed only when new processes arrive o the HRRN algorithm presented in tutorial was a preemptive version; the assignment calls for a non-preemptive

implementation all the above clarifications are explained in detail on the newsgroup

tutorial

notes

are

now

available

on

the

web

at

http://www.cs.utoronto.ca/~psy/teaching/2000/468f/ suggested reading list for discrete event simulation is available on the newsgroup diagram of discrete event simulation:
Generate service time,s1, for job 1. j Generate interarrival time, t2, for job 2. j

Generate interarrival time, t0, for job 0 j

t0

i= 0

ti
t

t1+t0

Generate service time,s0, for job 0. j Generate interarrival time, t1, for job 1. j

Generate service time, sn, for jobjn. Generate interarrival time, , for tn+1 job jn+ 1.

non-preemptive schedulers need to recompute priorities only when a process finishes executing except for round-robin, preemptive schedulers need to recompute priorities only a process arrives or finishes

for round-robin, the scheduler needs to recompute priorities when a process finishes or one quantum after a process begins executing (whichever is sooner) your simulation can conveniently ignore the time between events just advance the clock to the next event (i.e. a process arrival, a process completion, or the end of a round-robin quantum) instead of waiting

remember, no scheduling algorithm, including round robin, will allow the CPU to remain idle while there are waiting jobs

PAGE REPLACEMENT each process is allocated frames (memory) which hold the processs pages (data) frames are filled with pages as needed this is called demand paging over-allocation of memory is prevented by modifying the page-fault service routine to replace pages the job of the page replacement algorithm is to decide which page gets victimized to make room for a new page page replacement completes separation of logical and physical memory

OVERVIEW OF A2Q2 given a certain memory size and a sequence of page numbers (the reference string), use each of three different page replacement algorithms to determine the performance

calculate, tabulate, and graph page faults vs. number of frames

the performance calculations should be done with as few passes of the reference string as possible i.e. even though there are nine different test cases (3 algorithms 3 parameters each), you may not have to run a simulation nine times

PAGE REPLACEMENT ALGORITHMS Optimal algorithm ideally we want to select an algorithm with the lowest page-fault rate

such an algorithm exists, and is called (unsurprisingly) the optimal algorithm:

procedure: replace the page that will not be used for the longest time (or at all) i.e. replace the page with the greatest forward distance in the reference string example using 4 frames:
Reference # Page referenced Frames _ = faulting page 1 1 1 2 2 1 2 3 3 1 2 3 4 4 1 2 3 4 5 1 1 2 3 4 6 2 1 2 3 4 7 5 1 2 3 5 8 1 1 2 3 5 9 2 1 2 3 5 1 0 3 1 2 3 5 1 1 4 4 2 3 5 12 5 4 2 3 5

analysis: 12 page references, 6 page faults, 2 page replacements. Page faults per number of frames = 6/4 = 1.5 unfortunately, the optimal algorithm requires special hardware (crystal ball, magic mirror, etc.) not typically found on todays computers

optimal algorithm is still used as a metric for judging other page replacement algorithms

FIFO algorithm replaces pages based on their order of arrival: oldest page is replaced example using 4 frames:
Reference # Page referenced Frames _ = faulting page 1 1 1 2 2 1 2 3 3 1 2 3 4 4 1 2 3 4 5 1 1 2 3 4 6 2 1 2 3 4 7 5 5 2 3 4 8 1 5 1 3 4 9 2 5 1 2 4 1 0 3 5 1 2 3 1 1 4 4 1 2 3 12 5 4 5 2 3

analysis: 12 page references, 10 page faults, 6 page replacements. Page faults per number of frames = 10/4 = 2.5

LFU algorithm (page-based) procedure: replace the page which has been referenced least often

for each page in the reference string, we need to keep a reference count. All reference counts start at 0 and are incremented every time a page is referenced.

example using 4 frames:


Reference # Page referenced Frames _ = faulting page
n

1 1 11

2 2 11 12

3 3 11 12 13

4 4 11 12 13 14

5 1 21 12 13 14

6 2 21 22 13 14

7 5 21 22 15 14

8 1 31 22 15 14

9 2 31 32 15 14

1 0 3 31 32 23 14

1 1 4 31 32 23 24

12 5 1 32 25 24
3

= reference

count

at the 7th page in the reference string, we need to select a page to be victimized. Either 3 or 4 will do since they have the same reference count (1). Lets pick 3. likewise at the 10th page reference; pages 4 and 5 have been referenced once each. Lets pick page 4 to victimize. Page 3 is brought in, and its reference count (which was 1 before we paged it out a while ago) is updated to 2. analysis: 12 page references, 7 page faults, 3 page replacements. Page faults per number of frames = 7/4 = 1.75

LFU algorithm (frame-based) procedure: replace the page in the frame which has been referenced least often

need to keep a reference count for each frame which is initialized to 1 when the page is paged in, incremented every time the page in the frame is referenced, and reset every time the page in the frame is replaced

example using 4 frames:


Reference # Page referenced Frames _ = faulting page
n

1 1 11

2 2 11 12

3 3 11 12 13

4 4 11 12 13 14

5 1 21 12 13 14

6 2 21 22 13 14

7 5 21 22 15 14

8 1 31 22 15 14

9 2 31 32 15 14

1 0 3 31 32 13 14

1 1 4 31 32 13 24

12 5 1 32 15 24
3

= reference

count

at the 7th reference, we victimize the page in the frame which has been referenced least often -- in this case, pages 3 and 4 (contained within frames 3 and 4) are candidates, each with a reference count of 1. Lets pick the page in frame 3. Page 5 is paged in and frame 3s reference count is reset to 1. at the 10th reference, we again have a page fault. Pages 5 and 4 (contained within frames 3 and 4) are candidates, each with a count of 1. Lets pick page 4. Page 3 is paged into frame 3, and frame 3s reference count is reset to 1. analysis: 12 page references, 7 page faults, 3 page replacements. Page faults per number of frames = 7/4 = 1.75

LRU algorithm replaces pages based on their most recent reference replace the page with the greatest backward distance in the reference string example using 4 frames:
Reference # Page referenced Frames _ = faulting page 1 1 1 2 2 1 2 3 3 1 2 3 4 4 1 2 3 4 5 1 1 2 3 4 6 2 1 2 3 4 7 5 1 2 5 4 8 1 1 2 5 4 9 2 1 2 5 4 1 0 3 1 2 5 3 1 1 4 1 2 4 3 12 5 5 2 4 3

analysis: 12 page references, 8 page faults, 4 page replacements. Page faults per number of frames = 8/4 = 2

one possible implementation (not necessarily the best): o every frame has a time field; every time a page is referenced, copy the current time into its frames time field o when a page needs to be replaced, look at the time stamps to find the oldest

PFF algorithm thus far, all the algorithms presented assume each process is granted a fixed amount of memory (i.e. number of frames) in the real world, different processes have different memory requirements allocating too few frames to a process may result in that process thrashing (rapid concentrated page replacement) allocating too many frames to a process may result in other processes thrashing PFF aims to prevent thrashing by allocating or deallocating frames as required procedure: o every frame has a reference bit (initially 0) o whenever a page is referenced, set its frames reference bit o when a page fault occurs, compare the IFT (inter-fault time) with a certain threshold o if IFT < threshold, allocate a new frame to the process and reset all reference bits

o if IFT threshold, deallocate all frames whose reference bit is

not set, allocate a new frame for the faulting page, and reset all reference bits example with threshold = 3:
Reference # Page referenced Frames * = reference bit set _ = faulting page 2 2 3 2 3 4 1 1 1 2 2 1 3 3 1 4 4 1 5 1 * 1 2 3 4 6 2 * 1 * 2 3 4 5 5 7 5 1 2 8 1 * 1 2 9 2 * 1 * 2 1 0 3 1 2 1 1 4 1 2 12 5 1 2

5 3 3 4 3 4 5

since the number of frames allocated to a process is dynamic with this algorithm, when performing the analysis, use the mean number of frames in use per reference

in the above example, there were 39 frames in use over 12 page references, so the mean number of frames is 39/12 = 3.25

analysis for the above example: 12 page references, 8 page faults. Page faults per number of frames = 8/3.25 2.4615

You might also like