Disk Structure, and the Logical Block
Chapter Ninety-Three
Syllabus topic Module 2, "Mass-Storage Structure - Disk Structure, Disk Attachment"
Pages 374 to 377 of 452
In one line
The operating system does not address cylinders and heads: it treats the disk as one long array of numbered blocks, and the disk itself hides the geometry.
The array of logical blocks
A disk is presented as a one dimensional array of logical blocks, numbered 0 upwards, and the logical block is the smallest unit the operating system transfers.
| Sector | Logical block | |
|---|---|---|
| Whose unit | the disk's, in hardware | the operating system's |
| Size | 512 bytes usually | one or more sectors: 512, 1024, 4096 bytes |
| Numbered | by cylinder, track and position | 0 to n minus 1, one long line |
Everything above this chapter uses the block number and nothing else. That is the point of the abstraction: the file system of Chapter ninety eight asks for block 91,482 and neither knows nor cares where it is.
The mapping
The order in which the blocks are laid out, and a question asks for it in exactly this order.
| Level | Rule |
|---|---|
| 1 | sector by sector along a track |
| 2 | then track by track within the same cylinder, because those need no arm movement |
| 3 | then cylinder by cylinder, from the outermost inwards |
Track before cylinder, and that is the whole reason the order is worth learning. Block n and block n + 1 are almost always in the same cylinder, so reading in block order costs almost no seeking. It is why Chapter ninety two's sequential read was seventy times faster than the scattered one, and it is why Chapter one hundred seven's contiguous allocation works.
Converting a block number to a place, worked
A disk with 4 surfaces and 100 sectors per track. So one cylinder holds:
blocks per cylinder = 4 × 100 = 400
Where is logical block 1234?
1234 = 3 × 400 + 34
cylinder = 3
34 = 0 × 100 + 34
surface = 0
sector = 34
Cylinder 3, surface 0, sector 34.
And back again
Which block is cylinder 5, surface 2, sector 17?
block = 5 × 400 + 2 × 100 + 17 = 2000 + 200 + 17 = 2217
The method both ways in one line: divide by the blocks per cylinder, then by the sectors per track, and multiply in the same order to go back.
The capacity sum
The other standard sum, and it needs four numbers.
capacity = cylinders × surfaces × sectors per track × bytes per sector
Worked on the geometry that old machines were limited to, 16,383 cylinders, 16 heads, 63 sectors of 512 bytes:
16,383 × 16 × 63 × 512 = 8,455,200,768
8,455,200,768 bytes, which is the eight and a half gigabyte limit that once stopped disks from growing.
Disk Structure, and the Logical Block
Why the sums are a simplification
Real disks do not have a constant number of sectors per track, and a question that gives you one is giving you a model.
| The recording scheme | What it does | Consequence |
|---|---|---|
| constant angular velocity, the old way | the platter turns at a fixed speed and every track holds the same number of sectors | the outer tracks waste space, because their sectors are longer than they need to be |
| zoned recording, the modern way | outer tracks hold more sectors than inner ones | more capacity, but sectors per track is not one number |
| constant linear velocity, on optical discs | the sectors are the same length and the rotation speed changes with the track | more capacity again, and a variable spindle speed |
Two more reasons the mapping is not exact: bad sectors are remapped to spares elsewhere on the disk, so a block's neighbour may be far away, and the outermost tracks are sometimes reserved. The operating system cannot see any of it, which is the abstraction working as intended.
Disk attachment
MU's section names three ways a disk reaches a machine, and a question wants the distinction.
| Host attached | Network attached, NAS | Storage area network, SAN | |
|---|---|---|---|
| How it is reached | a local bus: SATA, SAS, USB | over the local network, by a file protocol such as NFS | a separate network dedicated to storage |
| What the client asks for | a block | a file | a block |
| Who runs the file system | this machine | the server | this machine |
| Used for | one machine's own disks | sharing files between machines | many servers sharing a pool of storage |
The distinction that carries the marks: NAS serves files and a SAN serves blocks. A machine using a SAN thinks it has its own disk; a machine using NAS knows it is talking to a file server.
Measured on the lab machine
The kernel publishes the block count of a device, which is all that is needed to work out its capacity.
$ cat /sys/block/vda/size
41943040
$ cat /sys/block/vda/queue/hw_sector_size
512
$ echo "capacity = $(( 41943040 * 512 )) bytes"
capacity = 21474836480 bytes
$ echo "that is $(( 41943040 * 512 / 1024 / 1024 / 1024 )) gigabytes"
that is 20 gigabytesForty one million sectors of 512 bytes: exactly twenty gigabytes. And the partition inside it is a range of block numbers and nothing more:
$ echo "starts at sector $(cat /sys/block/vda/vda1/start), and is $(cat /sys/block/vda/vda1/size) sectors long"
starts at sector 2099200, and is 39843807 sectors longA partition is arithmetic on block numbers. Nothing about the geometry appears anywhere, and Chapter ninety two showed that the machine's claim to be a rotating disk is not even true.
Disk Structure, and the Logical Block
Distinctions that carry marks
| Physical address | Logical block address | |
|---|---|---|
| Form | cylinder, surface, sector | one number |
| Who uses it | the disk's own controller | the operating system |
| Changes if a sector goes bad | yes, the spare is elsewhere | no: the number keeps working |
| Blocks per cylinder | Sectors per track | |
|---|---|---|
| Formula | surfaces × sectors per track | given, and on a real disk not constant |
| Used to find | the cylinder of a block | the surface and sector within it |
What it does not mean
A logical block is not a sector. It is one or more sectors, chosen by the file system.
Block order is not cylinder order. Blocks fill a whole cylinder, across all its surfaces, before moving to the next cylinder.
The geometry in a question is not a real disk's geometry. Zoned recording means sectors per track varies, and remapped bad sectors break the neighbour relation.
NAS is not a SAN. One serves files over the ordinary network; the other serves blocks over a network of its own.
A partition is not a physical division. It is a first block and a length.
Quick revision
- A disk is an array of logical blocks numbered from 0, and the block is the unit the
operating system transfers.
- The layout order:
sector by sector, then track by track inside the cylinder, then cylinder by cylinder outwards in. Track before cylinder, which is why sequential block numbers cost no seeking.
- Blocks per cylinder = surfaces × sectors per track. With 4 surfaces and 100 sectors, that
is 400.
- Block 1234 on that disk: 1234 = 3 × 400 + 34, so cylinder 3, surface 0, sector
34.
- Cylinder 5, surface 2, sector 17: 5 × 400 + 2 × 100 + 17 = 2217.
- Capacity = cylinders × surfaces × sectors per track × bytes per sector.
16,383 × 16 × 63 × 512 = 8,455,200,768 bytes.
- Real disks use zoned recording, so sectors per track varies; bad sectors are remapped;
the sums are a model.
- Host attached by SATA or SAS; NAS serves files over the network; a SAN serves
blocks over its own network.
- Measured: the lab disk is 41,943,040 sectors of 512 bytes, exactly 20 gigabytes,
and a partition is a start sector and a length.
Test yourself
- What does the operating system use to address a disk? A logical block number, from 0 to
one less than the number of blocks; the geometry is hidden by the disk.
- Give the order in which logical blocks are laid out. Sector by sector along a track, then
track by track within the same cylinder, then cylinder by cylinder from the outside inwards.
Disk Structure, and the Logical Block
- Why is track before cylinder the right order? Because the heads move together, so the
tracks of one cylinder need no arm movement: consecutive block numbers are cheap to read.
- A disk has 4 surfaces and 100 sectors per track. Where is logical block 1234? 400 blocks
per cylinder, so 1234 = 3 × 400 + 34: cylinder 3, surface 0, sector 34.
- Which block is cylinder 5, surface 2, sector 17 on that disk?
5 × 400 + 2 × 100 + 17 = 2217.
- Find the capacity of a disk of 16,383 cylinders, 16 heads and 63 sectors of 512 bytes.
16,383 × 16 × 63 × 512 = 8,455,200,768 bytes.
- Why is a constant sectors per track a simplification? Modern disks use zoned recording,
where outer tracks hold more sectors than inner ones, and bad sectors are remapped elsewhere.
- Distinguish NAS from a SAN. Network attached storage serves whole files over the ordinary
network and runs the file system itself; a storage area network serves blocks over a dedicated network, and the client runs the file system.
The rest of this subject
These notes are cut from the University's printed syllabus. Open the syllabus itself, or the past papers, for the same subject.