Disk Scheduling algorithm

Source: Internet
Author: User

Disk Benefits
    1. Very Large capacity
    2. The price per person is very low
    3. Storage information is not lost when power is turned off
Physical Properties

?? The disk surface is covered with magnetic material, and information is recorded on the magnetic surface. Each track of a fixed-head disk has a single head, which allows the computer to quickly transition from one track to another. But this requires a lot of head, the equipment cost is very high. A more general way is to have only one head on each surface, so that it moves from piece to side. This head device requires a hardware device to move the head.
?? Disk is generally used for file storage, the design principle is: low cost, large capacity, high speed. Expand storage Capacity: A. Increase the number of tracks per inch; B. Double-sided recording.
?? Access to the block of information generally have three parts of the time: the system first to move the head to the corresponding road or cylinder, this time is called seek time; once the head reaches the specified track, it must wait for the desired sector to go to the read/write head, which is called the rotational delay time; It takes time to actually transfer the information between the disk and the memory, which is called the transfer time. The total time of a disk service is the sum of these three.
?? To make the disk service as fast as possible, the operating system needs to provide an appropriate scheduling algorithm to improve the average time of the disk service.
?? The process needs to exchange information with the disk must be issued by the operating system calls, the disk requests generally have the following sections:
?? 1. Input and output;
?? 2. Disk address (drive, cylinder, face number, sector);
?? 3. memory address;
?? 4. Transfer length.

Disk scheduling algorithm 1, first come first service scheduling (FCFS)

?? The FCFS algorithm is preferred for the first arrival request service. For example, the following request Disk Service queue, the number of tracks to access are:
???? 98,183,37,122,14,124,65,67
?? The front is the first arrival of the request, assuming that the head is currently on the 53 track, in accordance with the first-come first service algorithm, then the head of the moving sequence is:
?? 53->98->183->37->122->14->124->65->67
This process has moved a total of (98-53) + (183-98) + (183-37) + (122-37) + (122-14) + (124-14) + (124-65) + (67-65) = 640 tracks
?? This scheduling method produces the head movement service is too big, the head frequently moves greatly, is easy to produce the mechanical vibration and the error, has the damage to the service life. Therefore, to design a good algorithm to reduce the head movement amplitude, reduce service time, improve the disk throughput.

2. Shortest seek Time priority method (SSTF)

?? The priority service is close to the request for the current position of the head. SSTF is essentially the form of the SJF (shortest job first algorithm) dispatch. Using the SSTF scheduling algorithm, the order of execution for the above request queue is:
?? 53->65->67->37->14->98->122->124->183
A total of 236 tracks were moved, a little more than one-third FCFS, significantly improving the disk service.
?? However, this algorithm is not optimal. For example, if you move the head from 53 to 37 (although not the closest) and then move to 14, the next is 65,67,98,122,124,183, moving a total of 208 tracks <236.
?? SSTF may also cause some requests to be left out of service for a long time (i.e. "hunger"). If a new request is always coming near the current head, a request that is far away from the head will be waiting.

3. Scanning method (scan)

?? Due to the dynamic nature of the queue requesting the service, there will always be new requests arriving, so the scanning algorithm can be used. The read/write head starts at one end of the disk, moves to the other end, and serves when the required track is encountered until it reaches the other end of the disk. On the other end, the head moves in the opposite direction, continuing to do the following services. This way the head is swept from one end of the disk to the other.
?? According to the previous example, you know the direction of the head movement and its nearest position. If the head moves in a 0-way direction, the service is first for 37 and 14 lanes. To reach 0, the head moves in the opposite direction and moves to the other end of the disk, followed by the service sequence 65,67,98,122,124,183.
?? When implementing an algorithm, it is not necessary to have the head always move from one end of the disk to the other. More generally, the head moves only to the farthest request track in each direction, and once there is no further service request in the current direction, the direction of the head movement will reverse and continue to serve the following request. This algorithm is also called the "Elevator algorithm". For example, in the above example, the head service is 37, 14 after the discovery of no new request, will not move forward to 0, and immediately turn around the service 65 road ...
?? The problem with this algorithm is that the request to the track is assumed to be evenly distributed, and when the head reaches the far end of the side and the direction is reversed, the request that falls immediately behind the disk is relatively small, because the tracks have just been serviced and there are more requests at the other side of the disk, with the longest waiting time.

4. Tour Scanning method (C-scan)

?? C-scan is a variant of scan, which makes the waiting time even. The difference with scan is that it moves to one end, the direction is put over, but in the return process does not service, is directly from one end to another, and then in the direction of the move, encountered the requested track on the service. For example, the above example, first move to 0, 53–>37–>14, and then opposite direction, to the other end, 183–>124–>122–>98–>67–>65.

selection of disk scheduling algorithms

?? The performance of any scheduling algorithm is tightly dependent on the number and type of I/O requests, and for systems with heavy disk loads it is more appropriate to choose the elevator algorithm and the C-scan algorithm. In very rare cases, if there is very little in the queue for an outstanding request, then all the algorithms are actually equivalent. Research has shown that there is typically only one request in the queue. At this point, FCFS is also a suitable algorithm.
?? Requests for disk services are greatly affected by how the file is distributed. The degree to which a continuous file is read will result in a large number of requests being squeezed together on the disk, with limited movement of the head. In the case of concatenated or indexed files, it is possible to refer to the widely distributed disk blocks on the disk, and to achieve better disk efficiency by reducing the head movement.
?? The location of directories and index blocks has an important impact on the queue of I/O requests. If the file's data and its directory entries are far apart on the disk, the head movement is a long distance away. If you place directories and index blocks in the cache, you can significantly reduce the movement of the heads, especially for read requests.
?? The effect of pathfinding distance on scheduling algorithm is considered. For modern disks, however, the rotational delay is almost near the average seek time. However, it is difficult for the operating system to improve the rotational delay time by scheduling, because the physical location of the logical block is not disclosed externally. Of course, the disk manufacturer can mitigate this problem by implementing a scheduling algorithm in the controller hardware.

[The above is collated from the operating system tutorial-linux example Analysis Meng Qingchang]

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Disk Scheduling algorithm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.