Solutions to Homework 5

12.4 Describe three circumstances under which blocking I/O should be used. Describe three

circumstances under which nonblocking I/O should be used. Why not just implement

nonblocking I/O and have processes busy-wait until their device is ready?

Answer:

Generally, blocking I/O is appropriate when the process will only be waiting for one spe-cific

event. Examples include a disk, tape, or keyboard read by an application program.

Non-blocking I/O is useful when I/O may come from more than one source and the order

of the I/O arrival is not predetermined. Examples include network daemons listening to

more than one network socket, window managers that accept mouse movement as well

as keyboard input, and I/O-management programs, such as a copy command that copies

data between I/O devices. In the last case, the program could optimize its performance

by buffering the input and output and using non-blocking I/O to keep both devices fully

occupied.

Non-blocking I/O is more complicated for programmers, because of the asynchronous

rendezvous that is needed when an I/O occurs. Also, busy waiting is less efficient than

interrupt-driven I/O so the overall system performance would decrease.

12.8 How does DMA increase system concurrency? How does it complicate hardware design?

Answer:

DMA increases system concurrency by allowing the CPU to perform tasks while the DMA

system transfers data via the system and memory busses. Hardware design is compli-cated

because the DMA controller must be integrated into the system, and the system

must allow the DMA controller to be a bus master. Cycle stealing may also be necessary

to allow the CPU and DMA controller to share use of the memory bus.

13.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, in FIFO order, 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 FCFS schedule is 143, 86, 1470, 913, 1774, 948, 1509, 1022, 1750, 130. The total

seek distance is 7081.

b. The SSTF schedule is 143, 130, 86, 913, 948, 1022, 1470, 1509, 1750, 1774. The total

seek distance is 1745.

c. The SCAN schedule is 143, 913, 948, 1022, 1470, 1509, 1750, 1774, 4999, 130, 86. The

total seek distance is 9769.

d. The LOOK schedule is 143, 913, 948, 1022, 1470, 1509, 1750, 1774, 130, 86. The total

seek distance is 3319.

e. The C-SCAN schedule is 143, 913, 948, 1022, 1470, 1509, 1750, 1774, 4999, 86, 130. The

total seek distance is 9985.

f. (Bonus.) The C-LOOK schedule is 143, 913, 948, 1022, 1470, 1509, 1750, 1774, 86, 130.

The total seek distance is 3363.

13.9 Explain why SSTF 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 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.

 

 

 

13.10 Requests are not usually uniformly distributed. For example, a cylinder containing the file system

FAT or 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 a FAT in DOS or inodes

in UNIX. Describe one or more ways to take advantage of this indirection to improve the disk

performance.

Answer:

a. SSTF would take greatest advantage of the situation. FCFS could 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. Modify SSTF to 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. (UNIX accomplishes the latter goal by allocating data and metadata in

regions called cylinder groups.)