munotes®

Disk Management

Get access to whole semester resourcesSemester Pass

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:

PartWhat is in itWhy
headerthe sector numberso the controller knows which sector it is reading
data areathe bytes, usually 512the sector's contents
traileran error correcting codeto 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

StepWhat it does
partitioningdivides 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 systemwrites 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.

StepWhere the code isWhat it does
1ROM, on the motherboarda tiny bootstrap loader. It cannot be changed, so it is kept as small as possible
2the boot block, the first blocks of the boot diskthe ROM loads the full bootstrap program from it
3the boot partitionthe full bootstrap knows the file system, finds the kernel, and loads it
4the kernelstarts, and the machine is running
munotes.in389

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.

MethodWhat happensCost
mark them at format timethe format program tests each sector and writes a value into the file system's structures meaning "unusable"; the file system never allocates itsimple, and it must be done again if a sector fails later
sector sparing, also called forwardingthe 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 numberthe spare is somewhere else on the disk, so that block now costs a seek
sector slippingthe sectors are renumbered so the whole run slides along by one, moving past the bad sector and keeping sequential orderthe 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 partitionIn a file in the file system
Speedfaster: no file system structures, no directory lookup, and large contiguous runsslower: the file system's own allocation and indirection are in the way
Flexibilityfixed size, decided when the disk is partitionedeasy to grow or add, no repartitioning
Used bysystems that care about paging speedsystems 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.

munotes.in390

Disk Management

How much

The estimate isWhat happens
too smallprocesses are aborted, or the system stops
too largedisk 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

SystemWhat it does
an older designcopies the whole process image into swap space when the process starts, and pages from there
a newer oneswaps 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 kB

No 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 formattingLogical formatting
Createssectors, with header, data and error correcting codethe file system's structures in a partition
Done bythe manufacturer, usuallythe operating system, on demand
After it the disk holdsnumbered sectorsa usable file system
Sector sparingSector slipping
The bad sector's numberis remapped to a spare elsewhereis skipped by renumbering
Sequential orderbroken: that block needs a seekpreserved
Costa seek on every use of that blockcopying the data along by one sector once
munotes.in391

Disk Management

Soft errorHard error
The error correcting coderepairs itcannot repair it
The operating systemis not toldgets 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

  1. 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.

  1. 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.

  1. 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.

  1. Why do some databases ask for a raw partition? Because they know their own access pattern
munotes.in392

Disk Management

and can organise the blocks better than a general purpose file system.

  1. 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.

  1. 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.

  1. 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.

  1. 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.

  1. 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.

  1. 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.

munotes.in393

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.

Issue
Done!