Sub topic 5
Computing disk access time
This chapter assumes you know how a magnetic disk is organized into platters, tracks, sectors and cylinders. It also assumes you can convert between milliseconds and seconds, and between RPM and rotation time.
The three components
The disk controller needs three things before it can deliver the data you asked for.
- Seek time is the time to move the head assembly to the target cylinder.
- Rotational latency is the time spent waiting for the target sector to rotate under the head.
- Transfer time is the time the head spends over the sectors being read or written.
Access time is their sum:
access time = seek time + rotational latency + transfer timeSeek and rotational latency are positioning costs. They are paid once per request, no matter how little data you read. Transfer time grows with the amount of data.
Computing each term
Rotation time and rotational latency
Convert RPM to the time of one rotation:
rotation time (ms) = 60,000 / RPMAt 7200 RPM, one rotation takes 60,000 / 7200 = 8.33 ms.
The target sector can be anywhere on the track. It is equally likely to be just arriving or almost a full turn away. So the average rotational latency is half a rotation, 4.17 ms at 7200 RPM. The worst case is a full rotation, 8.33 ms, and the best case is 0.
Transfer time
The head passes over every sector on the track once per rotation. Reading k sectors from a track with S sectors takes a fraction k / S of a rotation:
transfer time = rotation time × k / SWith 400 sectors per track at 7200 RPM, one sector takes 8.33 / 400 = 0.0208 ms. Eight sectors (a 4 KB block with 512-byte sectors) take 0.167 ms.
If a question gives a transfer rate instead, use transfer time = bytes / rate. If it gives bytes per track, the rate is bytes per track / rotation time. A track of 400 × 512 B = 204,800 B passing in 8.33 ms gives about 24.6 MB/s.
Seek time
Seek time depends on how far the head must travel, and it is not linear. Short seeks are dominated by acceleration and settling, so a track-to-track seek can be well under 1 ms while a full-stroke seek is 15 to 20 ms. Exam questions usually state an average seek time and use it directly. Some give a per-cylinder cost, such as 1 ms per 100 cylinders. In that case, the distance from the scheduling chapters feeds straight into this formula.
Worked example
A disk spins at 7200 RPM, has 400 sectors per track and an average seek time of 9 ms. Find the average time to read one 4 KB block, which is 8 sectors.
- Seek: 9 ms.
- Rotational latency: 8.33 / 2 = 4.17 ms.
- Transfer: 8.33 × 8 / 400 = 0.17 ms.
- Total: 9 + 4.17 + 0.17 = 13.33 ms.
Positioning accounts for about 99% of this time. This is why file systems try hard to keep related blocks together, and why disk schedulers try to cut seek distance.
The following code implements the same formula:
def avg_rotational_latency_ms(rpm):
# On average the target sector is half a rotation away.
rotation_ms = 60_000 / rpm
return rotation_ms / 2
def transfer_time_ms(rpm, sectors_per_track, sectors_read):
rotation_ms = 60_000 / rpm
return rotation_ms * sectors_read / sectors_per_track
def access_time_ms(seek_ms, rpm, sectors_per_track, sectors_read):
return (seek_ms
+ avg_rotational_latency_ms(rpm)
+ transfer_time_ms(rpm, sectors_per_track, sectors_read))
print(round(avg_rotational_latency_ms(7200), 2)) # 4.17
print(round(access_time_ms(9, 7200, 400, 8), 2)) # 13.33Random versus sequential access
Suppose you read a 1 MB file, which is 256 blocks of 4 KB, on the same disk.
- Random placement. Each block costs a full access of 13.33 ms. The total is 256 × 13.33 = about 3413 ms.
- Contiguous placement. You pay one seek and one rotational latency. The 2048 sectors then stream past the head. Transfer time is 8.33 × 2048 / 400 = 42.67 ms. The total is 9 + 4.17 + 42.67 = about 55.8 ms.
Contiguous placement is roughly 60 times faster. This comparison is the main reason contiguous allocation, and the linked and indexed schemes that try to approximate it, matter in the file-system chapters.
Edge cases and common errors
- Using a full rotation for latency. Unless the question says "worst case", use half a rotation. If it asks for the worst case, use a full rotation and the maximum seek.
- Forgetting that transfer is a fraction of a rotation. Transfer time is not the time of one whole rotation. It is that time scaled by
k / S. - Unit slips. RPM is per minute, so the constant is 60,000 ms. Check whether the problem uses KB as 1000 or 1024 bytes, and whether the sector size is 512 B or 4 KB.
- Multi-track reads. If a read spans several tracks, the simple formula ignores track-switch and head-switch time. A problem that gives a track-to-track seek time expects you to add it once for each track boundary crossed.
- Reading the same track again. A request on the cylinder the head is already on has zero seek time. Only the latency and transfer terms apply.
- Controller overhead. Some problems add a fixed controller or command overhead. Add it as a fourth term.
- Unrelated consecutive requests. When the problem says requests are in a queue, compute seek from head movement (the scheduling chapters). Average seek only applies when the cylinder is random.
Effective data rate
Because positioning dominates small requests, the achieved data rate is far below the media rate. For the 4 KB read above, 4096 B in 13.33 ms is about 0.31 MB/s, while the media rate is about 24.6 MB/s. Larger requests amortize the fixed seek and latency cost. This is why operating systems read ahead, why file systems allocate in extents, and why buffering and caching (covered earlier) help so much.
Exercise
A disk rotates at 15,000 RPM and has 1000 sectors per track. The average seek time is 4 ms. Find the average time to read 100 contiguous sectors on one track.
Show answer
Rotation time = 60,000 / 15,000 = 4 ms. Average rotational latency = 4 / 2 = 2 ms. Transfer time = 4 × 100 / 1000 = 0.4 ms. Total = 4 + 2 + 0.4 = 6.4 ms.
Exercise
Using the 7200 RPM disk from the worked example (400 sectors per track, 9 ms average seek), how long does it take to read 4 KB blocks that sit at random places on the disk, if you read 100 of them, compared with reading 100 blocks stored contiguously (800 sectors on consecutive tracks, ignoring track-switch time)?
Show answer
Random: each block costs 13.33 ms, so 100 blocks take about 1333 ms. Contiguous: one seek and one latency (9 + 4.17 = 13.17 ms) plus transfer of 800 sectors = 8.33 × 800 / 400 = 16.67 ms, for a total of about 29.8 ms. Contiguous is about 45 times faster.
Exercise
A disk has a worst-case seek of 18 ms, spins at 5400 RPM and has 300 sectors per track. What is the worst-case time to read a single sector?
Show answer
Rotation time = 60,000 / 5400 = 11.11 ms. Worst-case rotational latency is a full rotation, 11.11 ms. Transfer of one sector = 11.11 / 300 = 0.037 ms. Total = 18 + 11.11 + 0.037 = about 29.15 ms.