Disk Scheduling, RAID and Storage Devices

HDDs versus SSDs, disk scheduling algorithms, RAID levels and their trade-offs, and how storage performance affects applications.

Est. 35 min Updated Suggest a fix
// Part 01 — Storage path

An I/O Request Has More Than One Cost

An application asks the operating system to read or write data. The request travels through filesystem and block layers to a device, then the completion travels back. Its total latency can include queueing, device service, filesystem work, controller behaviour, and cache effects. A fast disk cannot compensate for a database issuing many tiny synchronous writes, and a benchmark in cache may not represent durable storage.

Hard disk drives (HDDs) store data on rotating media and move a head to the requested track. Their mechanical positioning makes request order important. Solid-state drives (SSDs) use flash storage with no moving head, so seek distance does not have the same direct meaning. SSD controllers still manage queues, parallel flash channels, garbage collection, and wear; random access is not literally free.

CharacteristicHDDSSD
Mechanical movementHead seek and rotational delay matterNo moving head
Request orderingNearby requests can reduce head movementQueue depth and controller scheduling matter; geometry is abstracted
Small random readsOften costlier than sequential accessUsually much more practical, but latency still varies
WritesPhysical writes and cache policy matterFlash erasure, write amplification, and endurance matter
Failure planningMechanical and electronic failure possibleController, flash, firmware, or power failure possible
💡 Note
The OS sees logical block addresses, not a transparent map of where bytes physically sit. SSD firmware and storage controllers can reorder or combine requests, so a textbook algorithm predicts a simplified device, not every modern drive's exact behaviour.
// Part 02 — HDD scheduling

Reduce Head Travel Without Starving Requests

In a simplified HDD model, the head begins at one cylinder and serves pending requests. FCFS handles arrival order and is fair in that simple sense, but may move back and forth. SSTF selects the nearest pending cylinder and often reduces movement, but a request far away may wait a long time. SCAN sweeps in one direction, serving requests on the way, then reverses; C-SCAN serves in one direction and returns to the beginning without servicing on the return.

disk_head_movement.py
python
requests = [82, 170, 43, 140, 24, 16, 190]
start = 50


def total_movement(order, head):
    movement = 0
    for cylinder in order:
        movement += abs(cylinder - head)
        head = cylinder
    return movement


fcfs_order = requests
sstf_order = []
pending = requests.copy()
head = start
while pending:
    closest = min(pending, key=lambda cylinder: abs(cylinder - head))
    sstf_order.append(closest)
    pending.remove(closest)
    head = closest

print("FCFS order:", fcfs_order)
print("FCFS movement:", total_movement(fcfs_order, start))
print("SSTF order:", sstf_order)
print("SSTF movement:", total_movement(sstf_order, start))

Run the code to compare total cylinder movement for this one request set. That is a teaching metric, not a complete performance measurement: it excludes rotation, transfer size, queue wait, caching, and the possibility that another request arrives while the head is moving. Compare waiting time as well as total movement when evaluating fairness.

📌 Real World Example
On a busy shared HDD, SSTF can keep choosing requests near the current head while a distant request waits. An elevator sweep gives requests a turn as the head crosses their position, trading some shortest-path efficiency for more predictable service.
// Part 03 — Compare policies

SCAN and C-SCAN as Elevator Policies

Suppose a head is moving toward higher-numbered cylinders. SCAN serves requests ahead, reaches a chosen end of its sweep, then reverses. C-SCAN serves only while moving upward; after reaching the end it returns to the low end and begins another upward sweep. The return movement is counted as travel but does not serve requests. This tends to provide more uniform waiting across the address range in the simplified model.

  1. Sort pending requests by cylinder number.
  2. Split them into requests at or above the current head and requests below it.
  3. For SCAN, service the upward group, then the downward group in reverse order.
  4. For C-SCAN, service the upward group, wrap to the low end, then service the lower group upward.
  5. Compare total travel and per-request wait; do not conclude from distance alone.

Real systems may have several queues and device-specific scheduling. The scheduler may merge adjacent block requests, reorder for latency, or use priorities. Workload type matters: a sequential media scan, a database with many small random reads, and a laptop boot all create different request patterns.

// Part 04 — SSD considerations

No Seek Arm Does Not Mean No Scheduling

SSDs do not expose cylinders to applications. Their firmware maps logical blocks to flash pages, writes new data to available locations, and later reclaims blocks. Updating a small logical region can involve a larger internal unit of work, known as write amplification. Garbage collection can compete with foreground requests, which is one reason latency can vary even when there is no mechanical seek.

Host-side scheduling still matters for fairness, queueing, and I/O priorities. A device can process work in parallel, but excessive outstanding requests can increase tail latency and make one workload dominate another. A sequential access pattern may still help filesystems and applications, but the HDD rule "minimise cylinder distance" is not a useful direct model for SSDs.

TermMeaningOperational question
IOPSCompleted I/O operations per secondWhat block size and read/write mix produced the figure?
ThroughputBytes transferred per unit timeIs the workload sequential or random?
LatencyTime for an I/O request to completeWhat are median and tail values under load?
Queue depthOutstanding requests waiting or in flightDoes more concurrency improve throughput or only increase wait?
DurabilityWhether acknowledged data survives failuresWhat cache, flush, and replication guarantees apply?
// Part 05 — RAID basics

Redundancy, Performance and Capacity Trade Off

RAID combines disks into a logical storage set. Striping distributes blocks across devices and can improve parallel throughput, but striping alone does not provide redundancy. Mirroring keeps copies on separate devices and can continue after a device failure, at the cost of capacity. Parity stores calculated redundancy that can reconstruct missing data within the scheme's fault tolerance. RAID is not a substitute for backups: it does not protect against deletion, ransomware, site loss, or every controller and operator error.

