• 沒有找到結果。

Mass-Storage Structure

在文檔中 OPERATING SYSTEM CONCEPTS (頁 73-85)

68 Chapter 14 Mass-Storage Structure

Answer:

a. New requests for the track over which the head currently resides can theoretically arrive as quickly as these requests are being serviced.

b. All requests older than some predetermined age could be “forced” to the top of the queue, and an associated bit for each could be set to indicate that no new request could be moved ahead of these requests. ForSSTF, the rest of the queue would have to be reorganized with respect to the last of these “old” requests.

c. To prevent unusually long response times.

d. Paging and swapping should take priority over user requests. It may be desirable for other kernel-initiatedI/O, such as the writing of file system metadata, to take precedence over userI/O. If the kernel supports real-time process priorities, theI/O requests of those processes should be favored.

14.2 Suppose that a disk drive has 5000 cylinders, numbered 0 to 4999. The drive is currently serving a request at cylinder 143, and the previous request was at cylinder 125. The queue of pending requests, inFIFOorder, is

86, 1470, 913, 1774, 948, 1509, 1022, 1750, 130

Starting from the current head position, what is the total distance (in cylinders) that the disk arm moves to satisfy all the pending requests, for each of the following disk-scheduling algorithms?

a. FCFS b. SSTF c. SCAN d. LOOK

e. C-SCAN Answer:

a. The FCFSschedule is 143, 86, 1470, 913, 1774, 948, 1509, 1022, 1750, 130. The total seek distance is 7081.

b. TheSSTFschedule is 143, 130, 86, 913, 948, 1022, 1470, 1509, 1750, 1774. The total seek distance is 1745.

c. TheSCANschedule is 143, 913, 948, 1022, 1470, 1509, 1750, 1774, 4999, 130, 86. The total seek distance is 9769.

d. TheLOOKschedule is 143, 913, 948, 1022, 1470, 1509, 1750, 1774, 130, 86. The total seek distance is 3319.

e. TheC-SCANschedule is 143, 913, 948, 1022, 1470, 1509, 1750, 1774, 4999, 86, 130. The total seek distance is 9813.

f. (Bonus.) TheC-LOOKschedule is 143, 913, 948, 1022, 1470, 1509, 1750, 1774, 86, 130.

The total seek distance is 3363.

14.3 From elementary physics, we know that when an object is subjected to a constant acceler-ation a, the relacceler-ationship between distance d and time t is given by d = 12at2. Suppose that,

Answers to Exercises 69

during a seek, the disk in Exercise 14.2 accelerates the disk arm at a constant rate for the first half of the seek, then decelerates the disk arm at the same rate for the second half of the seek. Assume that the disk can perform a seek to an adjacent cylinder in 1 millisecond and a full-stroke seek over all 5000 cylinders in 18 milliseconds.

a. The distance of a seek is the number of cylinders that the head moves. Explain why the seek time is proportional to the square root of the seek distance.

b. Write an equation for the seek time as a function of the seek distance. This equation should be of the form t = x + y

p

L, where t is the time in milliseconds and L is the seek distance in cylinders.

c. Calculate the total seek time for each of the schedules in Exercise 14.2. Determine which schedule is the fastest (has the smallest total seek time).

d. The percentage speedup is the time saved divided by the original time. What is the percentage speedup of the fastest schedule overFCFS?

Answer:

a. Solving d = 12at2for t gives t =

p

(2d/a).

b. Solve the simultaneous equations t = x + y

p

L that result from (t = 1, L = 1) and (t = 18, L = 4999) to obtain t = 0.7561 + 0.2439

p

L.

c. The total seek times are: FCFS65.20;SSTF31.52;SCAN62.02;LOOK40.29;C-SCAN 62.10; (andC-LOOK40.42). Thus,SSTFis fastest here.

d. (65.20;31.52)/ 65.20 = 0.52 The percentage speedup ofSSTFoverFCFSis 52%, with respect to the seek time. If we include the overhead of rotational latency and data transfer, the percentage speedup will be less.

14.4 Suppose that the disk in Exercise 14.3 rotates at 7200RPM. a. What is the average rotational latency of this disk drive?

