Download ch14

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
Transcript
Chapter 14
Mass-Storage Structure
1
Disk Structure
磁碟結構
Disk drives are addressed as large 1dimensional arrays of logical blocks, where
the logical block is the smallest unit of
transfer.
The 1-dimensional array of logical blocks is
mapped into the sectors of the disk
sequentially.


Sector 0 is the first sector of the first track on the
outermost cylinder.
Mapping proceeds in order through that track,
then the rest of the tracks in that cylinder, and
then through the rest of the cylinders from
outermost to innermost.
2
磁碟排程
Disk Scheduling
The operating system is responsible for using
hardware efficiently — for the disk drives, this
means having a fast access time and disk bandwidth.
Access time has two major components
尋找時間
旋轉延遲


Seek time is the time for the disk are to move the heads to
the cylinder containing the desired sector.
Rotational latency is the additional time waiting for the disk
to rotate the desired sector to the disk head.
Disk bandwidth is the total number of bytes
磁碟頻寬
transferred, divided by the total time between the
first request for service and the completion of the
last transfer.
3
Multiple Choices Question:
(
)Two major determining factors of
disk access time is the _________
and the rotational latency.
(A) around time (B) feedback time
(C) seek time (D) execution time
(E) wait time
Ans: C
4
Disk Scheduling (Cont.)
Several algorithms exist to schedule the
servicing of disk I/O requests.
We illustrate them with a request queue (0199).
98, 183, 37, 122, 14, 124, 65, 67
Head pointer 53
5
FCFS
Illustration shows total head movement of 640 cylinders.
6
SSTF
Selects the request with the minimum
seek time from the current head
position.
SSTF scheduling is a form of SJF
scheduling; may cause starvation of
some requests.
Illustration shows total head movement
of 236 cylinders.
7
SSTF (Cont.)
8
SCAN
The disk arm starts at one end of the
disk, and moves toward the other end,
servicing requests until it gets to the
other end of the disk, where the head
movement is reversed and servicing
continues.
Sometimes called the elevator
algorithm.
Illustration shows total head movement
of 208 cylinders.
9
Multiple Choices Question:
(
) Which algorithm listed below is also
called “elevator algorithm”?
(A) SCAN (B) SSTF (C) LOOK
(D) C-LOOK (E) FCFS
Ans: A
10
SCAN (Cont.)
11
C-SCAN
Provides a more uniform wait time than
SCAN.
The head moves from one end of the disk to
the other. servicing requests as it goes.
When it reaches the other end, however, it
immediately returns to the beginning of the
disk, without servicing any requests on the
return trip.
Treats the cylinders as a circular list that
wraps around from the last cylinder to the
first one.
12
C-SCAN (Cont.)
13
C-LOOK
Version of C-SCAN
Arm only goes as far as the last
request in each direction, then reverses
direction immediately, without first
going all the way to the end of the disk.
14
C-LOOK (Cont.)
15
Selecting a Disk-Scheduling
Algorithm
SSTF is common and has a natural appeal
SCAN and C-SCAN perform better for systems that
place a heavy load on the disk.
Performance depends on the number and types of
requests.
Requests for disk service can be influenced by the
file-allocation method.
The disk-scheduling algorithm should be written as a
separate module of the operating system, allowing it
to be replaced with a different algorithm if necessary.
Either SSTF or LOOK is a reasonable choice for the
default algorithm.
16
True-False Question:
( )Either FCFS or LOOK is a
reasonable choice for the
default disk scheduling
algorithm.
Ans: X
17
§14.3
Disk Management
Disk Formatting
Boot Block
Bad Block
18
§14.3.1
Disk Formatting
Low-level formatting: Before a disk can
store data, it must be divided into
sectors that the disk controller can read
and write. It fills the disk with a special
data structure for each sector.



header
data area (usually 512 bytes)
trailer
19
Error-correcting code (ECC)
The header and the trailer contain
information used by the disk controller,
such as sector number and ECC.
ECC: value calculated from all the bytes
in the data area. Can be used to
calculate the correct value if few bits of
data have been corrupted.
The controller automaticaly does the
ECC processing whenever a sector is
read and written.
20
Disk Structure
To hold files, the OS needs to record its
own data structure on the disk.


First step: partition the disk into one or
more groups of cylinders. Each partition
can be treated as a separate disk.
Second step: logical formatting (or create
a file system). OS stores the initial filesystem data structures onto the disk.
 maps of free and allocated space
(FAT or inodes)
 initial empty directory