LayoutIdeaCapacity / failure trade-off
RAID 0Stripe blocks across devicesUses combined capacity; a device failure can lose the array.
RAID 1Keep mirrored copiesUsable capacity is reduced; can tolerate a copy/device failure depending on layout.
RAID 5Striping with distributed parityParity overhead; can reconstruct one device failure, but rebuilds are a risk window.
RAID 6Striping with dual parityMore parity overhead; can reconstruct two device failures in the layout.
RAID 10Mirror pairs, then stripeCombines parallelism and mirrors; capacity and tolerance depend on which devices fail.
⚠️ Important
A RAID label does not guarantee a particular controller, filesystem, write-cache policy, or safe failure mode. Verify the exact implementation and test recovery. Keep independent, tested backups with a separate failure domain.
// Part 06 — Parity intuition

How a Parity Stripe Reconstructs One Missing Block

XOR parity illustrates the principle behind single-parity layouts. For three data bytes, parity is their bitwise XOR. If one byte is missing and the other data plus parity remain, XOR can recover it because a value XORed with itself cancels to zero. This toy program demonstrates the arithmetic only; real RAID must also manage block placement, failures, writes, metadata, and recovery safely.

xor_parity_demo.py
python
data = [0b1010, 0b1100, 0b0110]
parity = data[0] ^ data[1] ^ data[2]
print("data:", data)
print("parity:", parity)

missing_index = 1
survivors = [value for index, value in enumerate(data) if index != missing_index]
recovered = parity
for value in survivors:
    recovered ^= value
print("recovered block:", recovered)
print("matches original:", recovered == data[missing_index])

A real rebuild reads surviving blocks and computes missing data across the array. During rebuild, the remaining devices are under load and another failure may exceed the layout's tolerance. Monitor health, keep replacement procedures current, and regularly test restores from backups rather than treating a healthy RAID status as a backup.

// Part 07 — Observe I/O

Measure the Application Path, Not Just the Device

Start from a user-visible symptom: a report takes too long, a checkout times out, or a batch misses its window. Record application latency and correlate it with queueing and storage metrics. On Linux, tools such as iostatcan show device activity when installed; lsblk lists block devices. Tool output and available fields vary by platform, so check the local manual and avoid copying a command that silently changes a device.

observe-storage.sh
bash
# Read-only inventory and activity examples on Linux.
lsblk

# If sysstat is installed, inspect device metrics over a short interval.
iostat -xz 1 3

# Inspect filesystem capacity separately from device latency.
df -h

An online store can have a fast device but slow checkout because the application performs a synchronous write for every small update. A measurement should include realistic concurrency, request sizes, reads and writes, cache state, and the durability settings used in production. Do not run destructive benchmarks on a device with important data.

// Part 08 — Pitfalls

Common Storage Mistakes

Calling RAID a backup

Why: RAID helps with selected device failures but mirrors deletion and can share system-wide failures.

Fix: Keep versioned, separate backups and test restoring them.

Using SSTF movement as a full performance result

Why: The model omits rotational delay, queueing, caching, and fairness.

Fix: Treat it as a comparison exercise; measure real latency and wait time.

Assuming SSD latency is constant

Why: Queue depth, garbage collection, firmware, and workload can change response time.

Fix: Measure tail latency under the actual read/write mix.

Comparing IOPS without workload details

Why: Block size, concurrency, caching, and durability alter the result.

Fix: Record the workload and configuration alongside every benchmark.

// Part 09 — Practice

Design Storage for a Small Order Service

Practice

Explain the device, scheduler, and recovery plan

  1. Run the Python example with a different request list and compare FCFS with SSTF movement.
  2. Draw a SCAN service order for requests on both sides of the starting head position.
  3. For a photo archive, explain when sequential throughput matters more than small random-read latency.
  4. Compare RAID 1, RAID 5, and RAID 10 for capacity, failure tolerance, and rebuild risk without calling any of them a backup.
  5. Write a measurement plan that includes request size, read/write mix, concurrency, latency percentiles, and durability settings.

Hint: Begin with the workload and failure objective; choose a layout only after you know what data must survive.

🎯 Key Takeaways

  • ✓HDD request scheduling can reduce head movement; SSTF may starve distant requests while SCAN-style policies trade efficiency for fairness.
  • ✓SSDs remove mechanical seek but still have queueing, flash management, and variable latency.
  • ✓IOPS, throughput, latency, queue depth, and durability describe different properties.
  • ✓RAID striping, mirroring, and parity make different capacity and failure-tolerance trade-offs.
  • ✓RAID is not a backup; independent backups need regular restore tests.
  • ✓Measure storage with the application workload and durability settings you actually use.
  • For device and filesystem behaviour, use the operating system and storage-vendor documentation for the hardware you operate; implementations differ.

Next

What comes next

Storage is one resource the OS manages. Next, explore how hypervisors and containers isolate CPU, memory, processes, and filesystems.

Lesson 09 · Virtualisation and Containers — Hypervisors, Namespaces and cgroups →

HELP US IMPROVE

How was this lesson?

Your note is shared with the Chaduvuko team for review. Please don’t include personal or sensitive information.

Choose your feedback

Spotted a mistake or something unclear? Suggest a fix on GitHub or email us. Select the text first and it is quoted for you.

Share

Discussion

0

Have a better approach? Found something outdated? Share it — your knowledge helps everyone learning here.

Continue with GitHub
Loading...