11.3 Disk Scheduling

The most important hardware device used as secondary memory is the magnetic disk drive. File systems stored on these drives must be accessed in an efficient manner. It turns out that transferring data to and from secondary memory is the worst bottleneck in a general computer system.

Recall from Chapter 10 that the speed of the CPU and the speed of main memory are much faster than the speed of data transfer to and from secondary memory such as a magnetic disk. That’s why a process that must perform I/O to disk is made to wait while that data is transferred, to give another process a chance to use the CPU.

Because secondary I/O is the slowest aspect of a general computer system, the techniques for accessing data on a disk drive are of crucial importance to file systems. As a computer deals with multiple processes over a period of time, requests to access the disk accumulate. The technique that the operating system uses to determine which requests to satisfy first is called disk scheduling. We examine several specific disk-scheduling algorithms in this section.

Recall from Chapter 5 that a magnetic disk drive is organized as a stack of platters, where each platter is divided into tracks, and each track is divided into sectors. The set of corresponding tracks on all platters is called a cylinder. FIGURE 11.6 revisits the disk drive depicted in Chapter 5 to remind you of this organization.

A figure represents the layout of a magnetic disk drive.

FIGURE 11.6 A magnetic disk drive

Of primary importance to us in this discussion is the fact that the set of read/write heads hovers over a particular cylinder along all platters at any given point in time. The seek time is the amount of time it takes for the heads to reach the appropriate cylinder. The latency is the additional time it takes the platter to rotate into the proper position so that the data can be read or written. Seek time is the more restrictive of these two parameters and, therefore, is the primary issue dealt with by the disk-scheduling algorithms.

At any point in time, a disk drive may have a set of outstanding requests that must be satisfied. For now, we consider only the cylinder (the parallel concentric circles) to which the requests refer. A disk may have thousands of cylinders. To keep things simple, let’s also assume a range of 110 cylinders. Suppose at a particular time the following cylinder requests have been made, in this order:

49, 91, 22, 61, 7, 62, 33, 35

Suppose also that the read/write heads are currently at cylinder 26. Now a question arises: To which cylinder should the disk heads move next? Different algorithms produce different answers to this question.

First-Come, First-Served Disk Scheduling

In Chapter 10 we examined a CPU-scheduling algorithm called first come, first served (FCFS). An analogous algorithm can be used for disk scheduling. It is one of the easiest to implement, though not usually the most efficient.

In FCFS, we process the requests in the order they arrive, without regard to the current position of the heads. Therefore, under a FCFS algorithm, the heads move from cylinder 26 (the current position) to cylinder 49. After the request for cylinder 49 is satisfied (that is, the data is read or written), the heads move from 49 to 91. After processing the request at 91, the heads move to cylinder 22. Processing continues in this manner, satisfying requests in the order that they were received.

Note that at one point the heads move from cylinder 91 all the way back to cylinder 22, during which they pass over several cylinders whose requests are currently pending.

Shortest-Seek-Time-First Disk Scheduling

The shortest-seek-time-first (SSTF) disk-scheduling algorithm moves the heads by the minimum amount necessary to satisfy any pending request. This approach could potentially result in the heads changing directions after each request is satisfied.

Let’s process our hypothetical situation using this algorithm. From our starting point at cylinder 26, the closest cylinder among all pending requests is 22. So, ignoring the order in which the requests came, the heads move to cylinder 22 to satisfy that request. From 22, the closest request is for cylinder 33, so the heads move there. The closest unsatisfied request to 33 is at cylinder 35. The distance to cylinder 49 is now the smallest, so the heads move there next. Continuing that approach, the rest of the cylinders are visited in the following order: 49, 61, 62, 91, 7.

This approach does not guarantee the smallest overall head movement, but it generally offers an improvement in performance over the FCFS algorithm. However, a major problem can arise with this approach. Suppose requests for cylinders continue to build up while existing ones are being satisfied. And suppose those new requests are always closer to the current position than an earlier request. It is theoretically possible that the early request never gets processed because requests keep arriving that take priority. This situation is called starvation. By contrast, FCFS disk scheduling cannot suffer from starvation.

SCAN Disk Scheduling

A classic example of algorithm analysis in computing comes from the way an elevator is designed to visit floors that have people waiting. In general, an elevator moves from one extreme to the other (say, the top of the building to the bottom), servicing requests as appropriate. It then travels from the bottom to the top, servicing those requests.

The SCAN disk-scheduling algorithm works in a similar way, except that instead of moving up and down, the read/write heads move in toward the spindle, then out toward the platter edge, then back toward the spindle, and so forth.

