I/O Systems & Disk Scheduling
766 words
4 min read
Visual companion
Python
Type and operator map
Python Week 1: the first filter for runtime behavior
View
Revision summary
What this note is really saying
Short form
# I/O Systems & Disk Scheduling ## 🎯 Learning Objectives - Explain the layered structure of the I/O system - Trace FCFS, SSTF, SCAN, C-SCAN, LOOK, and C-LOOK disk scheduling - Calculate seek time, rotational latency, and transfer time - Choose the right scheduling algorithm for different workloads * * * ## 1. I/O H...

I/O Systems & Disk Scheduling
🎯 Learning Objectives
- Explain the layered structure of the I/O system
- Trace FCFS, SSTF, SCAN, C-SCAN, LOOK, and C-LOOK disk scheduling
- Calculate seek time, rotational latency, and transfer time
- Choose the right scheduling algorithm for different workloads
1. I/O Hardware
1.1 I/O Hierarchy
(Diagram)
1.2 I/O Methods
| Method | Description | CPU Usage | Data Path |
|---|---|---|---|
| Programmed I/O (PIO) | CPU polls device, transfers each byte | Very high | CPU → Device |
| Interrupt-driven | CPU starts transfer, device interrupts on completion | Medium | CPU → Device |
| DMA | DMA controller handles transfer, interrupts CPU on completion | Low | Device → Memory (no CPU) |
2. Disk Structure
2.1 Disk Geometry
(Diagram)
2.2 Disk Access Time Components
Access Time=Seek Time+Rotational Latency+Transfer Time| Component | Typical Value | Formula |
|---|---|---|
| Seek time | 3-15 ms | Move arm to correct cylinder |
| Rotational latency | 2-8 ms (half rotation) | 1/(2 × RPM/60) |
| Transfer time | 0.01-1 ms | sectors × sector_size / transfer_rate |
Example: 7200 RPM disk, 5ms seek, transfer 512 bytes at 100 MB/s.
- Rotational latency = 60 / (7200 × 2) = 4.17 ms
- Transfer time = 512 / (100 × 10^6) = 0.005 ms
- Total ≈ 9.17 ms (seek dominates!)
3. Disk Scheduling Algorithms
3.1 Worked Example (Same Queue for All)
Request queue: 98, 183, 37, 122, 14, 124, 65, 67 Initial head position: 53 Direction: Towards 0 (left) or 199 (right)
3.2 FCFS (First Come, First Served)
Order: 53 → 98 → 183 → 37 → 122 → 14 → 124 → 65 → 67
Movement: |98-53| + |183-98| + |37-183| + |122-37| + |14-122| + |124-14| + |65-124| + |67-65|
= 45 + 85 + 146 + 85 + 108 + 110 + 59 + 2 = 640 cylinders
Gantt-style path:
pseudo53 → 98 (45) → 183 (85) → 37 (146) → 122 (85) → 14 (108) → 124 (110) → 65 (59) → 67 (2)
3.3 SSTF (Shortest Seek Time First)
Always pick the request with the shortest seek distance from current position.
| Step | Current | Candidates (distance) | Chosen | Movement |
|---|---|---|---|---|
| 1 | 53 | 37(16), 65(12), 67(14), 98(45), 122(69), 14(39) | 65 | 12 |
| 2 | 65 | 37(28), 67(2), 98(33), 122(57), 14(51) | 67 | 2 |
| 3 | 67 | 37(30), 98(31), 122(55), 14(53) | 37 | 30 |
| 4 | 37 | 98(61), 122(85), 14(23) | 14 | 23 |
| 5 | 14 | 98(84), 122(108) | 98 | 84 |
| 6 | 98 | 122(24) | 122 | 24 |
| 7 | 122 | 183(61) | 183 | 61 |
| 8 | 183 | — | Done | — |
Total movement: 12 + 2 + 30 + 23 + 84 + 24 + 61 = 236 cylinders
3.4 SCAN (Elevator Algorithm)
Move in one direction, servicing all requests, then reverse direction.
Direction: towards 199 (right)
| Step | Current | Direction | Service | Next | Movement |
|---|---|---|---|---|---|
| 1 | 53 | → | |||
| 2 | 65 | → | 65 | 65 | 12 |
| 3 | 67 | → | 67 | 67 | 2 |
| 4 | 98 | → | 98 | 98 | 31 |
| 5 | 122 | → | 122 | 122 | 24 |
| 6 | 183 | → | 183 | 183 | 61 |
| 7 | 199 | → (end) | — | — | 16 |
| 8 | 199 | ← | |||
| 9 | 124 | ← | 124 | 75 | |
| 10 | 37 | ← | 37 | 87 | |
| 11 | 14 | ← | 14 | 23 |
Total movement: (199-53) + (199-14) = 146 + 185 = 331 cylinders
3.5 C-SCAN (Circular SCAN)
Move in one direction servicing requests, then jump back to the start and repeat.
Direction: towards 199 (right)
| Step | Current | Service | Movement |
|---|---|---|---|
| 1 | 53 | — | — |
| 2 | 65 | 65 | 12 |
| 3 | 67 | 67 | 2 |
| 4 | 98 | 98 | 31 |
| 5 | 122 | 122 | 24 |
| 6 | 183 | 183 | 61 |
| 7 | 199 (end) | — | 16 |
| 8 | 0 (jump) | — | 199 |
| 9 | 14 | 14 | 14 |
| 10 | 37 | 37 | 23 |
Total movement: (199-53) + (199-0) + (37-0) = 146 + 199 + 37 = 382 cylinders
3.6 LOOK and C-LOOK
Same as SCAN/C-SCAN but only go as far as the last request in each direction.
| Algorithm | Path | Total Movement |
|---|---|---|
| LOOK | 53→65→67→98→122→183→124→37→14 | (183-53)+(183-14)=130+169=299 |
| C-LOOK | 53→65→67→98→122→183→14→37 | (183-53)+(183-14)+(37-14)=130+169+23=322 |
3.7 Comparison
| Algorithm | Total Movement | Starvation? | Direction Bias? | Pros | Cons |
|---|---|---|---|---|---|
| FCFS | 640 | No | No | Simple, fair | Very slow |
| SSTF | 236 | Yes | No | Lowest movement | Starves far requests |
| SCAN | 331 | No | Yes (middle better) | No starvation | End-to-end latency |
| C-SCAN | 382 | No | More uniform | Uniform wait times | Jump overhead |
| LOOK | 299 | No | Yes | Avoids full sweep | — |
| C-LOOK | 322 | No | No | Most balanced | — |
4. 📐 Key Formulas / Concepts
| Concept | Formula |
|---|---|
| Rotational latency | 1/(2 × RPM/60) seconds |
| Transfer time | bytes / transfer_rate |
| Access time | seek + rotation + transfer |
| Disk throughput | bytes / access_time |
5. 📝 Practice Questions
Q1: Queue: 86, 147, 91, 177, 94, 150, 102, 130. Head at 100, direction right. Compute SCAN movement.Answer: Order: 100→102(2)→130(28)→147(17)→150(3)→177(27)→199(22)→94(105)→91(3)→86(5) Movement = (199-100)+(199-86) = 99+113 = 212 Q2: Why does SSTF cause starvation?Answer: SSTF always picks the shortest distance request. If new requests keep arriving close to the current position, far-away requests may never be serviced. This is analogous to shortest-job-first in CPU scheduling. Q3: A disk rotates at 15000 RPM. What is the average rotational latency?Answer: Average rotational latency = 60/(15000×2) = 60/30000 = 2 ms. Q4: Compare SCAN and C-SCAN in terms of waiting time variance.Answer: SCAN favors cylinders in the middle (get serviced on both passes). C-SCAN treats all cylinders more uniformly because the head always traverses in one direction, so the wait time depends on how far the cylinder is from the head's current pass direction. Q5: What prevents FCFS from being optimal for disk scheduling?Answer: FCFS doesn't optimize for mechanical movement. It serves requests in arrival order, causing the disk arm to bounce back and forth across the disk surface. This maximizes seek time and provides the worst throughput.
6. 🔗 Cross-References
- Week 9 - File Systems: How files map to disk blocks
- Week 5 - Synchronization: I/O request queues
- BSCS3031 (CSD): DMA, interrupts, device controllers Join Discord PreviousFile SystemsNextOS Security