CS 540 - Operating Systems - Homework 3 - Name:_________________ Assigned: Friday, April 2, 2004 Due: Monday, April 12, 2004 (in class) Please show all work on a separate sheet attached to this sheet. (50 points) 1. Consider a swapping system in which memory consists of the following hole sizes in memory order: 10K, 4K, 20K, 18K, 7K, 9K, 12K, and 15K. Which hole is taken for successive segment requests of: (a) 12K (b) 10K (c) 9K for first fit? Now repeat the question for best fit, worst fit, and next fit. (8 points) Ans: First fit: (a) 20K (b) 10K (c) 18K Best fit: (a) 12K (b) 10K (c) 9K Worst fit: (a) 20K (b) 18K (c) 15K Next fit: (a) 20 KB (b) 18K (c) 9K 2. A swapping system eliminates holes by compaction. Assuming a random distribution of many holes and many data segments and a time to read or write a 32-bit memory word of 10 nsec, about how long does it take to compact 128 MB? For simplicity, assume that word 0 is part of a hole and that the highest word in memory contains valid data. (5 points) Ans: 128 x 2^20 / 4 = 2^25 memory address compaction time = (read + write) * # of memory access = 2 x 10 x 10 ^ -9 x 2^25 = 671 ms 3. A machine has 48-bit virtual addresses and 32-bit physical addresses. Pages are 8 KB. How many entries are need for the page table? (5 points) Ans: 2^48/2^13 = 2^35 = 2^5 * 2^30 = 32 G entries 4. The overhead required to read an entry in memory (including the time to access associative memory) is 110 nanoseconds when the page number is not in the associative memory. The computer has an associative memory that can hold 16 entries and can be accessed in 10 nanoseconds. a. Find a formula that expresses the effective access time as a function of the hit ratio. b. What hit ratio is needed to reduce the effective access time to 80 nanoseconds? (10 points) Ans: Assume the memory access time is t. 2t + 10 = 110. Then t = 50 Assume the hit ratio is h. a. EAT = h (50 + 10) + (1 - h) 110 = 60 h + 110 - 110 h = 110 - 50 h b. 110 - 50 h <= 80 50 h >= 30 h >= 60% 5. A small computer has four page frames. At the first clock tick, the R bits are 0111 page 0 is 0, the rest are 1). At subsequent clock ticks, the values are 1011, 1010, 1101, 0010, 1010, 1100, and 0001. If the aging algorithm is used with an 8-bit counter, give the values of the four counters after the last tick. (5 points) Ans: Page 0: 01101110 Page 1: 01001001 Page 2: 00110111 Page 3: 10001011 6. A computer has four page frames. The time of loading, time of last access, and the R and M bits for each page are as shown below (the times are in clock ticks): Page Loaded Last Ref. R M 0 126 280 1 0 1 230 265 0 1 2 140 270 0 0 3 110 285 1 1 (a) Which page will NRU replace? (b) Which page will FIFO replace? (c) Which page will LRU replace? (d) Which page will second chance replace? (8 points) Ans: (a) Page 2 because R M = 0 0 (b) Page 3 because it is loaded at 110 (First In) (c) Page 1 because is referenced at 265 (Least Recently) (d) Page 2 because it is loaded at 140 and R M = 0 0. 7. If FIFO page replacement is used with three page frames and eight virutal pages, how many page faults will occur with the reference string 01723271035423 if the three frames are initially empty? Now repeat the problem for LRU and Optimal. (9 points) Ans: FIFO: 11 Page Faults 0 1 7 2 3 2 7 1 0 3 5 4 2 3 0 1 7 2 3 3 3 1 0 0 5 4 2 3 0 1 7 2 2 2 3 1 1 0 5 4 2 0 1 7 7 7 2 3 3 1 0 5 4 P P P P P P P P P P P LRU: 12 Page Faults 0 1 7 2 3 2 7 1 0 3 5 4 2 3 0 1 7 2 3 2 7 1 0 3 5 4 2 3 0 1 7 2 3 2 7 1 0 3 5 4 2 0 1 7 7 3 2 7 1 0 3 5 4 P P P P P P P P P P P P Optimal: 9 Page Faults 0 1 7 2 3 2 7 1 0 3 5 4 2 3 0 0 0 2 2 2 2 2 2 2 2 2 2 2 1 1 1 3 3 3 3 3 3 3 3 3 3 7 7 7 7 7 1 0 0 5 4 4 4 P P P P P P P P P Note: To get full points, students need to show steps to get the result. If students didn't show the steps, give one point deduction for each algorithm.