Let’s use this algorithm to satisfy our set of requests. Unlike in the other approaches, though, we need to decide which way the heads are moving initially. Let’s assume they are moving toward the lower cylinder values (and are currently at cylinder 26).

As the read/write heads move from cylinder 26 toward cylinder 1, they satisfy the requests at cylinders 22 and 7 (in that order). After reaching cylinder 1, the heads reverse direction and move all the way out to the other extreme. Along the way, they satisfy the following requests, in order: 33, 35, 49, 61, 62, 91.

New requests are not given any special treatment under this scheme. They may or may not be serviced before earlier requests—it depends on the current location of the heads and direction in which they are moving. If a new request arrives just before the heads reach that cylinder, it is processed right away. If it arrives just after the heads move past that cylinder, it must wait for the heads to return. There is no chance for starvation because each cylinder is processed in turn.

Some variations on this algorithm can improve its performance. For example, a request at the edge of the platter may have to wait for the heads to move almost all the way to the spindle and all the way back. To improve the average wait time, the Circular SCAN algorithm treats the disk as if it were a ring and not a disk. That is, when it reaches one extreme, the heads return all the way to the other extreme without processing requests.

Another variation is to minimize the extreme movements at the spindle and at the edge of the platter. Instead of going to the edge, the heads move only as far out (or in) as the outermost (or innermost) request. Before moving on to tackle the next request, the list of pending requests is examined to see whether movement in the current direction is warranted. This variation is referred to as the LOOK disk-scheduling algorithm, because it looks ahead to see whether the heads should continue in the current direction.

SUMMARY

A file system defines the way our secondary memory is organized. A file is a named collection of data with a particular internal structure. Text files are organized as a stream of characters; binary files have a particular format that is meaningful only to applications set up to handle that format.

File types are often indicated by the file extension of the file name. The operating system maintains a list of recognized file types so that it may open them in the correct kind of application and display the appropriate icons in the graphical user interface. The file extension can be associated with any particular kind of application that the user chooses.

The operations performed on files include creating, deleting, opening, and closing files. Of course, files must be able to be read from and written to as well. The operating system provides mechanisms to accomplish the various file operations. In a multiuser system, the operating system must also provide file protection to ensure that only authorized users have access to files.

Directories are used to organize files on disk. They can be nested to form hierarchical tree structures. Path names that specify the location of a particular file or directory can be absolute, originating at the root of the directory tree, or relative, originating at the current working directory.

Disk-scheduling algorithms determine the order in which pending disk requests are processed. First-come, first-served disk scheduling takes all requests in order but is not very efficient. Shortest-seek-time-first disk scheduling is more efficient but could suffer from starvation. SCAN disk scheduling employs the same strategy as an elevator, sweeping from one end of the disk to the other.

KEY TERMS

EXERCISES

For Exercises 1–15, mark the answers true or false as follows:

  1. True

  2. False

  1.   1. A text file stores binary data that is organized into groups of 8 or 16 bits that are interpreted as characters.

  2.   2. A program written in a high-level language is stored in a text file that is also called a source file.

  3.   3. The type of a file determines which kinds of operations can be performed on it.

  4.   4. The current file pointer indicates the end of a file.

  5.   5. Sequential access and direct access take about the same amount of time to retrieve data.

  6.   6. Some operating systems maintain a separate read pointer and write pointer for a file.

  7.   7. UNIX file permissions allow a group of users to access a file in various ways.

  8.   8. In most operating systems, a directory is represented as a file.

  9.   9. Two files in a directory system can have the same name if they are in different directories.

  10.   10. A relative path is relative to the root of the directory hierarchy.

  11.   11. An absolute path and a relative path will always be the same length.

  12.   12. An operating system is responsible for managing the access to a disk drive.

  13.   13. The seek time is the amount of time it takes for the heads of a disk to reach a particular cylinder.

  14.   14. The shortest-seek-time-first disk-scheduling algorithm moves the heads the minimum amount it can to satisfy a pending request.

  15.   15. The first-come, first-served disk-scheduling algorithm moves the heads the minimum amount it can to satisfy a pending request.

For Exercises 16–20, match the file extensions with the appropriate file.

  1. txt

  2. mp3, au, and wav

  3. gif, tiff, and jpg

  4. doc and wp3

  5. java, c, and cpp

  1.   16. Audio file

  2.   17. Image file

  3.   18. Text data file

  4.   19. Program source file

  5.   20. Word processing file

For Exercises 21–23, match the symbol with its use.

  1. /

  2. ..

  1.   21. Symbol used to separate the names in a path in a Windows environment

  2.   22. Symbol used to separate the names in a path in a UNIX environment

  3.   23. Symbol used to represent the parent directory in a relative path name

