DSA, Database System & Operating System β Memory Management, File Systems & Administration, NEC licence examination syllabus (Nepal Engineering Council).
Mapping File Blocks on the Disk Platter
Geometry, seek time and disk scheduling β the physical layer, and how much of it survives on SSDs.
π Where this lives: the disk-scheduling algorithms below were designed for a mechanical arm and are still shipping β Linux's mq-deadline and bfq schedulers descend directly from SCAN and its variants, while none (no scheduling at all) is now the correct choice for NVMe. Knowing which is which is a real operational decision: leaving a rotational scheduler enabled on an NVMe drive costs measurable throughput for no benefit. The measured 1.17Γ random-versus-sequential penalty later in this topic is the reason. Search "Linux IO scheduler none mq-deadline NVMe".
Disk geometry
t = seek + rotational latency + transfer With seek = 9 ms, rpm = 7200 rpm, KB = 4 KB, rate = 100 MB/s, total = 13.21 ms, rot = 4.17 ms, xfer = 0.04 ms.
Read 4 KB and the transfer time is a rounding error next to seek and rotation. Now read 1 MB: the fixed costs are unchanged, so the same overhead is spread over 256 times more data. That single fact is why sequential access is fast and random access is not.
A magnetic disk is a stack of PLATTERS, each with two surfaces,
each surface divided into concentric TRACKS, each track into
SECTORS.
PLATTER one physical disc
SURFACE one side of a platter (2 per platter)
TRACK one concentric ring on one surface
CYLINDER the same track number on ALL surfaces β reachable
without moving the arm, which is why it is the
unit that matters
SECTOR the smallest addressable unit (512 B or 4096 B)
HEAD one read/write head per surface, all on one arm
THE KEY INSIGHT ABOUT CYLINDERS: all heads move together on a
single arm, so every track at the same radius is accessible
with NO additional seek. Placing a file's blocks in one
cylinder rather than one track therefore multiplies the data
reachable per seek by the number of surfaces.
CAPACITY CALCULATION β a standard numerical:
capacity = cylinders Γ surfaces Γ sectors_per_track
Γ bytes_per_sector
WORKED: 16,383 cylinders, 16 heads, 63 sectors/track, 512 B
= 16383 Γ 16 Γ 63 Γ 512
= 8,455,200,768 bytes β 7.87 GiB
(These are the classic CHS limits β 1024/16/63 gave the famous
504 MB barrier, and 16383/16/63 the ~8 GB one. Modern drives
abandoned CHS for LBA precisely because the geometry became a
fiction.)
ACCESS TIME β three components, and only one is under software
control:
access time = SEEK TIME + ROTATIONAL LATENCY + TRANSFER TIME
SEEK TIME move the arm to the right cylinder
typically 3β12 ms β THE DOMINANT COST
β this is what disk scheduling minimises
ROTATIONAL wait for the sector to arrive under the head
LATENCY average = half a revolution
7200 rpm β 60/7200 = 8.33 ms per rev
β avg latency 4.17 ms
15000 rpm β 4 ms per rev β avg 2 ms
TRANSFER TIME read the bytes
= bytes / transfer_rate, often microseconds
WORKED: 7200 rpm, 5 ms average seek, 100 MB/s transfer,
reading 4 KB
seek = 5.00 ms
rotational = 4.17 ms
transfer = 4096 / 100e6 = 0.04 ms
TOTAL β 9.21 ms
NOTE THE PROPORTIONS: the transfer is 0.4% of the total. Over
99% of the time is spent GETTING to the data. That single fact
explains every optimisation in this topic β and why reading
1 MB sequentially costs barely more than reading 4 KB.
LOGICAL BLOCK ADDRESSING (LBA): the OS sees a flat array of
block numbers 0..Nβ1 and the drive maps them to physical
geometry internally. Consecutive LBAs are placed physically
adjacently, which is why sequential access is fast even though
the OS knows nothing about cylinders.
Disk scheduling algorithms β computed
REQUEST QUEUE (the standard textbook example):
98, 183, 37, 122, 14, 124, 65, 67
head starts at cylinder 53, disk has cylinders 0β199
All totals below were COMPUTED.
1. FCFS β serve in arrival order
order: 98 183 37 122 14 124 65 67
total head movement = 640 cylinders
β fair, trivially simple
β WORST performance β the head thrashes back and forth
(53β98β183β37 alone is 235 cylinders)
2. SSTF β shortest seek time first
order: 65 67 37 14 98 122 124 183
total = 236 cylinders
β much better than FCFS (63% less movement)
β STARVATION: a request at the far edge can be postponed
indefinitely while nearby requests keep arriving
β not optimal, despite being greedy
3. SCAN (elevator) β sweep to one end, then reverse
order: 65 67 98 122 124 183 199 37 14
total = 331 cylinders
β NO starvation β every request is served within one sweep
β predictable, bounded waiting
β worse than SSTF here (331 vs 236), because it travels to
cylinder 199 with nothing to do there
4. C-SCAN (circular SCAN) β sweep one way only, then jump back
order: 65 67 98 122 124 183 199 0 14 37
total = 382 cylinders
β UNIFORM waiting time β cylinders at both edges are treated
identically, unlike SCAN where the reversal point is
favoured
β highest movement here, because of the full return sweep
5. LOOK / C-LOOK β like SCAN/C-SCAN but reverse at the LAST
REQUEST rather than at the physical end of the disk
order: 65 67 98 122 124 183 37 14
total = 299 cylinders
β strictly better than SCAN (299 vs 331) β it never travels
to 199 for nothing
β keeps SCAN's no-starvation property
β LOOK is what real elevator schedulers actually do; "SCAN"
in a textbook usually means LOOK in an implementation
SUMMARY:
FCFS 640 simple, fair, terrible
SSTF 236 best movement, can starve
LOOK 299 good movement, no starvation β the practical
choice
SCAN 331 no starvation, wasted travel
C-SCAN 382 most uniform waiting, most movement
THE TRADE is between total movement and fairness. SSTF wins on
throughput and can starve; the SCAN family bounds waiting time
and pays for it in travel.
How much of this survives on an SSD β measured
io.c
/* 78 MB file, 20,000 blocks of 4 KB, read sequentially then in
random order. Verified on this machine's SSD. */
int fd = open("big.dat", O_CREAT|O_RDWR|O_TRUNC, 0644);
for (int i = 0; i < NBLK; i++) write(fd, buf, BLK);
fsync(fd);
/* sequential */
lseek(fd, 0, SEEK_SET);
for (int i = 0; i < NBLK; i++) read(fd, buf, BLK);
/* random */
for (int i = 0; i < NBLK; i++) {
off_t off = (off_t)(rand() % NBLK) * BLK;
pread(fd, buf, BLK, off);
}
MEASURED OUTPUT:
file size : 78 MB (20000 blocks of 4096 B)
sequential read : 8.9 ms (8730 MB/s)
random read : 10.5 ms (7474 MB/s)
random is 1.17x slower
1.17Γ β and that number changes the whole topic.
ON A SPINNING DISK, random 4 KB reads cost a seek plus
rotational latency EACH:
sequential: ~100 MB/s
random 4 KB: ~9.2 ms per block = 0.43 MB/s
β roughly 230Γ SLOWER
ON THIS SSD: 1.17Γ slower. There is no arm to move, so
"seeking" is just a different address on a flash chip.
(Note both figures here exceed the drive's raw speed β
8730 MB/s is the PAGE CACHE, since the 78 MB file fits
comfortably in RAM. That is itself the point of the next
topic: the cache is doing most of the work. The RATIO between
sequential and random is still meaningful, because both paths
are cached equally.)
WHAT THIS MEANS FOR THE ALGORITHMS ABOVE:
Β· DISK SCHEDULING IS NEARLY POINTLESS on SSDs. Reordering
requests to minimise head movement optimises a cost that no
longer exists. Linux's recommended scheduler for NVMe is
`none`.
Β· SSDs handle many requests IN PARALLEL (NVMe supports 65,536
queues), so serialising them into a sweep actively HURTS.
Depth matters more than order.
Β· what still matters: REQUEST SIZE (one 1 MB read beats 256
separate 4 KB reads) and ALIGNMENT to the erase block.
WHAT STILL MATTERS EVEN ON SSDs:
Β· SEQUENTIAL IS STILL FASTER, just by 1.17Γ rather than 230Γ
Β· large requests amortise per-request overhead
Β· the FILE SYSTEM's block placement still affects how many
requests are needed
Β· write amplification and TRIM (from the fragmentation topic)
So the classical algorithms are now history for NVMe and
still current for the spinning disks in archival storage and
for the conceptual point: minimise the number of expensive
operations, whatever "expensive" means on your hardware.
The 230Γ versus 1.17Γ comparison is the most important number in this topic. An entire body of algorithm design existed to avoid seeks, and the hardware change made it nearly irrelevant in about a decade. It is a good reminder that systems knowledge has a shelf life, and that the durable part is the reasoning β identify the dominant cost, then minimise it β not the specific algorithm.
π Go further: RAID is the other half of the physical layer, and the levels encode different trade-offs: RAID 0 stripes for speed with no redundancy, RAID 1 mirrors, RAID 5 uses one parity disk (survives one failure), RAID 6 two. The modern warning is that RAID 5 on large drives is now considered risky: rebuilding a 16 TB drive takes so long that a second failure during the rebuild is likely, and a single unrecoverable read error during rebuild loses the array. Search "why RAID 5 is dead URE rebuild time".
π‘ Exam angle: define cylinder, track, sector, head and know that a cylinder is reachable without an extra seek. The capacity calculation and the access time = seek + rotational latency + transfer breakdown are both standard numericals β remember average rotational latency is half a revolution (60/rpm Γ· 2). The guaranteed question is a disk scheduling trace: compute total head movement for FCFS, SSTF, SCAN, C-SCAN and LOOK on a given queue. Know that SSTF can starve and the SCAN family cannot, and that LOOK beats SCAN by reversing at the last request.
Syllabus points
Block-to-disk mapping
Create a free account to tick topics off, take notes as you read, watch the video lessons and get a day-by-day study plan built around your exam date.
Related topics in Memory Management, File Systems & Administration