Silberschatz,Galvin,and Gagne?199913.1Applied Operating System Concepts
Module 13,Secondary-Storage 二级存储
Disk Structure 磁盘结构
Disk Scheduling 磁盘调度
Disk Management 磁盘管理
Swap-Space Management 交换空间管理
Disk Reliability 磁盘可靠性
Stable-Storage Implementation 稳定存储实现
Tertiary Storage Devices 三级存储设备
Operating System Issues 有关操作系统的问题
Performance Issues 有关性能的问题
Silberschatz,Galvin,and Gagne?199913.2Applied Operating System Concepts
Disk Structure 磁盘结构
Disk drives are addressed as large 1-dimensional 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,0扇区是最外边柱面的第一个磁道的第一个扇区。
– 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,数据首先都映射到一个磁道,其余的数据映射到同一柱面的其他磁道,然后按照从外向里的顺序映射到其余的柱面。
Silberschatz,Galvin,and Gagne?199913.3Applied Operating System Concepts
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,旋转延迟是指等待磁盘上所需要的扇区旋转到磁头下面的时间。
Minimize seek time 最小寻道时间
Seek time? seek distance 寻道时间? 寻道距离
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,磁盘带宽,是用传输的总位数,除以第一个服务请求与最后传输完成之间的总时间。
Silberschatz,Galvin,and Gagne?199913.4Applied Operating System Concepts
Disk Scheduling (Cont.) 磁盘调度(续

Several algorithms exist to schedule the servicing of disk I/O
requests,有几种磁盘 I/O请求的服务调度算法
We illustrate them with a request queue (0-199),我们假设一个请求序列。
98,183,37,122,14,124,65,67
Head pointer 53 磁头当前的位置在 53。
Silberschatz,Galvin,and Gagne?199913.5Applied Operating System Concepts
FCFS 先来先服务
Illustration shows total head movement of 640 cylinders,如下图所示,磁头总共移动了 640个柱面的距离。
Silberschatz,Galvin,and Gagne?199913.6Applied Operating System Concepts
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,SSTF是 SJF调度的一种形式;
有可能引起某些请求的饥饿。
Illustration shows total head movement of 236 cylinders,如图所示,磁头移动的总距离是 236柱面。
Silberschatz,Galvin,and Gagne?199913.7Applied Operating System Concepts
SSTF (Cont.)
Silberschatz,Galvin,and Gagne?199913.8Applied Operating System Concepts
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,如图所示,磁头移动的总距离是 208柱面。
Silberschatz,Galvin,and Gagne?199913.9Applied Operating System Concepts
SCAN (Cont.)
Silberschatz,Galvin,and Gagne?199913.10Applied Operating System Concepts
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,把所有柱面看成一个循环的序列,最后一个柱面接续第一个柱面。
Silberschatz,Galvin,and Gagne?199913.11Applied Operating System Concepts
C-SCAN (Cont.)
Silberschatz,Galvin,and Gagne?199913.12Applied Operating System Concepts
C-LOOK
Version of C-SCAN 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,磁臂在每个方向上仅仅移动到最远的请求位置,然后立即反向移动,而不需要移动到磁盘的一端。
Silberschatz,Galvin,and Gagne?199913.13Applied Operating System Concepts
C-LOOK (Cont.)
Silberschatz,Galvin,and Gagne?199913.14Applied Operating System Concepts
Selecting a Disk-Scheduling Algorithm
选择一种磁盘调度算法
SSTF is common and has a natural appeal SSTF比较通用
,性能一般。
SCAN and C-SCAN perform better for systems that place a
heavy load on the disk,SCAN和 C-SCAN在重磁盘负载的系统中性能较好。
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,SSTF和 LOOK都是缺省算法的合理选择。
Silberschatz,Galvin,and Gagne?199913.15Applied Operating System Concepts
Disk Management 磁盘管理
Low-level formatting,or physical formatting — Dividing a disk
into sectors that the disk controller can read and write,低级格式化,或物理格式化 —— 把磁盘划分成扇区,以便磁盘控制器可以进行读写。
To use a disk to hold files,the operating system still needs to
record its own data structures on the disk,为了使用磁盘保存文件,操作系统还需要在磁盘上保存它自身的数据结构。
– Partition the disk into one or more groups of cylinders,
把磁盘划分成一组或多组柱面。
– Logical formatting or ―making a file system‖,逻辑格式化或“创建文件系统”。
Boot block initializes system,启动块初始化系统
– The bootstrap is stored in ROM,引导程序存储在 ROM中
– Bootstrap loader program,引导程序装载程序。
Methods such as sector sparing used to handle bad blocks,
一些方法,例如节省扇区,可以用来处理坏块。
Silberschatz,Galvin,and Gagne?199913.16Applied Operating System Concepts
Swap-Space Management 交换空间管理
Swap-space — Virtual memory uses disk space as an
extension of main memory,交换空间 —— 虚拟内存使用磁盘空间作为对主存的扩展。
Swap-space can be carved out of the normal file system,or,
more commonly,it can be in a separate disk partition,交换空间可以与常规的文件系统分离开,或者更通常的情况是放在一个单独的磁盘分区里。
Swap-space management 交换空间管理
– 4.3BSD allocates swap space when process starts;
holds text segment (the program) and data segment,
4.3BSD在程序开始时分配交换空间;保存正文段(程序
)和数据段。
– Kernel uses swap maps to track swap-space use,核心使用交换映射跟踪交换空间的使用情况。
– Solaris 2 allocates swap space only when a page is
forced out of physical memory,not when the virtual
memory page is first created,Solaris 2 仅在一页被交换出物理内存的时候分配交换空间,而不是在虚拟内存页最初生成的时候。
Silberschatz,Galvin,and Gagne?199913.17Applied Operating System Concepts
Disk Reliability 磁盘可靠性
Several improvements in disk-use techniques involve the use
of multiple disks working cooperatively,磁盘使用技术中,有几种实现都包括了使用多个磁盘协同工作方式。
Disk striping uses a group of disks as one storage unit,磁盘条使用一组磁盘作为一个存储单元。
RAID schemes improve performance and improve the
reliability of the storage system by storing redundant data,
RAID系统依靠存储冗余数据改善了存储系统的性能和可靠性。
– Mirroring or shadowing keeps duplicate of each disk,
镜像或影像为每个磁盘保存了备份。
– Block interleaved parity uses much less redundancy,
块交叉奇偶方式大大地减少了冗余。
Silberschatz,Galvin,and Gagne?199913.18Applied Operating System Concepts
Stable-Storage Implementation 稳定存储实现
Write-ahead log scheme requires stable storage,向前写日志系统需要稳定存储。
To implement stable storage,为了实现稳定存储
– Replicate information on more than one nonvolatile
storage media with independent failure modes,在多个非易失性存储介质上备份信息,这些介质具有不同的故障方式。
– Update information in a controlled manner to ensure that
we can recover the stable data after any failure during
data transfer or recovery,以一种有控制的方式更新信息
,以便确保在数据传输或修复的过程中发生错误以后我们能够恢复稳定的数据。
Silberschatz,Galvin,and Gagne?199913.19Applied Operating System Concepts
Tertiary Storage Devices 三级存储设备
Low cost is the defining characteristic of tertiary storage,三级存储的定义特征是低成本。
Generally,tertiary storage is built using removable media 通常,三级存储由可移动介质构成。
Common examples of removable media are floppy disks and
CD-ROMs; other types are available,通常的可移动介质的例子是软盘和光盘;其他还有一些类型。
Silberschatz,Galvin,and Gagne?199913.20Applied Operating System Concepts
Removable Disks 可移动磁盘
Floppy disk — thin flexible disk coated with magnetic material,
enclosed in a protective plastic case,软盘 —— 在又薄又软的盘面上涂上磁介质,装在一个用于保护的塑料套中。
– Most floppies hold about 1 MB; similar technology is
used for removable disks that hold more than 1 GB,大多数软盘的容量是 1MB; 类似的技术也用于可移动磁盘,
其容量大于 1GB。
– Removable magnetic disks can be nearly as fast as hard
disks,but they are at a greater risk of damage from
exposure,可移动磁盘的速度几乎与硬盘一样快,但由于是暴露在外的,损坏的风险更大。
Silberschatz,Galvin,and Gagne?199913.21Applied Operating System Concepts
Removable Disks (Cont.) 可移动磁盘(续)
A magneto-optic disk records data on a rigid platter coated
with magnetic material,光电磁盘在一个涂有磁介质的刚性盘面上记录数据。
– Laser heat is used to amplify a large,weak magnetic
field to record a bit,激光的热量用来放大一个大面积脆弱的磁区域,来记录一位。
– Laser light is also used to read data (Kerr effect),激光的光线也用来读取数据( Kerr效应)
– The magneto-optic head flies much farther from the disk
surface than a magnetic disk head,and the magnetic
material is covered with a protective layer of plastic or
glass; resistant to head crashes,光电磁头距离盘面的距离比磁头远,并且磁介质上覆盖有塑料或玻璃的保护层;抗磁头撞击。
Optical disks do not use magnetism; they employ special
materials that are altered by laser light,光盘不使用磁介质;
它们使用激光改造过的特殊材料。
Silberschatz,Galvin,and Gagne?199913.22Applied Operating System Concepts
WORM Disks
The data on read-write disks can be modified over and over,
可读写磁盘上的数据能够被反复修改。
WORM (―Write Once,Read Many Times‖) disks can be
written only once,WORM(,一次写,多次读“)盘只能被写一次。
Thin aluminum film sandwiched between two glass or plastic
platters,薄铝膜被加在两层玻璃或塑料盘中间。
To write a bit,the drive uses a laser light to burn a small hole
through the aluminum; information can be destroyed by not
altered,要写一位,驱动器用激光在铝膜上烧一个小洞;信息不能修改,只能被破坏。
Very durable and reliable,持久可靠。
Read Only disks,such as CD-ROM and DVD,com from the
factory with the data pre-recorded,只读盘,比如光盘和 DVD
,都是在工厂进行了数据预存储的。
Silberschatz,Galvin,and Gagne?199913.23Applied Operating System Concepts
Tapes 磁带
Compared to a disk,a tape is less expensive and holds more data,
but random access is much slower,与磁盘比较,磁带更便宜,并且能保存更多数据,但是随机访问非常慢。
Tape is an economical medium for purposes that do not require fast
random access,e.g.,backup copies of disk data,holding huge
volumes of data,如果不需要快速随机存取,磁带是一种经济的媒介,比如备份磁盘数据、保存极大量的数据
Large tape installations typically use robotic tape changers that
move tapes between tape drives and storage slots in a tape library,
大型磁带装置通常使用自动磁带机,把磁带从磁带库的磁带驱动器移动到存储槽。
– stacker – library that holds a few tapes 栈式存储器 —— 保存有一些磁带的库。
– silo – library that holds thousands of tapes 队式存储器 —— 保存有数以千计磁带的库。
A disk-resident file can be archived to tape for low cost storage; the
computer can stage it back into disk storage for active use,一个磁盘驻留文件可以存到磁带上,以便降低存储成本;计算机可以为了当前的使用,把它传输回到磁盘上。
Silberschatz,Galvin,and Gagne?199913.24Applied Operating System Concepts
Operating System Issues 有关操作系统的问题
Major OS jobs are to manage physical devices and to present
a virtual machine abstraction to applications 主要的系统工作是管理物理设备,并且为应用程序提供一个虚拟机的抽象。
For hard disks,the OS provides two abstraction,对于硬盘,
操作系统提供两个抽象
– Raw device – an array of data blocks,Raw设备 —— 一个数据块的数组。
– File system – the OS queues and schedules the
interleaved requests from several applications,文件系统 —— 操作系统对几个应用程序交叉的请求进行排队和调度。
Silberschatz,Galvin,and Gagne?199913.25Applied Operating System Concepts
Application Interface 应用程序接口
Most OSs handle removable disks almost exactly like fixed disks — a
new cartridge is formatted and an empty file system is generated on the
disk,多数操作系统处理可移动磁盘的方式与固定磁盘几乎是一样的 —
— 格式化一个新的盘碟,同时在盘上生成一个空的文件系统。
Tapes are presented as a raw storage medium,i.e.,and application
does not not open a file on the tape,it opens the whole tape drive as a
raw device,磁带作为一个 raw存储介质,也就是说,应用程序不是打开磁带上的一个文件,而是作为 raw设备打开整个磁带。
Usually the tape drive is reserved for the exclusive use of that
application,通常磁带设备是由一个应用程序独占使用的。
Since the OS does not provide file system services,the application
must decide how to use the array of blocks,由于操作系统不提供文件系统服务,应用程序必须决定如何使用数据块的数组。
Since every application makes up its own rules for how to organize a
tape,a tape full of data can generally only be used by the program that
created it,由于每个应用程序对于如何组织一个磁带都建立了自己的规则,一个装满数据的磁带通常只能由创建它的应用程序来使用。
Silberschatz,Galvin,and Gagne?199913.26Applied Operating System Concepts
Tape Drives 磁带驱动器
The basic operations for a tape drive differ from those of a disk
drive,磁带驱动器的基本操作与磁盘驱动器是不同的。
locate positions the tape to a specific logical block,not an entire
track (corresponds to seek),定位操作指向磁带的一个特定逻辑块
,而不是一个完整的磁道(与寻道操作对比)
The read position operation returns the logical block number where
the tape head is,读位置操作返回磁带头所在的逻辑块号。
The space operation enables relative motion,间隔操作允许相关的运动。
Tape drives are ―append-only‖ devices; updating a block in the
middle of the tape also effectively erases everything beyond that
block,磁带驱动器是“只能附加”的设备;更新磁带中间的一个块
,需要先清除那个块上的所有数据。
An EOT mark is placed after a block that is written,写完的一块后面需要加上一个 EOT标记。
Silberschatz,Galvin,and Gagne?199913.27Applied Operating System Concepts
File Naming 文件命名
The issue of naming files on removable media is especially
difficult when we want to write data on a removable cartridge
on one computer,and then use the cartridge in another
computer,当我们想向一台计算机的一个可移动盘碟写入数据、然后在另一台计算机中使用的时候,命名文件的问题在可移动媒介上更加困难。
Contemporary OSs generally leave the name space problem
unsolved for removable media,and depend on applications
and users to figure out how to access and interpret the data,
现代操作系统通常没有解决可移动媒介上的命名空间问题,而是依靠应用程序和用户来指出如何访问解释数据。
Some kinds of removable media (e.g.,CDs) are so well
standardized that all computers use them the same way,一些可移动介质(比如 CD) 相当的规格化,所有的计算机都以同样的方式使用它们。
Silberschatz,Galvin,and Gagne?199913.28Applied Operating System Concepts
Hierarchical Storage Management (HSM)
层次存储管理
A hierarchical storage system extends the storage hierarchy
beyond primary memory and secondary storage to
incorporate tertiary storage — usually implemented as a
jukebox of tapes or removable disks,一个层次存储系统扩展了存储层次,从主存、二级存储到一体化的三级存储 —— 通常是一个磁带的自动播放机或者可移动磁盘。
Usually incorporate tertiary storage by extending the file
system,通常通过扩展文件系统来一体化三级存储。
– Small and frequently used files remain on disk,经常使用的小文件仍然存在磁盘上。
– Large,old,inactive files are archived to the jukebox,不使用的大的旧文件存在自动播放机上。
HSM is usually found in supercomputing centers and other
large installaitons that have enormous volumes of data,
HSM在超级计算中心和其他有庞大数据量的大设备中比较常见

Silberschatz,Galvin,and Gagne?199913.29Applied Operating System Concepts
Speed 速度
Two aspects of speed in tertiary storage are bandwidth and
latency,三级存储速度的两个方面是带宽和延迟。
Bandwidth is measured in bytes per second,带宽用每秒字节数来衡量。
– Sustained bandwidth – average data rate during a large
transfer; # of bytes/transfer time,
Data rate when the data stream is actually flowing,持续的带宽 —— 大量传输过程中的平均数据率;单位传输时间的字节数。数据流实际流动时的数据率。
– Effective bandwidth – average over the entire I/O time,
including seek or locate,and cartridge switching.
Drive’s overall data rate,有效带宽 —— 整个 I/O时间的平均,包括寻道或者定位,以及盘碟选择。驱动器的全面数据率
Silberschatz,Galvin,and Gagne?199913.30Applied Operating System Concepts
Speed (Cont.) 速度(续)
Access latency – amount of time needed to locate data,访问延迟 —
— 定位数据需要的时间。
– Access time for a disk – move the arm to the selected cylinder and
wait for the rotational latency; < 35 milliseconds,磁盘的访问时间 —— 移动磁臂来选择柱面,并且等待旋转延迟; <35毫秒。
– Access on tape requires winding the tape reels until the selected
block reaches the tape head; tens or hundreds of seconds,访问磁带需要把所选的块倒到磁带头的位置;数十甚至数百秒。
– Generally say that random access within a tape cartridge is about
a thousand times slower than random access on disk,一般来说
,对盘碟的随机访问比对磁盘的随机访问要慢一千倍。
The low cost of tertiary storage is a result of having many cheap
cartridges share a few expensive drives,三级存储成本低,这是许多便宜的盘碟使用少量昂贵驱动器的结果。
A removable library is best devoted to the storage of infrequently used
data,because the library can only satisfy a relatively small number of
I/O requests per hour,一个可移动的库对于很少使用的数据的存储是很好的,因为库每个小时只需要满足相对很少的 I/O请求。
Silberschatz,Galvin,and Gagne?199913.31Applied Operating System Concepts
Reliability 可靠性
A fixed disk drive is likely to be more reliable than a removable
disk or tape drive,固定磁盘驱动器比可移动磁盘或磁带驱动器更可靠。
An optical cartridge is likely to be more reliable than a magnetic
disk or tape,光介质比磁介质的磁盘或磁带更可靠。
A head crash in a fixed hard disk generally destroys the data,
whereas the failure of a tape drive or optical disk drive often
leaves the data cartridge unharmed,对于固定的硬盘,磁头撞击通常会破坏数据,然而磁带或光盘驱动器的错误通常对数据盘碟是无害的。
Silberschatz,Galvin,and Gagne?199913.32Applied Operating System Concepts
Cost 成本
Main memory is much more expensive than disk storage 主存比磁盘存储要贵很多。
The cost per megabyte of hard disk storage is competitive
with magnetic tape if only one tape is used per drive,硬盘存储的每兆字节成本与磁带不相上下,如果每个驱动器只用一条磁带。
The cheapest tape drives and the cheapest disk drives have
had about the same storage capacity over the years,近年来
,最便宜的磁带驱动器和最便宜的磁盘驱动器的存储容量几乎一样。
Tertiary storage gives a cost savings only when the number of
cartridges is considerably larger than the number of drives,
只有当盘碟的数量远大于驱动器数量的时候,三级存储才能节约成本。