Chapter12-Disk Scheduling(1)

advertisement
Chapter 12 – I/O Management and Disk Scheduling
I/O Hardware
 Incredible variety of I/O devices
 Common concepts
 Port (a connection point)
 Bus (daisy chain or shared direct access)
 Controller (host adapter)
 I/O instructions control devices
 Devices have addresses, used by
 Direct I/O instructions
 Memory-mapped I/O
Prepared by Dr. Amjad Mahmood
12.1
Life Cycle of an I/O Request
Prepared by Dr. Amjad Mahmood
12.2
I/O System Architecture
 Devices controllers connect to the bus
 and represent the devices
 Device drivers talk to device controllers
 and through them to the devices
 Device drivers present a common interface to the
rest of the OS
Device Driver Interface
 Open(int deviceNumber): controllers can control more than
one device
 Close(int deviceNumber)
 Read(int deviceNumber, int deviceAddress, void *
memoryAddress, int length)
 Write(int deviceNumber, int deviceAddress, void *
memoryAddress, int length)
Prepared by Dr. Amjad Mahmood
12.3
General I/O Issues
 The operating system is able to improve overall
system performance if it can keep the various
devices as busy as possible.
 It is important for the operating system to handle
device interrupts as quickly as possible.
 For interactive devices (keyboard, mouse,
microphone), this can make the system more
responsive.
 For communication devices (modem, Ethernet,
etc), this can affect the effective speed of the
communications.
 For real-time systems, this can be the
difference between the system operating
correctly and malfunctioning.
Disk Structure
 Disks provide the bulk of secondary storage.
 Disk drives are addressed as large 1-dimensional
arrays of logical blocks, where the logical block is
the smallest unit of transfer. The size of logical block
is generally 512 bytes.
 The 1-dimensional array of logical blocks is mapped
into the sectors of the disk sequentially.
 Sector 0 is the first sector of the first track on
the outermost cylinder.
 Mapping proceeds in order through that track,
then the rest of the tracks in that cylinder, and
then through the rest of the cylinders from
outermost to innermost.
Prepared by Dr. Amjad Mahmood
12.4
 The number of sectors per tack is not a constant.
Therefore, modern disks are organized in zones of
cylinders. The number of sectors per track is
constant within a zone.
Disk Track Format
Prepared by Dr. Amjad Mahmood
12.5
Disk I/O
 Whenever a process needs I/O to or from a disk, it
issues a system call to the operating system.
 If the desired disk drive and controller is
available, the request can be serviced
immediately other wise the request is placed in
a queue.
 Once an I/O completes, the OS can choose a
pending request to serve next.
Disk Read/Write
 To read or write data, disk device must move the
arm to the appropriate track.
 Then, the disk device must wait for the desired
sector/data to rotate into position under the head
and then read the desired block/sector.
 Each track is recorded in units called Sectors. A
sector is the smallest amount of data that can be
physically read or written.
Disk performance Parameters
 The operating system is responsible for using
hardware efficiently - for the disk drives, this means
having a fast access time and disk bandwidth.
 Access time factors include
 Seek time (slowest)
 Time to position read/write head on track
 Search time
 Rotational delay - Rotate until desired
record under read/write head
Prepared by Dr. Amjad Mahmood
12.6
 Transfer time (fastest)
 Time to transfer data
 Seek time is the reason for
performance
 Minimize seek time
 Seek time  seek distance
differences
in
Disk Scheduling
 For a single disk there may be a number of I/O
requests
 If we have two or more pending disk requests,
which should go first?
Prepared by Dr. Amjad Mahmood
12.7
 Several algorithms exist to schedule the servicing of
disk I/O requests.
 We illustrate them with a request queue (0-199).
98, 183, 37, 122, 14, 124, 65, 67
Head pointer 53
First Come First Serve (FCFS)
The I/O requests are served in the order in which
they reach. See below (total head movement=640 cylinders)
 FCFS is a fair scheduling algorithm but not an
optimal one.

Prepared by Dr. Amjad Mahmood
12.8
Shortest-Seek-Time-First (SSTF)
 Selects the request with the minimum seek time
from the current head position.
 SSTF scheduling is a form of SJF CPU scheduling
 May cause starvation of some requests
 Is not optimal.
 Illustration shows total head movement of 236
cylinders.
SCAN Scheduling
 Directional bit
 Indicates if arm moving toward/away from disk
center
 Algorithm moves arm methodically
 From outer to inner track, services every
request in its path
 If reaches innermost track, reverses direction
and moves toward outer tracks
 Services every request in its path
 Sometimes called the elevator algorithm.
