CS 422 - HOMEWORK 3 SOLUTION Page 1 ---------------------------- Version 2, Nov. 18, 1998 Problem 1 --------- Let C = cache hit ratio (probability of a cache hit) = 0.9 M = memory hit ratio = 0.6 Teff = average time to load a word (effective read time) Tcache = time to load a word from cache to CPU = 20 ns Tmemory = time to load a word from memory to cache = 60 ns Tdisk = time to load a word from disk to memory = 12 ms TmemoryEff = effective memory load time Then, Teff = C Tcache + (1-C) TmemoryEff = C Tcache + (1-C) [ M Tmemory + (1-M) Tdisk ] = 0.9 (20 ns) + 0.1 [ 0.6 (60+20) ns + 0.4 (12 ms + 60 ns + 20 ns) ] = 18 ns + 0.1 [ 48 ns + 4.8 ms ] = 18 ns + 4.8 ns + 480 us = 480 us Problem 2 --------- 10 Number of entries in a 1-page page table = 4 KB / 4 = 1,024 = 2 Number of bytes accessible from a 1-page page table = 1 K (4 KB) = 4 MB 20 Number of entries which can be stored in 4 MB = 4 MB / 4 B = 2 Each additional level in the page table increases the number of entries 10 64 by a factor of 2 . A 64-bit address space contains 2 bytes. So, we need to find the minimum integer L such that: 10L 64 52 2 >= 2 / 4 K = 2 So, L = 6. Problem 3 --------- a) Define R0 R1 R0 <-- 0 R1 <-- value of n R2 <-- address of A R3 <-- address of B R4 <-- address of C L2: if (R0 >= R1) goto L1 R5 <-- *R3 // load indirect B[i] R5 <-- R5 + *R4 // add indirect C[i] R5 --> *R2 // store indirect A[i] R0 <-- R0 + 1 R2 <-- R2 + 4 // update pointers R3 <-- R3 + 4 R4 <-- R4 + 4 goto L2 L1: ... b) Suppose the code is in page 0 and the arrays are in consecutive pages in the order A, B, and then C. Since each array is 1 page long, A, B, and C are in pages 1, 2, and 3 respectively. 1) Each instruction fetch references a page 2) Each indirect memory access referenes a page So, the approximate sequence of page references once we enter the loop is: 0, 2, 0, 3, 0, 1, 0, 0, 0, 0, 0, ... repeats ... Problem 4 --------- a) 1) Optimal: Unknown because we don't know the future page references 2) FIFO: Frame 3 because it has been in memory the longest (loaded first) 3) LRU: Frame 1 because it is the least recently referenced (oldest reference time) 4) Clock: It's not clear how we got to this state since all frames have been referenced in the interval 160-163. The use bits must have been reset at time 160. Either frame 0 or 1 since the use bit is 0. But is probably frame 0 since it has been loaded the longest. 5) Enhanced Second Chance: Frame 1 since its use and modify bits are both 0. b) The reference string is: 1, 2, 0, 3, 4, 0, 0, 0, 0, 2, 4, 2, 1, 0, 3, 2 where the first 4 are from the table. Below, we show the window as it shifts to the right. 1, 2, 0, 3, 4, 0, 0, 0, 0, 2, 4, 2, 1, 0, 3, 2 ---------- ---------F ---------- ---------- ---------- ---------- ---------F ---------F ---------- ---------F ---------F ---------F ---------- So, 6 faults.