Title: COSC 243
1NETW 3005
Mass Storage (How discs work)
2Notice
- I was unaware just how much was missing in the
printed notes. - As a partial remedy for that, the lecture slides
will appear on the web within the next week.
NETW3005 (Operating Systems)
Lecture 11 - How discs work/44
2
3Reading
- For this lecture, you should have read Chapter 12
(Sections 1-4).
NETW3005 (Operating Systems)
Lecture 11 - How discs work/44
3
4Last lecture I/O systems
- Hardware ports, buses, controllers
- Application I/O interface
- Kernel I/O services
NETW3005 (Operating Systems)
Lecture 11 - How discs work/44
4
5This lecture How disks work
- The mechanics of disks
- Disk scheduling
- Formatting and booting
- Disk reliability bad blocks, RAIDs
- Swap space management
NETW3005 (Operating Systems)
Lecture 11 - How discs work/44
5
6The mechanics of disks
- A disk drive consists of
- a number of platters
- with two surfaces each
- arranged on a rotating spindle
- with a head for each surface.
NETW3005 (Operating Systems)
Lecture 11 - How discs work/44
6
7Some terminology
- A single disk platter has two surfaces.
- Each surface is organised into concentric circles
called tracks. - All tracks of the same radius form a cylinder.
- Each track is divided into sectors.
- A sector is the smallest addressable part of the
disk.
NETW3005 (Operating Systems)
Lecture 11 - How discs work/44
7
8The mechanics of disks
NETW3005 (Operating Systems)
Lecture 11 - How discs work/44
8
9Addressing
- Information on the disk is referenced by a
multi-part address which includes - drive number,
- cylinder number,
- surface number and,
- sector number.
NETW3005 (Operating Systems)
Lecture 11 - How discs work/44
9
10More terminology
- The heads all move together, accessing a cylinder
of the disk. - To access a particular sector, the heads are
moved to the appropriate cylinder, the correct
head is enabled, and the head waits until the
correct sector comes under it.
NETW3005 (Operating Systems)
Lecture 11 - How discs work/44
10
11Disk scheduling
- As we have seen, one of the bene?ts of the
kernels I/O subsystem is that a pool of pending
I/O requests can be scheduled. - Imagine a queue of I/O requests to a given disk.
- Ordering these requests in different ways will
result in different head seek times.
NETW3005 (Operating Systems)
Lecture 11 - How discs work/44
11
12Algorithms for disk scheduling
- Criteria for evaluating algorithms
- Seek time
- Fairness (in particular, starvation)
NETW3005 (Operating Systems)
Lecture 11 - How discs work/44
12
13FCFS scheduling
- Treat I/O requests in FCFS order.
Calculation of the seek time for the schedule
given on the next slide (98 - 53) (183 - 98)
(183 - 37) (122 - 37) (122 - 14) (124 -
14) (124 - 65) (67 - 65) 640 cylinders
Here we do not calculate the time but only the
number of cylinders' the head is moving that
gives us the distance which is directly
proportional to seek time i.e if the distance is
increasing seek time is also increasing
NETW3005 (Operating Systems)
Lecture 11 - How discs work/44
13
14Illustration shows total head movement of 640
cylinders.
NETW3005 (Operating Systems)
Lecture 11 - How discs work/44
14
15Advantages and disadvantages?
- Advantages?
- Fair.
- Simple to implement. (Simple also means quick!)
- Disadvantages?
- Theres nothing to stop big swings.
NETW3005 (Operating Systems)
Lecture 11 - How discs work/44
15
16Shortest seek-time first scheduling
- At any moment, choose the request with the
shortest distance from the current head position.
NETW3005 (Operating Systems)
Lecture 11 - How discs work/44
16
17Illustration shows total head movement of 236
cylinders.
NETW3005 (Operating Systems)
Lecture 11 - How discs work/44
17
18Advantages and disadvantages?
Seek time for SSTF is calculated as follows (65
- 53) (67 - 65) (67 - 37) (37 - 14) (98 -
14) (122 - 98) (124 - 122) (183 - 124)
236 this is so many cylinder movements not time
- Advantages?
- You get much shorter seek times this way, because
youre eliminating the big swings. (At least,
youll only get them if theres nothing closer.) - Disadvantages?
- Starvation is a possibility.
NETW3005 (Operating Systems)
Lecture 11 - How discs work/44
18
19Is SSTF optimal?
- No it is too short-sighted, i.e. no look-ahead.
- It is possible to develop an optimal algorithm,
but the time taken to calculate it means its not
really worth it. - For example if the head moves to 37 then 14 and
then 65, 67 and so on seek time will be less - (53 - 37) (37 - 14) (65 - 14) (67 - 65)
(98 - 67) (122 - 98) (124 - 122) (183 -
124) 208
NETW3005 (Operating Systems)
Lecture 11 - How discs work/44
19
20SCAN scheduling
- Start the disk at one end, and move right to the
other end, servicing all the I/O requests you get
to on your way. Then start in the other direction.
NETW3005 (Operating Systems)
Lecture 11 - How discs work/44
20
21Illustration shows total head movement of 236
cylinders.
NETW3005 (Operating Systems)
Lecture 11 - How discs work/44
21
22Advantages and disadvantages?
(53 - 37) (37 - 14) (14 - 0) (65 - 0) (67
- 65) (98 - 67) (122 - 98) (124 - 122)
(183 - 124) 236
- Advantages?
- Fairer? Do we prevent starvation?
- Disadvantages?
- Requests for the middle of the disk are
advantaged over those at the ends.
NETW3005 (Operating Systems)
Lecture 11 - How discs work/44
22
23C-SCAN scheduling
- Like SCAN, but when the head gets to one end, it
goes straight to the other end without servicing
any requests.
NETW3005 (Operating Systems)
Lecture 11 - How discs work/44
23
24NETW3005 (Operating Systems)
Lecture 11 - How discs work/44
24
25Advantages and disadvantages?
- Advantages?
- We dont favour any region of the disk.
- Disadvantages?
- Starvation is as possible here as in SCAN.
NETW3005 (Operating Systems)
Lecture 11 - How discs work/44
25
26C-LOOK scheduling
- Like C-SCAN, except that rather than going to the
ends of the disk, we only go as far as the
furthest request in each direction.
NETW3005 (Operating Systems)
Lecture 11 - How discs work/44
26
27NETW3005 (Operating Systems)
Lecture 11 - How discs work/44
27
28Advantages and disadvantages?
- Advantages?
- A definite win over C-SCAN.
- In practice, the C-versions of SCAN/LOOK are
preferred. - Disadvantages?
- Starvation, as with SCAN.
NETW3005 (Operating Systems)
Lecture 11 - How discs work/44
28
29Priority scheduling
- We might not want to treat all these requests as
equal, e.g. page-fault- generated requests might
need to be handled first.
NETW3005 (Operating Systems)
Lecture 11 - How discs work/44
29
30Influences on scheduling algorithms
- The choice of scheduling algorithm depends on how
the disk is set up to store ?les.
NETW3005 (Operating Systems)
Lecture 11 - How discs work/44
30
31How much head movement will there be in
- Contiguous allocation?
- head movement will be minimised for sequential
access, so best will be C-SCAN. - Linked allocation?
- more head seeks. Makes more sense to use SSTF.
- FATs / indexed allocation?
- here it really makes sense to cache the FAT/index
block or implement a hot spot.
NETW3005 (Operating Systems)
Lecture 11 - How discs work/44
31
32Where should index blocks be stored?
- Near the blocks containing the files data.
- Obviously that mightnt be possible.
- But if you have a choice
NETW3005 (Operating Systems)
Lecture 11 - How discs work/44
32
33Where should directories be stored?
- In the middle of the partition is a good idea, so
you never have more than half the disk to scan. - Or near the FAT.
- Best to cache recently-used directory info as
well.
NETW3005 (Operating Systems)
Lecture 11 - How discs work/44
33
34Disk formatting
- Low-level formatting normally done in the
factory. - Creates the sectors on the disk, and ?lls each
with an initial data structure - A header and trailer, containing information used
by the disk controller - e.g. sector number,
error-correcting code (ECC). - A data area (usually 512 bytes).
NETW3005 (Operating Systems)
Lecture 11 - How discs work/44
34
35Disk formatting
- Partitioning done by the operating system.
- Logical formatting making an (empty) file system.
NETW3005 (Operating Systems)
Lecture 11 - How discs work/44
35
36Bad blocks
- Sectors on a disk sometimes become defective.
- We need a strategy for preventing these blocks
being used. - The usual method is to keep a record of a disks
bad blocks.
NETW3005 (Operating Systems)
Lecture 11 - How discs work/44
36
37Strategies
- Simple
- invoke a program periodically to search for bad
blocks. - Sophisticated
- Keep a list of bad blocks, and update it when new
bad blocks are found. - In either case, set aside a number of spare
sectors which the O/S cant see, and redirect.
NETW3005 (Operating Systems)
Lecture 11 - How discs work/44
37
38Problems with sparing?
- They can mess up disk-scheduling algorithms,
because the O/S doesnt know about the
redirection.
NETW3005 (Operating Systems)
Lecture 11 - How discs work/44
38
39Solutions
- Put the scheduling in the controller.
- But that has problems of its own.
- Spread your spare sectors around on the disk.
- Sector slipping shuffling all the data on disk
to make room for the spare block right next to
the one its replacing.
NETW3005 (Operating Systems)
Lecture 11 - How discs work/44
39
40Error recovery and RAIDs
- Modern error-recovery strategies often involve
cooperation between several disks. - A frequent cooperation method is a RAID
(redundant array of independent disks). - Each block of data is broken into sub-blocks,
with one sub-block stored on each disk. - The disks have their rotations synchronised.
NETW3005 (Operating Systems)
Lecture 11 - How discs work/44
40
41RAIDs
- Mirroring each disk holds all the data.
- Block interleaved parity. A parity bit for the
group of sub-blocks is written to a special
parity block. If one of the sub- blocks is lost,
it can be recovered from the other sub-blocks
plus the parity block.
NETW3005 (Operating Systems)
Lecture 11 - How discs work/44
41
42Booting a system
- A computer needs a bootstrap program to run when
its turned on. - This program has several tasks
- to initialise CPU registers, main memory
- to load the kernel and start executing it.
- The initial program must be hardwired into the
computer (typically in ROM).
NETW3005 (Operating Systems)
Lecture 11 - How discs work/44
42
43Booting a system
- In fact, the initial program is often very small.
- Often it just loads a bigger bootstrap program,
and this program does the rest. - The program will be stored at a fixed location on
the disk, called the boot block.
NETW3005 (Operating Systems)
Lecture 11 - How discs work/44
43
44Swap-space management
- Recap memory management often uses a backing
store to hold data from processes being
multitasked. - We could implement swap space simply as a file
within a directory structure. - Problems with this approach?
NETW3005 (Operating Systems)
Lecture 11 - How discs work/44
44
45Swap-space management
- A more frequent solution is to create a special
partition for swap space. - The disk allocation algorithm on this partition
is optimised for speed, rather than memory
efficiency. - Some OSs can swap in both file space and raw swap
partitions, e.g. Solaris 2.
NETW3005 (Operating Systems)
Lecture 11 - How discs work/44
45
46Next Lecture
!Revision! Make sure you come along (Exam hints
are possible)