Beruflich Dokumente
Kultur Dokumente
Extra-Credit (15 points) c) Simulate a fully-associative cache that has 32 lines, where each line can hold one
byte only. Use the second-chance algorithm that approximates LRU replacement. The Second-Chance algorithm is actually a FIFO replacement algorithm with a small modification that causes it to approximate LRU. FIFO alone means first-in-first-out, that is, the cache entry that was first loaded in will be the first one to be replaced. To implement a FIFO-scheme you need to keep track of the order in which entries were loaded into the cache. If you've taken CS15 or if you know data structures called "lists", they'll be the obvious tool to implement a FIFO-scheme (actually, a circular list is the way to go). If you dont know lists, you can still work on this problem using a little hack: - Reserve a global variable (integer) called RefCount that initially has value 0. - To every cache entry, associate an integer value called "stamp". When an entry isl loaded into the cache, make it's "stamp" take value RefCount, and then make RefCount++. If you look through all entries, you can spot the one with the minimum stamp and that will be the first one that was loaded, that is, the first one to be replaced according to the FIFO-scheme. The flaw in this is that eventually, for many more references than you will see in this homework problem, RefCount would overflow, but we don't need to worry about that. Searching for the minimum every time you look for a replacement candidate will make your simulator a bit inefficient, but this hack will still work. You can now implement Second-Chance on top of this FIFO-scheme. Assume that every cache entry has an associated R bit, which indicates whether this entry has been recently referenced or not. When the entry is first loaded into the cache, we make its R=1. Whenever an entry is referenced, even if there's no replacement search going on, we make it's R=1. When an entry is selected for replace search going on, we make it's R=1. When an entry is selected for replacement according to the FIFO order, we check its R bit. Note that this entry will be the one in the cache with the lowest "stamp" value. If R=1, the entry was referenced recently, so we clear it (giving it the promised second-chance), move it to the end of the FIFO and look for another candidate to replace (the one now at the head of the FIFO). If you're using the hack above, moving an entry to the end will be equivalent to changing its "stamp" to RefCount and doing RefCount++. Also, searching for the next candidate in line for replacement according to our FIFO-hack means that we'll look for the entry for which "stamp" = "previous stamp" + 1. If that one also has R=1, we move on to the next, and the next, and the next... until we find one entry with R=0. That will be the one to replace. If we happen to search through the entire cache and find R=1 for all entries, we go back and replace the oldest entry in the cache.
b) It is fair to assume that if you read a sector in this disk, you're likely to read the next one as part of the same read operation. "Skew" is defined to be the number of sectors between the last sector of one track and the first sector of the next, as shown in the diagrams below (N = sectors per track, s = skew). Disks often have different amounts of skew: a value used when switching tracks on the same cylinder and another when switching cylinders. Compute the optimal values of skew for cylinder switch and for track switch.