Get free ebooK with 50 must do coding Question for Product Based Companies solved
Fill the details & get ebook over email
Thank You!
We have sent the Ebook on 50 Must Do Coding Questions for Product Based Companies Solved over your email. All the best!

Disk Scheduling Algorithms in OS

During the time of execution, a process requires some I/O time to process the data which can be accessing the secondary memory or storage devices. The accessing time of these devices depends upon the scheduling algorithms used. Thus, they are named disk scheduling algorithms in OS. Before delving deep into the topic let us first learn some of the terminologies related to the Disk Scheduling Algorithms in OS.

Important Terminologies for Disk Scheduling Algorithms in OS

These are some of the important terms that you must be comfortable with in order to understand the disk scheduling algorithms in os.

  • Seek Time
    The time taken by the read/write head to move from one position to another position is present on the hard drive. It is of two types, average or maximum where the mean time to move is the average time while the maximum it can take is the maximum time.

  • Rotational Latency
    The data gets stored with the help of a rotating disk where the read/write head gets the position of the disk for accessing the data. The time taken between the request and read data is known to be rotational latency. In this manner, the lesser the rotational latency, the better.

  • Disk Access Time
    The total time taken to get the first required data processing a read/write request. It comprises access time and data transfer time or in other words, it can be the summation of Rotational Latency, Seek Time and Transfer Time.

  • Transfer Time
    The time taken to fetch the data after the request is made from the user side and providing the output is known as “Transfer Time”.

  • Disk Response Time
    The average of the waiting time is known as the “Disk Response Time”.

Types of Scheduling Algorithm

Now having some basic understanding of what disk scheduling algorithms are and the necessary terminologies required for learning disk scheduling algorithms in os, let us go through each algorithm.

First Come First Serve

It is a disk scheduling algorithm that processes the requests made in the order of the time they arrived. We can assume the queue data structure to understand this algorithm as the request that came in earlier will be the first one to be performed.

It is not the most optimal as a long time-taking request needs to be performed completely before a shorter one and it has the non-preemptive property that makes it complete the current task and avoid any other execution before the completion of the current.

Example:
Let us consider the request sequence as 82, 170, 43, 140, 24, 16 and 190 and current position of head at 50.

Here the seek time for this example will be

Seek time for FCFS = (82-50) + (170-82) + (170-43) + (140-43) + (140-24) + (24-16) + (190-16) = 642

Advantages:

  • Easy Implementation
  • No Starvation

Disadvantages:

Low Efficiency
More Seek Time

Shortest Seek Time First

Another disk scheduling algorithm in os that looks for the least seek time needed for read/write head to access drive data. Thus, the read/write head approaches data that is closest to its position.

It is faster as compared to another algorithm as it is preemptive which enables it to switch to requests that arrived later. It also minimizes the seek time needed to access data but creates problems such as Starvation wherein some requests never get the read/write head.

Example:
Let us consider the request sequence as 82, 170, 43, 140, 24, 16 and 190 and current position of head at 50.

Here the seek time for this example will be

Calculation of Seek Time  for SSTF = (50-43) + (43-24) + (24-16) + (82-16) + (140-82) + (170-140) + (190-170) = 208

Advantages:

  • Less Disk Response Time
  • Increased Efficiency than FCFS

Disadvantages:

  • Low Speed
  • Starvation can occur

SCAN Scheduling Disk Algorithm

It also goes by the name of the Elevator Algorithm, similarly to an elevator, it scans from starting point in a hard drive to the ending point and returns back to its initial stage at the starting point working on requests.

It has a drawback where it can make the user wait longer for more amount of requests in the queue because it set the priorities of the request currently being scanned which can make one wait longer for requests at the far end of the disk.

Example:
Let us consider the request sequence as 82, 170, 43, 140, 24, 16 and 190 and current position of head at 50.

Here the seek time for this example will be

Calculation of Seek Time for SCAN = (199-50) + (199-16) =332

Advantages:

  • Easy Implementation.
  • No waiting of requests in the queue.

Disadvantages:

  • No matter if there are requests in the direction, the head keeps on moving to the end.

LOOK Algorithm

It is a variant of the SCAN Scheduling algorithm it moves from start to end but on fulfilment of requests, it returns back by reversing the direction rather than going to the very end.

This technique is helpful in reducing waiting time for requests lying far from the initial point.

Example:
Let us consider the request sequence as 82, 170, 43, 140, 24, 16 and 190 and current position of head at 50.

The seek Time for the above example,

