Disk Management
Chapter Ninety-Seven
Syllabus topic Module 2, "Mass-Storage Structure - Disk Management"
Pages 389 to 393 of 452
In one line
A disk arrives as magnetic surface and has to be divided into sectors, given a file system, made bootable, protected from its own bad spots, and partly reserved for paging.
Low level formatting
Low level, or physical, formatting divides each track into sectors the controller can read and write. It is usually done at the factory.
Each sector is written as three parts:
| Part | What is in it | Why |
|---|---|---|
| header | the sector number | so the controller knows which sector it is reading |
| data area | the bytes, usually 512 | the sector's contents |
| trailer | an error correcting code | to detect, and often repair, a sector that has decayed |
The error correcting code is recomputed on every write and checked on every read. If the check fails but the code can repair the damage, the controller repairs it silently and the operating system never knows: that is a soft error. If it cannot, the read fails, and that is a hard error.
The header and trailer are overhead, so a disk holds less than cylinders times sectors times 512 bytes of usable data, and a larger sector size wastes proportionally less of the surface on headers.
Partitioning and logical formatting
| Step | What it does |
|---|---|
| partitioning | divides the array of blocks into ranges, each treated as a separate disk. Chapter ninety three measured one: a start block and a length |
| logical formatting, or making a file system | writes the initial structures into a partition: the free space map, an empty root directory, and the superblock of Chapter fifty six hundred five |
The operating system may also group blocks into clusters of several blocks: the disk transfers blocks, but the file system allocates clusters, which reduces the size of the structures that track free space and makes transfers longer and more sequential.
Some programs, chiefly databases, ask for a partition with no file system at all and do their own organisation. That is called raw disk access, and it exists because a database knows its own access pattern better than a general purpose file system does.
The boot block
The sequence a question asks for, and it is a chain of four steps because each stage can only hold so much code.
| Step | Where the code is | What it does |
|---|---|---|
| 1 | ROM, on the motherboard | a tiny bootstrap loader. It cannot be changed, so it is kept as small as possible |
| 2 | the boot block, the first blocks of the boot disk | the ROM loads the full bootstrap program from it |
| 3 | the boot partition | the full bootstrap knows the file system, finds the kernel, and loads it |
| 4 | the kernel | starts, and the machine is running |
Disk Management
On a system with a master boot record, the first block holds the partition table and a small loader, and the partition marked bootable holds the next stage. The reason for the indirection is that ROM is fixed at manufacture and everything after it can be replaced: a new kernel does not need a new motherboard.
A disk with no bootstrap in its boot block is a perfectly good disk that cannot start the machine. That is why the boot block is written by a separate step and not by the file system.
Bad blocks
Disks develop bad sectors, and there are three ways of living with them. A question asks for the difference between the last two.
| Method | What happens | Cost |
|---|---|---|
| mark them at format time | the format program tests each sector and writes a value into the file system's structures meaning "unusable"; the file system never allocates it | simple, and it must be done again if a sector fails later |
| sector sparing, also called forwarding | the controller keeps a pool of spare sectors. A bad sector's number is remapped to a spare, and the operating system keeps using the same block number | the spare is somewhere else on the disk, so that block now costs a seek |
| sector slipping | the sectors are renumbered so the whole run slides along by one, moving past the bad sector and keeping sequential order | the data from the last sector onwards must be copied one place along |
Sector sparing defeats disk scheduling, and that is the point worth making. Chapters ninety four to ninety six spent their effort on the order of block numbers; a remapped block is not where its number says it is, so the arm goes where the schedule did not intend. Controllers reduce the damage by keeping spare sectors in every cylinder, so the substitute is at least nearby.
And the honest part: the data in a bad sector is usually lost. Remapping gives you a working block number, not the bytes that were in it, which is why a system with important data has backups rather than confidence.
Swap space management
The next section of the same chapter in MU's textbook, and it finishes the module's memory story.
Where swap space lives
| In a raw partition | In a file in the file system | |
|---|---|---|
| Speed | faster: no file system structures, no directory lookup, and large contiguous runs | slower: the file system's own allocation and indirection are in the way |
| Flexibility | fixed size, decided when the disk is partitioned | easy to grow or add, no repartitioning |
| Used by | systems that care about paging speed | systems that value convenience |
Swap space is optimised for speed, not for space efficiency, which is the sentence to remember. The data in it lives only as long as the process does, so nothing is worth the overhead that protects a file.
Disk Management
How much
| The estimate is | What happens |
|---|---|
| too small | processes are aborted, or the system stops |
| too large | disk is wasted, and nothing else |
The traditional rule of twice physical memory dates from machines whose memory was small; a modern figure depends entirely on what the machine runs. The asymmetry is what matters in an answer: too little is fatal and too much merely wasteful.
Two designs worth naming
| System | What it does |
|---|---|
| an older design | copies the whole process image into swap space when the process starts, and pages from there |
| a newer one | swaps nothing at start: pages are read from the program file on demand, and space in swap is used only when a page is replaced and must be kept |
The second is better for the reason Chapter eighty gave: most of a program is never touched, so copying it all into swap is work thrown away. Note also that pages of program text need no swap at all, because they can always be read again from the program file, which is Chapter eighty four's clean victim.
What the lab machine has
$ swapon --show | wc -l
0
$ grep -c . /proc/swaps
1
$ grep -E '^Swap' /proc/meminfo
SwapCached: 0 kB
SwapTotal: 0 kB
SwapFree: 0 kBNo swap areas at all: swapon lists none, /proc/swaps has only its header line, and the totals are zero. This is the limitation Chapter eighty one and Chapter ninety one ran into and named. With no swap space there is nowhere to write a page of data, so this machine cannot page anonymous memory out, cannot show a major fault on data, and cannot be made to thrash. It kills a process that asks for too much instead.
What it can still do is everything the earlier measurements used: pages arriving on first touch, faults counted one per page, and copy on write. A missing swap area is a fact about this container, stated here rather than worked around.
Distinctions that carry marks
| Low level formatting | Logical formatting | |
|---|---|---|
| Creates | sectors, with header, data and error correcting code | the file system's structures in a partition |
| Done by | the manufacturer, usually | the operating system, on demand |
| After it the disk holds | numbered sectors | a usable file system |
| Sector sparing | Sector slipping | |
|---|---|---|
| The bad sector's number | is remapped to a spare elsewhere | is skipped by renumbering |
| Sequential order | broken: that block needs a seek | preserved |
| Cost | a seek on every use of that block | copying the data along by one sector once |
Disk Management
| Soft error | Hard error | |
|---|---|---|
| The error correcting code | repairs it | cannot repair it |
| The operating system | is not told | gets a failed read |
What it does not mean
Formatting a disk does not erase it securely. Logical formatting writes new structures; the old blocks are still there until something writes over them.
The boot block is not the kernel. It holds the bootstrap that finds the kernel.
A remapped sector does not recover the data. It gives a working block number.
Swap space is not virtual memory. It is the place pages go; Chapter eighty is why they can.
More swap space does not make a machine faster. It stops it failing when memory runs out; the paging is the cost.
Quick revision
- Low level formatting makes sectors of header, data and an error correcting code. The
code fixes soft errors silently; a hard error is a failed read.
- Partitioning divides the block array into ranges; logical formatting writes the file
system's initial structures. Raw disk access skips the file system, and databases use it.
- Boot: ROM bootstrap, then the boot block's full bootstrap, then the kernel from the
boot partition. ROM is fixed, so everything after it can be replaced.
- Bad blocks: marked at format time; sector sparing, which remaps to a spare and
defeats disk scheduling, so spares are kept per cylinder; or sector slipping, which renumbers and keeps sequential order.
- The data in a bad sector is usually lost either way.
- Swap space: a raw partition is faster, a file is more flexible; it is optimised for
speed, not space. Too little is fatal, too much is merely wasteful.
- Better design: nothing copied at start, pages read from the program file, swap used
only for pages that are replaced; program text needs no swap.
- The lab machine has no swap area, which is why it cannot show a major fault on data and
cannot thrash.
Test yourself
- What are the three parts of a formatted sector, and what is the third for? A header with
the sector number, the data area of usually 512 bytes, and a trailer holding an error correcting code, which detects and often repairs decay.
- Distinguish a soft error from a hard error. A soft error is repaired by the error
correcting code and never reported; a hard error cannot be repaired and the read fails.
- What does logical formatting do? It writes a file system's initial structures into a
partition: the free space map and an empty root directory among them.
- Why do some databases ask for a raw partition? Because they know their own access pattern
Disk Management
and can organise the blocks better than a general purpose file system.
- Give the boot sequence in four steps. The ROM bootstrap runs; it loads the full bootstrap
program from the boot block; that finds and loads the kernel from the boot partition; the kernel starts.
- Why is the bootstrap split between ROM and the boot block? ROM cannot be changed after
manufacture, so only a tiny loader lives there and everything replaceable lives on the disk.
- Distinguish sector sparing from sector slipping. Sparing remaps a bad sector's number to a
spare elsewhere on the disk, which costs a seek and breaks sequential order; slipping renumbers the sectors to move past the bad one and preserves the order, at the cost of copying the data along by one place.
- Why is sector sparing bad for disk scheduling? Because the schedule assumes block numbers
reflect position, and a remapped block is somewhere else; controllers keep spares in each cylinder to limit the damage.
- Compare swap space in a raw partition with swap space in a file. The partition is faster,
with no file system structures in the way and large contiguous runs; the file is easier to create, grow and remove.
- Why is it worse to have too little swap space than too much? Too little means processes
are aborted or the system stops; too much only wastes disk.
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.