0
0
Operating-systemsConceptBeginner · 3 min read

SSTF Disk Scheduling: How It Works and When to Use It

The SSTF (Shortest Seek Time First) disk scheduling algorithm selects the disk I/O request closest to the current head position to minimize seek time. It reduces the movement of the disk arm by always choosing the nearest request next, improving efficiency over simple methods like FCFS.
⚙️

How It Works

The SSTF disk scheduling algorithm works by always choosing the disk request that is closest to the current position of the disk head. Imagine you are at a library shelf and need to pick books from different shelves. Instead of going to the shelves in the order you received the requests, you pick the closest shelf first to save walking time.

This approach reduces the total movement of the disk arm, which is the part that reads or writes data on the disk. By minimizing this movement, the disk can handle requests faster and more efficiently than simply processing them in the order they arrive.

However, SSTF can cause some requests to wait longer if they are far from the current head position, especially if many requests are clustered nearby. This is called the starvation problem.

💻

Example

This example shows how SSTF selects the next disk request based on the shortest distance from the current head position.

python
def sstf_schedule(requests, head):
    requests = requests.copy()
    order = []
    while requests:
        # Find request closest to current head
        closest = min(requests, key=lambda r: abs(r - head))
        order.append(closest)
        head = closest
        requests.remove(closest)
    return order

# Disk requests at these positions
requests = [55, 58, 39, 18, 90, 160, 150, 38, 184]
# Starting head position
head = 50

scheduled_order = sstf_schedule(requests, head)
print("Order of servicing requests:", scheduled_order)
Output
Order of servicing requests: [55, 58, 39, 38, 18, 90, 150, 160, 184]
🎯

When to Use

SSTF is useful when you want to reduce the average seek time of disk operations compared to simple methods like First-Come-First-Serve (FCFS). It works well in systems where requests are frequent and scattered, helping to improve overall disk performance.

However, it is not ideal for real-time systems or where fairness is critical, because some requests might wait too long (starvation). It is often used in desktop operating systems or environments where average response time is more important than strict order.

Key Points

  • SSTF selects the disk request closest to the current head position.
  • It reduces seek time by minimizing disk arm movement.
  • Can cause starvation for requests far from the current head.
  • Better average performance than FCFS but less fair.
  • Commonly used in systems prioritizing efficiency over strict order.

Key Takeaways

SSTF chooses the nearest disk request to reduce seek time and improve efficiency.
It can cause some requests to wait longer, leading to starvation.
SSTF is better than simple FCFS scheduling for average response time.
Use SSTF when reducing disk arm movement is more important than strict fairness.
It is suitable for general-purpose systems but not for real-time critical tasks.