Seek Time for LOOK = (190-50) + (190-16) =314

Advantages:

  • There is no starvation.
  • There is no time wastage as the head does not goes to the end.

Disadvantages:

  • The arm must need to be conscious while finding the last request.

C-SCAN Algorithm

Another algorithm is slightly similar to SCAN where the scanning is performed from one end to another servicing the requests, but instead of returning back, it moves to the other end of the disk and continues scanning in the reversed direction it was initially scanning.

This in turn creates a C-Shaped Path traversed in terms of movement. It has a better performance and reduces the wait time.

Example:
Let us consider the request sequence as 82, 170, 43, 140, 24, 16 and 190 and current position of head at 50.

The seek time for the above algorithm wll be

Seek Time of C-SCAN =(199-50) + (199-0) + (43-0) =391

Advantages:

  • Uniform distribution of waiting time among the requests.
  • This has good response time.

Disadvantages:

  • The head will keep going to the end of the disk.
  • Time requires to locate the spot is increased in this algorithm.

C-LOOK Algorithm

It follows the exact same procedure as C-SCAN Algorithm by moving to the other ends of the disk upon servicing all the requests with a slight change in that the C-SCAN algorithm reverses the direction after moving to the other end but the C-LOOK disk scheduling algorithm in os continues scanning in the same direction.

Example:
Let us consider the request sequence as 82, 170, 43, 140, 24, 16 and 190 and current position of head at 50.

The seek Time for the above algorithm will be

Seek Time of C-LOOK = (190-50) + (190-16) + (43-16) =341

Advantages:

  • Reduction in waiting time.
  • There is no starvation.

Disadvantages:

  • The arm need to be conscious while dealing with the last request.

Why We should use Disk Scheduling Algorithms in OS

Disk scheduling algorithms are used to improve the performance of a computer’s hard disk by efficiently accessing and retrieving data from the disk. The main reason for using disk scheduling algorithms is to reduce the seek time and rotational latency of the disk, which are the two major factors that affect the disk’s access time.

When a computer needs to access data from the disk, it sends a request to the disk controller, which then retrieves the data from the disk. The disk scheduling algorithm is responsible for deciding the order in which these requests are processed by the disk controller. By optimizing the order of these requests, the disk scheduler can minimize the time it takes for the disk to access the data, which in turn improves the overall performance of the system.

Disk scheduling algorithms are particularly important in systems where multiple processes or applications are accessing the disk simultaneously. In such cases, the disk scheduler must prioritize the requests in a fair and efficient manner to prevent any single process from monopolizing the disk and causing delays for other processes.

Conclusion
In this article we read what disk scheduling algorithms in OS are and looked at some of the important terminologies needed to get the topic better. We later saw each disk scheduling algorithm in os in detail along with their advantages and disadvantages. We hope you liked this article and expect to see you again at PrepBytes with another informative article.

Frequently Asked Questions

Here are some Frequently Asked Questions related to “Disk Scheduling Algorithms in OS”.

1. What is a disk scheduling algorithm?
A disk scheduling algorithm is a method used by the operating system to determine the order in which disk I/O requests are serviced. These algorithms aim to minimize the total seek time and rotational latency of the disk arm to increase the overall efficiency of the system.

2. What are some common disk scheduling algorithms in OS?
There are several disk scheduling algorithms, including FCFS (First-Come, First-Serve), SSTF (Shortest Seek Time First), SCAN, C-SCAN, LOOK, and C-LOOK. Each of these algorithms has its own advantages and disadvantages, and the choice of algorithm depends on the system’s requirements and workload.

3. What is the difference between FCFS and SSTF disk scheduling algorithms in OS?
FCFS scheduling serves I/O requests in the order in which they arrive, while SSTF selects the request that requires the shortest seek time to be serviced next. SSTF is often considered more efficient than FCFS because it reduces the total seek time of the disk arm.

4. How do disk scheduling algorithms in OS affect system performance?
The choice of disk scheduling algorithm can have a significant impact on system performance. A well-designed algorithm can reduce disk access time and improve overall system throughput, while a poorly designed algorithm can result in increased latency and decreased performance.

5. Can disk scheduling algorithms in OS be customized to meet specific system requirements?
Yes, disk scheduling algorithms can be customized to meet specific system requirements. For example, some systems may prioritize certain types of I/O requests over others or may adjust scheduling parameters based on the current workload. Customized algorithms can help optimize system performance in specialized environments.

Leave a Reply

Your email address will not be published. Required fields are marked *