21
§14.3.2
Boot Block
Initial (tiny) bootstrap loader program
stored in read-only memory (ROM) to
bring in a full bootstrap program from
disk.
The full bootstrap program is stored in
a partition called the boot block, at a
fixed location on the disk.
A disk that has a boot partition is called
a boot disk or system disk.
22
MS-DOS disk layout
23
§14.3.3
Bad Blocks
Frequently, one or more sectors
become defected... Bad blocks. They
are handled differently:

IDE controller: handled manually.
When formatting, also scans the disk to
find bad blocks. If bad blocks are found, it
is remembered in the FAT. Later bad
blocks must be found by manually run
chkdsk command to search.
24
Sector Sparing

SCSI controller:
The controller maintains a list of bad
blocks on the disk, which is initialized
during formatting and updated over the
life of the disk.
Formatting also set aside spare sectors for
replacing bad sectors logically...sector
sparing or forwarding.
25
Sector Sparing
A typical bad-sector transaction:




OS read a logical block
Controller calculates the ECC and finds it
bad. Reported to the OS.
During next reboot, the SCSI controller
replace the bad sector with a spare.
After that, requests this logical block is
translated into the replacement sector’s
address by the controller.
26
Sector Sparing
Redirection by the controller could
invalidate any optimization by the OS’s
disk-scheduling algorithm!
Provide a few spare sectors in each
cylinder, and a spare cylinder as well.
When a bad block is remapped, the
controller uses a spare sector from the
same cylinder, if possible.
27
Sector Slipping
Suppose logical block 17 becomes
defective, and the first available spare
follows sector 202.
Sector slipping would remap all the
sectors from 17 to 202, moving them
all down one spot.
This would frees up sector 18, so 17
can be mapped to it.
28
§14.4
Swap-Space Management
Virtual memory uses disk space as an
extension of main memory.
Decreases system performance but
provide better throughput for virtualmemory system.
29
§14.4.1
Swap-Space Use
Swapping uses swap space to hold the entire
process image.
Paging stores pages that have been pushed
out of main memory.
UNIX allow multiple swap spaces put on
separate disks so the loading placed on the
I/O system by paging and swapping can be
spread over the system’s I/O devices.
It is safer to overestimate than to
underestimate swap space.
30
§14.4.2
Swap-Space Location
Swap space can be from normal file
system or can be in a separate disk
partition.
1. From normal file system: inefficient.
Navigating the directory structure
takes time and extra disk accesses.

External fragmentation can greatly
increase swapping times by forcing
multiple seeks during reading or writing
of a process image.
31
Swap-Space Location
2. From separate disk partition: a
separate swap-space storage manager
is used to allocate and deallocate the
blocks.
Manager optimized for speed, not for
storage efficiency.
Although internal fragmentation may
increase, it is acceptable because data in
the swap space generally live for much
shorter amounts of time than do files in
the file system.
32
Swap-Space Management
Example -- UNIX
§14.4.3
UNIX 4.3 BSD preallocate swap space
to a process when it is started.
Enough space is set aside to hold the
program, known as the text pages or
text segment, and the data segemnt of
the process.
File system is consulted only once for
each text page.
33
Swap-Space Management
Example -- UNIX
§14.4.3
Two swap maps per process are used by
the kernel to track swap-space use.
The text segment is a fixed size of 512 KB
chunks allocated, except the final chunk
for last page.
34
Swap-Space Management
Example -- UNIX
§14.4.3
The data segment can grow over time, the
map contains swap addresses for blocks of
varying size.
Given index i, a block pointed to by swapi
map entry i is of size 2 x 16KB, to a
maximum of 2 MB.
35
Swap-Space Management
Example -- UNIX
§14.4.3
When a process tries to grow its data
segment beyond the final allocated block in
its swap area, the OS allocates another
double-sized block.
This scheme results in small processes using
only small blocks. It also minimizes
fragmentation.
36
Swap-Space Management
Example – Solaris 1
§14.4.3
Thrown away pages if selected for pageout.
More efficient to reread a page from the file
system than to write it to swap space and
then to reread it from there.
Solaris 2 allocates swap space only when a
page is forced out of physical memory,
rather than when the virtual-memory page
is first created.
37
§14.5
RAID Structure
Before, disk-organization techniques
called redundant arrays of inexpensive
disks (RAID) composed of small cheap
disks as a cost-effective alternative to
large, expensive disks.
Today, RAIDs are used for their higher
reliability and higher data-transfer rate,
rather than for economic reasons.
38