b. What seek distance can be covered in the time that you found for part a?

Answer:

a. 7200 rpm gives 120 rotations per second. Thus, a full rotation takes 8.33 ms, and the average rotational latency (a half rotation) takes 4.167 ms.

b. Solving t = 0.7561 + 0.2439

p

L for t = 4.167 gives L = 195.58, so we can seek over 195 tracks (about 4% of the disk) during an average rotational latency.

14.5 The accelerating seek described in Exercise 14.3 is typical of hard-disk drives. By contrast, floppy disks (and many hard disks manufactured before the mid-1980s) typically seek at a fixed rate. Suppose that the disk in Exercise 14.3 has a constant-rate seek rather than a constant-acceleration seek, so the seek time is of the form t = x + yL, where t is the time in milliseconds and L is the seek distance. Suppose that the time to seek to an adjacent cylinder is 1 millisecond, as before, and is 0.5 milliseconds for each additional cylinder.

a. Write an equation for this seek time as a function of the seek distance.

b. Using the seek-time function from part a, calculate the total seek time for each of the schedules in Exercise 14.2. Is your answer the same as it was for Exercise 14.3(c)?

c. What is the percentage speedup of the fastest schedule overFCFSin this case?

70 Chapter 14 Mass-Storage Structure

Answer:

a. t = 0.95 + 0.05L

b. FCFS362.60; SSTF95.80;SCAN497.95; LOOK174.50; C-SCAN500.15; (andC-LOOK 176.70).SSTFis still the winner, andLOOKis the runner-up.

c. (362.60;95.80)/ 362.60 = 0.74 The percentage speedup ofSSTFoverFCFSis 74%, with respect to the seek time. If we include the overhead of rotational latency and data transfer, the percentage speedup will be less.

14.6 Write a Java program for disk scheduling using theSCANandC-SCANdisk-scheduling algorithms.

Answer: Please refer to the supporting Web site for source code solution.

14.7 Compare the performance ofC-SCANandSCANscheduling, assuming a uniform distri-bution of requests. Consider the average response time (the time between the arrival of a request and the completion of that request’s service), the variation in response time, and the effective bandwidth. How does performance depend on the relative sizes of seek time and rotational latency?

Answer:

There is no simple analytical argument to answer the first part of this question. It would make a good small simulation experiment for the students. The answer can be found in Figure 2 of Worthington et al. [1994]. (Worthington et al. studied theLOOKalgorithm, but similar results obtain forSCAN. Figure 2 in Worthington et al. shows thatC-LOOK has an average response time just a few percent higher thanLOOKbut thatC-LOOKhas a significantly lower variance in response time for medium and heavy workloads. The intuitive reason for the difference in variance is thatLOOK(andSCAN) tend to favor re-quests near the middle cylinders, whereas theC-versions do not have this imbalance. The intuitive reason for the slower response time ofC-LOOKis the “circular” seek from one end of the disk to the farthest request at the other end. This seek satisfies no requests.

It only causes a small performance degradation because the square-root dependency of seek time on distance implies that a long seek isn’t terribly expensive by comparison with moderate length seeks.

For the second part of the question, we observe that these algorithms do not schedule to improve rotational latency; therefore, as seek times decrease relative to rotational latency, the performance differences between the algorithms will decrease.

14.8 Is disk scheduling, other thanFCFSscheduling, useful in a single-user environment? Ex-plain your answer.

Answer: In a single-user environment, theI/Oqueue usually is empty. Requests gener-ally arrive from a single process for one block or for a sequence of consecutive blocks. In these cases,FCFSis an economical method of disk scheduling. ButLOOKis nearly as easy to program and will give much better performance when multiple processes are perform-ing concurrentI/O, such as when a Web browser retrieves data in the background while the operating system is paging and another application is active in the foreground.

14.9 Explain whySSTF scheduling tends to favor middle cylinders over the innermost and outermost cylinders.

Answer: The center of the disk is the location having the smallest average distance to all other tracks. Thus the disk head tends to move away from the edges of the disk. Here is another way to think of it. The current location of the head divides the cylinders into two groups. If the head is not in the center of the disk and a new request arrives, the new

Answers to Exercises 71

request is more likely to be in the group that includes the center of the disk;, thus, the head is more likely to move in that direction.

14.10 Requests are not usually uniformly distributed. For example, a cylinder containing the file systemFATor inodes can be expected to be accessed more frequently than a cylinder that only contains files. Suppose you know that 50 percent of the requests are for a small, fixed number of cylinders.

a. Would any of the scheduling algorithms discussed in this chapter be particularly good for this case? Explain your answer.

b. Propose a disk-scheduling algorithm that gives even better performance by taking advantage of this “hot spot” on the disk.

c. File systems typically find data blocks via an indirection table, such as aFATinDOS or inodes inUNIX. Describe one or more ways to take advantage of this indirection to improve the disk performance.

Answer:

a. SSTFwould take greatest advantage of the situation.FCFScould cause unnecessary head movement if references to the “high-demand” cylinders were interspersed with references to cylinders far away.

b. Here are some ideas. Place the hot data near the middle of the disk. ModifySSTFto prevent starvation. Add the policy that if the disk becomes idle for more than, say, 50 ms, the operating system generates an anticipatory seek to the hot region, since the next request is more likely to be there.

c. Cache the metadata in primary memory, and locate a file’s data and metadata in close physical proximity on the disk. (UNIXaccomplishes the latter goal by allocat-ing data and metadata in regions called cylinder groups.)

14.11 Why is rotational latency usually not considered in disk scheduling? How would you modifySSTF,SCAN, andC-SCANto include latency optimization?

Answer: Most disks do not export their rotational position information to the host.

Even if they did, the time for this information to reach the scheduler would be subject to imprecision and the time consumed by the scheduler is variable, so the rotational position information would become incorrect. Further, the disk requests are usually given in terms of logical block numbers, and the mapping between logical blocks and physical locations is very complex.

14.12 How would use of aRAMdisk affect your selection of a disk-scheduling algorithm? What factors would you need to consider? Do the same considerations apply to hard-disk scheduling, given that the file system stores recently used blocks in a buffer cache in main memory?

Answer: Disk scheduling attempts to reduce the overhead time of disk head position-ing. Since aRAMdisk has uniform access times, scheduling is largely unnecessary. The comparison betweenRAMdisk and the main memory disk-cache has no implications for hard-disk scheduling because we only schedule the buffer cache misses, not the requests that find their data in main memory.

14.13 Why is it important to balance file systemI/Oamong the disks and controllers on a system in a multitasking environment?

Answer: A system can only perform at the speed of its slowest bottleneck. Disks or disk controllers are frequently the bottleneck in modern systems as their individual

per-72 Chapter 14 Mass-Storage Structure

formance cannot keep up with that of theCPUand system bus. By balancingI/Oamong disks and controllers, neither an individual disk nor a controller is overwhelmed, so that bottleneck is avoided.

14.14 What are the tradeoffs involved in rereading code pages from the file system versus using swap space to store them?

Answer: If code pages are stored in swap space, they can be transferred more quickly to main memory (because swap space allocation is tuned for faster performance than general file system allocation). Using swap space can require startup time if the pages are copied there at process invocation rather than just being paged out to swap space on demand. Also, more swap space must be allocated if it is used for both code and data pages.

14.15 Is there any way to implement truly stable storage? Explain your answer.

Answer: Truly stable storage would never lose data. The fundamental technique for stable storage is to maintain multiple copies of the data, so that if one copy is destroyed, some other copy is still available for use. But for any scheme, we can imagine a large enough disaster that all copies are destroyed.

14.16 The reliability of a hard-disk drive is typically described in terms of a quantity called mean time between failures (MTBF). Although this quantity is called a “time,” theMTBFactually is measured in drive-hours per failure.

a. If a disk farm contains 1000 drives, each of which has a 750,000 hourMTBF, which of the following best describes how often a drive failure will occur in that disk farm:

once per thousand years, once per century, once per decade, once per year, once per month, once per week, once per day, once per hour, once per minute, or once per second?

b. Mortality statistics indicate that, on the average, a U.S. resident has about 1 chance in 1000 of dying between ages 20 and 21 years. Deduce theMTBFhours for 20 year olds. Convert this figure from hours to years. What does thisMTBFtell you about the expected lifetime of a 20 year old?

c. The manufacturer claims a 1-million hourMTBFfor a certain model of disk drive.

What can you say about the number of years that one of those drives can be expected to last?

Answer:

a. 750,000 drive-hours per failure divided by 1000 drives gives 750 hours per failure—

about 31 days or once per month.

b. The human-hours per failure is 8760 (hours in a year) divided by 0.001 failure, giving a value of 8,760,000 “hours” for theMTBF. 8760,000 hours equals 1000 years. This tells us nothing about the expected lifetime of a person of age 20.

c. TheMTBFtells nothing about the expected lifetime. Hard disk drives are generally designed to have a lifetime of 5 years. If such a drive truly has a million-hourMTBF, it is very unlikely that the drive will fail during its expected lifetime.

14.17 The term “fast wideSCSI-II”denotes aSCSIbus that operates at a data rate of 20 megabytes per second when it moves a packet of bytes between the host and a device. Suppose that a fast wideSCSI-IIdisk drive spins at 7200RPM, has a sector size of 512 bytes, and holds 160 sectors per track.

Answers to Exercises 73

a. Estimate the sustained transfer rate of this drive in megabytes per second.

b. Suppose that the drive has 7000 cylinders, 20 tracks per cylinder, a head switch time (from one platter to another) of 0.5 millisecond, and an adjacent cylinder seek time of 2 milliseconds. Use this additional information to give an accurate estimate of the sustained transfer rate for a huge transfer.

c. Suppose that the average seek time for the drive is 8 milliseconds. Estimate theI/Os per second and the effective transfer rate for a random-access workload that reads individual sectors that are scattered across the disk.

d. Calculate the random-access I/Os per second and transfer rate for I/O sizes of 4 kilobytes, 8 kilobytes, and 64 kilobytes.

e. If multiple requests are in the queue, a scheduling algorithm such asSCANshould be able to reduce the average seek distance. Suppose that a random-access work-load is reading 8-kilobyte pages, the average queue length is 10, and the scheduling algorithm reduces the average seek time to 3 milliseconds. Now calculate theI/Os per second and the effective transfer rate of the drive.

Answer:

a. The disk spins 120 times per second, and each spin transfers a track of 80 KB. Thus, the sustained transfer rate can be approximated as 9600 KB/s.

b. Suppose that 100 cylinders is a huge transfer. The transfer rate is total bytes divided by total time. Bytes: 100 cyl * 20 trk/cyl * 80 KB/trk, i.e., 160,000 KB. Time: rotation time + track switch time + cylinder switch time. Rotation time is 2000 trks / 120 trks per sec, i.e., 16.667 s. Track switch time is 19 switch per cyl * 100 cyl * 0.5 ms, i.e., 950 ms. Cylinder switch time is 99 * 2 ms, i.e., 198 ms. Thus, the total time is 16.667 + 0.950 + 0.198, i.e., 17.815 s. (We are ignoring any initial seek and rotational latency, which might add about 12 ms to the schedule, i.e. 0.1%.) Thus the transfer rate is 8981.2 KB/s. The overhead of track and cylinder switching is about 6.5%.

c. The time per transfer is 8 ms to seek + 4.167 ms average rotational latency + 0.052 ms (calculated from 1 / (120 trk per second * 160 sector per trk)) to rotate one sec-tor past the disk head during reading. We calculate the transfers per second as 1/(0.012219), i.e., 81.8. Since each transfer is 0.5 KB, the transfer rate is 40.9 KB/s.

d. We ignore track and cylinder crossings for simplicity. For reads of size 4 KB, 8 KB, and 64 KB, the correspondingI/Os per second are calculated from the seek, rota-tional latency, and rotarota-tional transfer time as in the previous item, giving (respec-tively) 1/(0.0126), 1/(0.013), and 1/(0.019). Thus we get 79.4, 76.9, and 52.6 transfers per second, respectively. Transfer rates are obtained from 4, 8, and 64 times these I/Orates, giving 318 KB/s, 615 KB/s, and 3366 KB/s, respectively.

e. From 1/(3+4.167+0.83) we obtain 125I/Os per second. From 8 KB perI/Owe obtain 1000 KB/s.

14.18 More than one disk drive can be attached to aSCSIbus. In particular, a fast wideSCSI-II bus (see Exercise 14.17) can be connected to at most 15 disk drives. Recall that this bus has a bandwidth of 20 megabytes per second. At any time, only one packet can be transferred on the bus between some disk’s internal cache and the host. However, a disk can be moving its disk arm while some other disk is transferring a packet on the bus. Also, a disk can be transferring data between its magnetic platters and its internal cache while some other disk is transferring a packet on the bus. Considering the transfer rates that

74 Chapter 14 Mass-Storage Structure

you calculated for the various workloads in Exercise 14.17, discuss how many disks can be used effectively by one fast wideSCSI-IIbus.

Answer:

For 8 KB randomI/Os on a lightly loaded disk, where the random access time is calculated to be about 13 ms (see Exercise 14.17), the effective transfer rate is about 615 MB/s. In this case, 15 disks would have an aggregate transfer rate of less than 10 MB/s, which should not saturate the bus. For 64 KB random reads to a lightly loaded disk, the transfer rate is about 3.4 MB/s, so 5 or fewer disk drives would saturate the bus. For 8 KB reads with a large enough queue to reduce the average seek to 3 ms, the transfer rate is about 1 MB/s, so the bus bandwidth may be adequate to accommodate 15 disks.

14.19 Remapping of bad blocks by sector sparing or sector slipping could influence perfor-mance. Suppose that the drive in Exercise 14.17 has a total of 100 bad sectors at random locations and that each bad sector is mapped to a spare that is located on a different track, but within the same cylinder. Estimate the number ofI/Os per second and the effective transfer rate for a random-access workload consisting of 8-kilobyte reads, with a queue length of 1 (that is, the choice of scheduling algorithm is not a factor). What is the effect of a bad sector on performance?

Answer:

Since the disk holds 22,400,000 sectors, the probability of requesting one of the 100 remapped sectors is very small. An example of a worst-case event is that we attempt to read, say, an 8 KB page, but one sector from the middle is defective and has been remapped to the worst possible location on another track in that cylinder. In this case, the time for the retrieval could be 8 ms to seek, plus two track switches and two full rotational latencies.

It is likely that a modern controller would read all the requested good sectors from the original track before switching to the spare track to retrieve the remapped sector and thus would incur only one track switch and rotational latency. So the time would be 8 ms seek + 4.17 ms average rotational latency + 0.05 ms track switch + 8.3 ms rotational latency + 0.83 ms read time (8 KB is 16 sectors, 1/10 of a track rotation). Thus, the time to service this request would be 21.8 ms, giving anI/Orate of 45.9 requests per second and an ef-fective bandwidth of 367 KB/s. For a severely time-constrained application this might matter, but the overall impact in the weighted average of 100 remapped sectors and 22.4 million good sectors is nil.

14.20 Discuss the relative advantages and disadvantages of sector sparing and sector slipping.

Answer:

Sector sparing can cause an extra track switch and rotational latency, causing an unlucky request to require an extra 8 ms of time. Sector slipping has less impact during future reading, but at sector remapping time it can require the reading and writing of an entire track’s worth of data to slip the sectors past the bad spot.

14.21 The operating system generally treats removable disks as shared file systems but assigns a tape drive to only one application at a time. Give three reasons that could explain this difference in treatment of disks and tapes. Describe additional features that would be required of the operating system to support shared file-system access to a tape jukebox.

Would the applications sharing the tape jukebox need any special properties, or could they use the files as though the files were disk-resident? Explain your answer.

Answer:

a. Disks have fast random-access times, so they give good performance for interleaved access streams. By contrast, tapes have high positioning times. Consequently, if two users attempt to share a tape drive for reading, the drive will spend most of its

在文檔中 OPERATING SYSTEM CONCEPTS (頁 73-85)