Storage Management
Storage management in operating systems involves handling data storage efficiently to ensure fast access and retrieval. It includes disk scheduling algorithms for optimizing disk access and buffer cache mechanisms to speed up data access.
Disk Scheduling Algorithms
When multiple requests are waiting for disk access, the operating system decides the order in which they should be serviced. The goal is to minimize seek time (the time taken by the disk arm to move to the requested track).
First-Come, First-Served (FCFS)
- How it works: Requests are processed in the order they arrive.
- Advantages:
- Simple to implement.
- Fair (no starvation).
- Disadvantages:
- Poor performance when requests are scattered, leading to high seek times.
Example:
Consider disk requests at tracks 98, 183, 37, 122, 14, 124, 65, 67, and the head starts at 53.
Request Queue |
Seek Distance from Previous |
98 |
45 (98 - 53) |
183 |
85 (183 - 98) |
37 |
146 (183 - 37) |
122 |
85 (122 - 37) |
14 |
108 (122 - 14) |
124 |
110 (124 - 14) |
65 |
59 (124 - 65) |
67 |
2 (67 - 65) |
- Total Seek Time = 45 + 85 + 146 + 85 + 108 + 110 + 59 + 2 = 640
- High total seek time, inefficient.
Shortest Seek Time First (SSTF)
- How it works: The request closest to the current head position is serviced first.
- Advantages:
- Disadvantages:
- Starvation: If requests keep coming near the head, far requests may wait indefinitely.
Example (Same Requests as Above):
Head at 53 → Nearest request is 65 → Then 67 → Then 37, etc.
- Results in lower seek time than FCFS.
SCAN (Elevator Algorithm)
- How it works: The head moves in one direction, serving requests until it reaches the last request in that direction, then reverses.
- Advantages:
- Prevents starvation.
- More efficient than FCFS and SSTF.
- Disadvantages:
- Higher seek time compared to LOOK.
Example:
- Head moves from 53 towards 0, servicing 37, 14, then moves towards 199(the max end for the example), servicing 65, 67, 98, 122, 124, 183.
C-SCAN (Circular SCAN)
- How it works: Similar to SCAN, but after reaching one end, it jumps back to the other end instead of reversing.
- Advantage:
- Provides uniform wait time.
- Disadvantage:
- More unnecessary movement compared to LOOK.
LOOK Algorithm
- How it works: Like SCAN, but stops at the last request in the direction (instead of going to the extreme end).
- Advantage:
- Reduces unnecessary movement.
C-LOOK Algorithm
- How it works: Like C-SCAN, but stops at the last request and jumps to the beginning.
- Advantage:
- More efficient than C-SCAN.
Buffer Cache and Disk Caching
A buffer cache is a memory space used to store frequently accessed disk data to speed up retrieval.
How It Works
- When data is needed, the OS first checks the cache.
- If found (cache hit), it is accessed quickly.
- If not (cache miss), it is fetched from the disk and stored in the cache.
Types of Disk Caching
- Write-Through Cache: Data is written to both cache and disk simultaneously.
- Write-Back Cache: Data is written to the cache first, then later to the disk.