🗂 What You'll Learn
- Physical structure of magnetic disks & SSDs
- How access time is calculated (seek + rotation + transfer)
- Disk scheduling algorithms (FCFS, SSTF, SCAN, C-SCAN, LOOK, C-LOOK)
- RAID levels and why they exist
- Boot block & bad block management
🔗 Connections to Other Chapters
- Ch 8 - 9 (Memory/VM): Swap space lives on disk
- Ch 11 - 12 (File Systems): Files are stored on disk; allocation methods use disk blocks
- Ch 3 (Processes): I/O-bound vs CPU-bound processes - I/O often means disk
Anatomy of a Hard Disk (HDD)
Understanding the physical layout is key to understanding why access time has multiple components.
Conceptual view of a magnetic disk platter
📐 Key Terms
- Platter: Circular disk coated with magnetic material
- Track: Concentric ring on a platter surface
- Sector: Smallest addressable unit (usually 512B or 4KB)
- Cylinder: All tracks at the same radius across all platters
- Read/Write Head: Reads/writes data as platter spins under it
- Disk Arm: Moves head radially across platters
🖥️ OS + User View
- User sees: Files and folders
- OS sees: Array of logical blocks
- Disk sees: Sectors on tracks on cylinders
The disk controller maps logical block numbers to physical locations.
| Feature | Magnetic HDD | SSD (Solid-State) |
|---|---|---|
| Moving Parts | Yes (arm, platters) | No |
| Access Time | ~3 - 12 ms | ~0.1 ms |
| Volatile? | No | No |
| Fragmentation Issue | Yes (seek time) | No (random access same speed) |
| Price per GB | Cheaper | More expensive |
| Lifespan | Limited by mechanical wear | Limited write cycles |
| Suitable for Scheduling? | Yes - head movement matters | Less critical - no seek time |
The Three Components of Access Time
Every disk access has three time costs. Understanding each component is critical for exam calculations.
① Seek Time
Time to move the disk arm to the correct cylinder (track). This is the dominant and most variable cost. Disk scheduling algorithms focus on minimizing this.
② Rotational Latency
Time for the desired sector to rotate under the read/write head. On average, this is half of one full rotation.
③ Transfer Time
Time to actually read/write the data once the head is in position. Usually the fastest component.
🧠 Memory Aid
Seek → Rotate → Transfer - like a journey: travel to the city → wait for the right street → pick up the package.
The Problem
Multiple processes request disk I/O simultaneously. The OS must decide the order to serve them. Since seek time is the biggest cost, a smart order can save huge amounts of time.
Setting the Stage
All algorithms are evaluated on:
- Total head movement (in cylinders) - lower is better
- Throughput - requests served per time unit
- Fairness - no request waits forever
📌 We always track: current head position, queue of pending requests, and sometimes direction of movement.
📋 Reference Example (used throughout)
Queue: 98, 183, 37, 122, 14, 124, 65, 67
Initial head position: 53 | Disk: 0 - 199
This is the classic textbook example from Silberschatz Ch.10
1. FCFS - First-Come, First-Served
Rule: Serve requests in the order they arrive. No reordering.
Total movement: |98−53| + |183−98| + |37−183| + ... = 640 cylinders
- ✅ Simple, fair (no starvation)
- ❌ Worst performance - head zigzags across disk
🧠 Remember
FCFS = First Come First Served = no optimization at all = like serving a restaurant table by table in order of who called first, even if they're all the way across town.
2. SSTF - Shortest Seek Time First
Rule: Always serve the request closest to the current head position.
Total movement: 236 cylinders
- ✅ Much better than FCFS
- ❌ Starvation possible - requests far from head may never get served
- ❌ Not optimal (greedy approach)
🧠 SSTF ≈ SJF for disks
Just like SJF scheduling picks the shortest CPU burst, SSTF picks the shortest seek distance. Same concept, same starvation problem!
3. SCAN - The Elevator Algorithm
Rule: Head moves in one direction, serving all requests along the way, then reverses direction at the end (or last request) and sweeps back.
Total movement: ~236 cylinders (much less than FCFS)
- ✅ No starvation - head eventually reaches every cylinder
- ✅ Better throughput than FCFS
- ❌ Requests just behind the head wait for a full sweep
🧠 Think: Elevator
An elevator goes UP serving all floors, reaches top, comes back DOWN. The disk head does the same across cylinders 0 - 199.
4. C-SCAN - Circular SCAN
Rule: Like SCAN, but when the head reaches the end, it immediately jumps back to the beginning without serving requests on the return trip. Only serves one direction.
- ✅ More uniform waiting time than SCAN
- ✅ No starvation
- ❌ Jump from end to beginning counts as head movement
🧠 C-SCAN = One-Way Street
SCAN = elevator going up AND down. C-SCAN = only going up, teleports back to ground floor. More fair because requests near cylinder 0 aren't always last.
5. LOOK & C-LOOK
LOOK: Like SCAN but doesn't go all the way to the end of the disk - only goes as far as the last request in that direction, then reverses.
C-LOOK: Like C-SCAN but only goes to the last request, then jumps to the first request (not cylinder 0).
- ✅ More efficient than SCAN/C-SCAN - no unnecessary travel to disk edge
- ✅ Commonly used in practice
🧠 LOOK vs SCAN - "Look Before You Go"
SCAN goes to the wall. LOOK looks ahead and stops at the last request. Saves travel time at the edges.
| Algorithm | Strategy | Starvation? | Performance | Best For |
|---|---|---|---|---|
FCFS |
Arrival order | No | Worst | Light loads only |
SSTF |
Nearest cylinder first | ⚠ Yes | Good | Low-latency if load is clustered |
SCAN |
Elevator sweep, reverses at edge | No | Good | Heavy loads |
C-SCAN |
One-way sweep, jump to start | No | Good, uniform | Uniform waiting time needed |
LOOK |
Like SCAN, stops at last request | No | Better than SCAN | General purpose |
C-LOOK |
Like C-SCAN, jumps to first request | No | Best practical | General purpose - most used |
🔌 Swap Space (Swap Partition)
- Section of disk used as extension of RAM
- Pages swapped out to swap space when memory is full
- Much slower than RAM - causes thrashing if overused
- OS manages its own swap-space allocation separately from the file system
🔴 Boot Block (Bootstrap)
- Located in a fixed location on disk (usually first sector)
- Contains the bootstrap loader - loads the OS
- ROM/EPROM on motherboard points CPU to boot block
- Also called Master Boot Record (MBR)
⚠ Bad Blocks
- Physical sectors that are damaged and can't reliably store data
- Simple approach: Flag bad blocks in FAT so OS avoids them
- Advanced approach: Sector sparing - disk controller secretly remaps bad blocks to spare sectors
- Slip sparing - reassign all sectors to skip the bad one
📼 Tertiary Storage
- Tapes, optical disks (CD/DVD), removable drives
- Very slow but cheap and portable
- Used for archival/backup storage
- Accessed sequentially (tapes) or near-randomly (optical)
Why RAID?
A single disk can fail. RAID spreads data across multiple disks to improve reliability and/or performance. Two key techniques: redundancy (copies) and striping (parallelism).
| RAID Level | Name | Technique | Fault Tolerance | Performance |
|---|---|---|---|---|
| RAID 0 | Striping | Data spread across disks, no redundancy | ❌ None | ⚡ Best (parallel reads/writes) |
| RAID 1 | Mirroring | Full copy on each disk | ✅ Excellent (N-1 failures) | Read fast, write same as 1 disk |
| RAID 4 | Block-level striping + dedicated parity | One disk stores parity blocks | ✅ 1 failure | Parity disk is bottleneck |
| RAID 5 | Distributed parity | Parity distributed across all disks | ✅ 1 failure | ✅ Good balance |
| RAID 6 | Double parity | Two parity blocks per stripe | ✅ 2 failures | Good, more overhead |
| RAID 10 | Stripe of Mirrors | RAID 0 + RAID 1 combined | ✅ Excellent | ⚡ Excellent |
🧠 RAID Levels Mnemonic
0 = Zero protection (speed only) | 1 = One full mirror | 5 = Five-star balance | 6 = Six is safer (2 parity) | 10 = Best of both worlds (stripe + mirror)
🎯 How to Tackle Disk Scheduling Problems
- Write out the request queue and starting head position clearly
- For SCAN/C-SCAN/LOOK/C-LOOK: establish the initial direction
- Draw the sequence of head movements step by step
- Compute |difference| between consecutive positions and sum them
- Remember: only SSTF can cause starvation
🧠 The "Elevator" Map
SSTF → Nearest First
SCAN → ↑ then ↓ (to edge)
C-SCAN → ↑ always, jump ↩
LOOK → ↑ then ↓ (to last req)
C-LOOK → ↑ always, jump to first req
🧠 Disk Structure ABC
Track = ring on platter
Cylinder = stack of tracks
Platter = the disk
Arm = moves head radially
What OSes Use in Practice
Linux uses a variant of C-LOOK (deadline scheduler) with a real-time deadline to prevent starvation. Windows uses similar priority-based disk scheduling.
SSD Scheduling
SSDs don't need seek optimization since there's no moving head. FCFS or simple FIFO is often used with SSDs, because random access costs the same as sequential.
Access Time Formula - Always Draw It
In exams, if asked about access time, write: Total = Seek + Rotation + Transfer. Identify
which value you're given and what you need to calculate.
RAID Questions
Know RAID 0 (no fault tolerance, max speed), RAID 1 (mirroring), RAID 5 (distributed parity, best balance). These three appear most in exams.
(a) Faster but volatile (b) Faster and nonvolatile (c) Slower but cheaper (d) Larger and volatile Quiz 1
LOOK vs C-LOOK: LOOK is like SCAN but stops at the last request (doesn't go all the way to the disk edge). C-LOOK is like C-SCAN but jumps to the first pending request instead of cylinder 0. Both LOOK variants are more efficient than SCAN/C-SCAN.
Disk scheduling algorithms focus on minimizing seek time because it is the largest and most variable component. Rotational latency and transfer time are fixed by disk hardware and cannot be controlled by the OS.
RAID 0 provides NO fault tolerance - it only uses striping. If one disk fails, ALL data is lost. "RAID 0 = Zero protection."
(2) File size estimation: Must know file size in advance to allocate contiguous space. Hard for output files whose size isn't known ahead.
(3) Files cannot grow: If adjacent space is taken, the file must be moved entirely to find a larger contiguous area.