Exercises 24–57 are problems or short-answer questions.

  1.   24. What is a file?

  2.   25. Distinguish between a file and a directory.

  3.   26. Distinguish between a file and a file system.

  4.   27. Why is a file a generic concept and not a technical one?

  5.   28. Name and describe the two basic classifications of files.

  6.   29. Why is the term binary file a misnomer?

  7.   30. Distinguish between a file type and a file extension.

  8.   31. What would happen if you gave the name myFile.jpg to a text file?

  9.   32. How can an operating system make use of the file types that it recognizes?

  10.   33. How does an operating system keep track of secondary memory?

  11.   34. What does it mean to open and close a file?

  12.   35. What does it mean to truncate a file?

  13.   36. Compare and contrast sequential and direct file access.

  14.   37. File access is independent of any physical medium.

    1. How could you implement sequential access on a disk?

    2. How could you implement direct access on a magnetic tape?

  15.   38. What is a file protection mechanism?

  16.   39. How does UNIX implement file protection?

  17.   40. Given the following file permission, answer these questions.

    Read Write/Delete Execute
    Owner Yes Yes Yes
    Group Yes Yes No
    World Yes No No
    1. Who can read the file?

    2. Who can write or delete the file?

    3. Who can execute the file?

    4. What do you know about the content of the file?

  18.   41. What is the minimum amount of information a directory must contain about each file?

  19.   42. How do most operating systems represent a directory?

  20.   43. Answer the following questions about directories.

    1. A directory that contains another directory is called what?

    2. A directory contained within another directory is called what?

    3. c. A directory that is not contained in any other directory is called what?

    4. The structure showing the nested directory organization is called what?

    5. Relate the structure in (d) to the binary tree data structure examined in Chapter 8.

  21.   44. What is the directory called in which you are working at any one moment?

  22.   45. What is a path?

  23.   46. Distinguish between an absolute path and a relative path.

  24.   47. Show the absolute path to each of the following files or directories using the directory tree shown in Figure 11.4:

    1. QTEffects.qtx

    2. brooks.mp3

    3. Program Files

    4. 3dMaze.scr

    5. Powerpnt.exe

  25.   48. Show the absolute path to each of the following files or directories using the directory tree shown in Figure 11.5:

    1. tar

    2. access.old

    3. named.conf

    4. smith

    5. week3.txt

    6. printall

  26.   49. Assuming the current working directory is C:WINDOWSSystem, give the relative path name to the following files or directories using the directory tree shown in Figure 11.4:

    1. QTImage.qtx

    2. calc.exe

    3. letters

    4. proj3.java

    5. adobep4.hlp

    6. WinWord.exe

  27.   50. Show the relative path to each of the following files or directories using the directory tree shown in Figure 11.5:

    1. localtime when working directory is the root directory

    2. localtime when the working directory is etc

    3. printall when the working directory is utilities

    4. week1.txt when the working directory is man2

  28.   51. What is the worst bottleneck in a computer system?

  29.   52. Why is disk scheduling concerned more with cylinders than with tracks and sectors?

  30.   53. Name and describe three disk scheduling algorithms.

Use the following list of cylinder requests in Exercises 54–56. They are listed in the order in which they were received.

40, 12, 22, 66, 67, 33, 80

  1.   54. List the order in which these requests are handled if the FCFS algorithm is used. Assume that the disk is positioned at cylinder 50.

  2.   55. List the order in which these requests are handled if the SSTF algorithm is used. Assume that the disk is positioned at cylinder 50.

  3.   56. List the order in which these requests are handled if the SCAN algorithm is used. Assume that the disk is positioned at cylinder 50 and the read/write heads are moving toward the higher cylinder numbers.

  4.   57. Explain the concept of starvation.

THOUGHT QUESTIONS

  1.   1. The concept of a file permeates computing. Would the computer be useful if there were no secondary memory on which to store files?

  2.   2. The disk scheduling algorithms examined in this chapter sound familiar. In what other context have we discussed similar algorithms? How are these similar and how are they different?

  3.   3. Are there any analogies between files and directories and file folders and filing cabinets? Clearly, the term “file” came from this concept. Where does this analogy hold true and where does it not?

  4.   4. Spamming is the Internet equivalent of unsolicited telephone sales pitches. There are laws now that allow a telephone user to request that his or her name be removed from the solicitor’s calling list. Should there be similar laws relating to spamming?

  5.   5. In your opinion, is spamming a reasonable business strategy, like regular direct or “junk” mail, or is it a form of electronic harassment? Why or why not?

  6.   6. Which approach is better, opt-in or opt-out?

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.41.106