Prepared by Dr. Amjad Mahmood
12.9
 Illustration shows total head movement of 208
cylinders (head is moving towards cylinder 0).
C-SCAN Scheduling
 Provides a more uniform wait time than SCAN.
 The head moves from one end of the disk to the
other, servicing requests as it goes. When it
reaches the other end, however, it immediately
returns to the beginning of the disk, without
servicing any requests on the return trip.
 Treats the cylinders as a circular list that wraps
around from the last cylinder to the first one.
Prepared by Dr. Amjad Mahmood
12.10
C-Look Scheduling
 Version of C-SCAN
 Arm only goes as far as the last request in each
direction, then reverses direction immediately,
without first going all the way to the end of the disk.
Selecting a Disk Scheduling Algorithm
 Best strategy
 FCFS best with light loads
• Service time unacceptably long under high
loads
 SSTF best with moderate loads
• Localization problem under heavy loads
 SCAN best with light to moderate loads
• Eliminates indefinite postponement
– Throughput and mean service times
SSTF similarities
 C-SCAN best with moderate to heavy loads
• Very small service time variances
Prepared by Dr. Amjad Mahmood
12.11
Summary of Disk Scheduling Algorithms
Prepared by Dr. Amjad Mahmood
12.12
Disk Management
 Low-level formatting, or physical formatting Dividing a disk into sectors that the disk controller
can read and write.
 To use a disk to hold files, the operating system still
needs to record its own data structures on the disk.
 Partition the disk into one or more groups of
cylinders.
 Logical formatting or “making a file system”.
 Boot block initializes system.
 The bootstrap is stored in ROM.
 Bootstrap loader program.
 Bad sectors may be managed manually. For
example MS-DOS format command does a logical
format and if it finds any bad sector, it writes a
special value into FAT.
 Sector sparing method may also used to handle bad
blocks (as used in SCSI disks). The controller
maintains a list of bad sectors which is updated
regularly. Low level formatting also sets aside some
spare sectors. The controller can be asked to
replace each bad sector logically with one of the
spare sectors.
Prepared by Dr. Amjad Mahmood
12.13
Exercise
Question. None of the disk-scheduling disciplines, except FCFS, is truly fair (starvation
may occur).
a. Explain why this assertion is true.
b. Describe a way to modify algorithms such as SCAN to ensure fairness.
c. Explain why fairness is an important goal in a time-sharing system.
d. Give three or more examples of circumstances in which it is important that the operating
system be unfair in serving I/O requests.
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. For SSTF, 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-initiated I/O, such as the writing of file system metadata, to take precedence over user
I/O. If the kernel supports real-time process priorities, the I/O requests of those processes
should be favored.
Question. 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. Left as an exercise.
Question. List and briefly define three techniques for performing I/O.
Answer. Programmed I/O: The processor issues an I/O command, on behalf of a process, to an I/O
module; that process then busy-waits for the operation to be completed before proceeding. Interruptdriven I/O: The processor issues an I/O command on behalf of a process, continues to execute
subsequent instructions, and is interrupted by the I/O module when the latter has completed its work.
The subsequent instructions may be in the same process, if it is not necessary for that process to wait
for the completion of the I/O. Otherwise, the process is suspended pending the interrupt and other
work is performed. Direct memory access (DMA): A DMA module controls the exchange of data
between main memory and an I/O module. The processor sends a request for the transfer of a block
of data to the DMA module and is interrupted only after the entire block has been transferred.
Question. What is the difference between block-oriented devices and stream-oriented devices? Give
a few examples of each.
Answer. Block-oriented devices stores information in blocks that are usually of fixed size, and
transfers are made one block at a time. Generally, it is possible to reference data by its block number.
Disks and tapes are examples of block-oriented devices. Stream-oriented devices transfer data in
and out as a stream of bytes, with no block structure. Terminals, printers, communications ports,
mouse and other pointing devices, and most other devices that are not secondary storage are stream
oriented.
Question. Briefly define the disk scheduling policies.
Answer. FIFO: Items are processed from the queue in sequential first-come-first-served order. SSTF:
Select the disk I/O request that requires the least movement of the disk arm from its current position.
Prepared by Dr. Amjad Mahmood
12.14
SCAN: The disk arm moves in one direction only, satisfying all outstanding requests en route, until it
reaches the last track in that direction or until there are no more requests in that direction. The service
direction is then reversed and the scan proceeds in the opposite direction, again picking up all
requests in order. C-SCAN: Similar to SCAN, but restricts scanning to one direction only. Thus, when
the last track has been visited in one direction, the arm is returned to the opposite end of the disk and
the scan begins again.
Prepared by Dr. Amjad Mahmood
12.15
Download