Part 6 of 7 · 3 min read
Blocks, sector size and the rotational flag
What the OS sees
Think of a hotel where guests ask for "room 412" and never for "the third door on the left of the fourth floor". The front desk keeps the map. The analogy stops in one place: a hotel's room numbers never change, and a disk may quietly move a bad sector to a spare one under the same number.
In plain words: The OS addresses a disk by logical block address, a plain number. The drive keeps a map from each number to a place on a platter, and it can change the map without telling the OS, for example when it sets aside a damaged sector and uses a spare. The sector size is the smallest unit the OS can read or write. Older drives use 512 bytes. Newer drives use 4,096 bytes inside, and many still present 512-byte blocks to the OS for compatibility.
A worked example. A file system reads 4 KiB from LBA 1,000 on a drive that exposes 512-byte sectors. It asks for 4,096 / 512 = 8 sectors, numbered 1,000 to 1,007. If the drive stores 4,096-byte physical sectors, those eight logical sectors sit inside one physical sector when LBA 1,000 is a multiple of 8. Here 1,000 / 8 = 125, so the request is aligned. A request that began at LBA 1,001 would touch two physical sectors and the drive would have to read both and merge them.
The key lines. Linux shows what it knows about a disk in /sys/block. This command reads the flag and the sector sizes of the first virtual disk of the test machine.
$ cat /sys/block/vda/queue/rotational
0
$ cat /sys/block/vda/queue/logical_block_size /sys/block/vda/queue/physical_block_size
512
512
A 0 means the kernel believes the device has no moving parts. A 1 means a spinning disk. Some schedulers and file system tools use this flag to choose their behaviour. A virtual disk reports whatever its host decides to report.
Logical block address
A logical block address (LBA) is the number that the OS uses to name one block of a storage device, counted from 0. The device translates the number to a physical position, and it may change the translation, for example to replace a damaged sector.
Example: a request for LBA 1,000 with a count of 8 asks for eight consecutive 512-byte blocks that start at block 1,000.
Interview angle
A common question is "Why is sequential I/O faster than random I/O on a disk?" A good answer names the three delays, says that the first two are mechanical and are paid for each seek, and gives one number such as 13 ms for a 4 KiB random read against about 0.04 ms of transfer.
Check yourself:
1. Why can the OS not rely on LBA 1,000 and LBA 1,001 being physically next to each other?
2. When is a 4 KiB request at LBA 1,001 unaligned on a drive with 4 KiB physical sectors?
3. What does rotational equal on a spinning disk?
Words you will meet
| Word | Meaning |
|---|---|
| Platter | A flat round disk coated with magnetic material. |
| Track | One ring of data on one surface. |
| Sector | The smallest block of a track, 512 or 4,096 bytes. |
| Seek | Moving the arm to another track. |
| LBA | A block's number, counted from 0, as the OS names it. |
Quick notes
- A hard disk keeps data on spinning platters. All heads sit on one arm and move together.
- Request time = seek + rotational delay + transfer.
- Full turn in ms = 60,000 / RPM. Average rotational delay is half of that.
- Small requests are dominated by seek and rotation. Large ones approach the peak rate.
- Sequential reads can be a few hundred times faster than random reads on a spinning disk.
- The OS names blocks by LBA. The drive may remap them. Align requests to the physical sector.