操作系统笔记 CH12 Mass-Storage Structure

磁盘

扇区0是最外面柱面的第一个磁道的第一个扇区。映射先按磁道内扇区顺序,再按柱面内磁道顺序,最后按从外到内的柱面顺序来排序的。

Head crash results from disk head making contact with the disk surface. Cannot be repaired, the entire disk must be replaced.

Disks can be removable

Host controller in computer uses bus to talk to disk controller built into drive or storage array.

The disk controller operates the disk-drive hardware to carry out the command.

Disk controllers have a built-in cache. Data transfer at the disk drive happens between the cache and the disk surface. Data transfer to the host, at fast electronic speeds, occurs between the cache and the host controller.

磁带

长久,存储大量数据。慢

磁盘结构

Disk drives are addressed as large 1-dimensional arrays of logical blocks, where the logical block is the smallest unit of transfer.

Low-level formatting(低级格式化) creates logical blocks on physical media.

  • Constant Linear Velocity ( 常数线性周转率)

    the density of bits per track is uniform

    CD-ROM, DVD-ROM

  • Constant Angular Velocity ( 常数角周转率)

    the density of bits decreases from inner tracks to outer tracks

    hard disk

disk attachment

计算机访问磁盘存储两种方式

  • 通过IO端口(或主机附属存储)

    小系统采用这种方法

  • 通过分布式文件系统DFS的远程主机,称为网络附属存储

Host-attached storage

Is accessed through I/O ports talking to I/O busses

I/O directed to bus ID, device ID, logical unit (LUN)

Network-Attached Storage (NAS)

客户通过远程进程调用接口访问NAS

UNIX中的NFS,windows中的CIFS(Common Internet File System)

RPCs are carried via TCP or UDP on IP network.

The NAS unit is usually implemented as a RAID array with software that implements the RPC interface.

New iSCSI protocol uses IP network protocol to carry the SCSI protocol. Remotely attaching to devices (blocks)

Storage Area Network (SAN)

服务器与存储单元之间的私有网络(采用存储协议而非网络协议)

灵活

Common in large storage environments.

Multiple hosts attached to multiple storage arrays – flexible

SAN is one or more storage arrays Connected to one or more Fiber Channel switches

Hosts also attach to the switches.

Storage made available via LUN Masking from specific arrays to specific servers.

disk scheduling

Minimize seek time

OS maintains queue of requests, per disk or device.

controllers have small buffers and can manage a queue of I/O requests.

FSFC

SSTF Shortest Seek Time First

starvation

SCAN / elevator

到达另一端时,磁头改变方向

C-SCAN

当磁头移到另一端时,会马上返回磁盘开始。将柱面当成环链

LOOK

磁头只移动到一个方向上最远的请求为止

C-LOOK

磁盘调度算法的选择

SSTF is common and has a natural appeal

SCAN and C-SCAN对磁盘负荷大的系统执行较好,不会有starvation

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.

磁盘管理

磁盘格式化 disk formatting

低级格式化/物理格式化:将磁盘分成扇区以便磁盘控制器能读能写。为每个扇区采用特殊的数据结构。The data structure typically consists of a header(sector #), a data area, and a trailer(ECC, error correction code) 扇区通常512B,但可选

OS需要将自己的数据结构记录在磁盘上

  1. 将磁盘分为由一个或多个柱面组成的分区。将每个分区作为一个逻辑磁盘。

  2. Logical formatting逻辑格式化

    创建文件系统

为了提高效率,大多数OS将块集中到一大块,称作簇(cluster)。磁盘IO通过块完成,文件系统IO通过簇完成

raw disk生磁盘:将磁盘分区作为一个逻辑块的大顺序数组,没有任何文件系统数据结构

raw disk可用作swap space

对该数组的IO称作raw IO

有些数据库系统比较喜欢raw IO

boot block 引导块

bootstrap程序应找到磁盘上的操作系统内核,装入内存,并转到起始地址,从而开始OS的执行

bootstrap保存在ROM中。不过大多数OS只在ROM中保留bootstrap loader: 进一步从磁盘上调入更完整的bootstrap程序

完整的bootstrap程序在磁盘的启动块(boot block)上,启动块位于磁盘的固定位置。

拥有启动分区的磁盘称为boot disk或system disk

启动扇区 MBR master boot record . Besides boot code, the MBR contains a partition table listing the partitions for the hard disk and a flag indicating which partition the system is to be booted from.

启动ROM中的代码引导磁盘控制器将启动块读入到内存(此时尚未装入设备驱动程序)

硬盘分为一个或多个分区,一个分区为boot partition,包含OS和设备驱动程序。该分区的第一个扇区既是boot sector

bad blocks

Controller calculates the ECC and finds the sector is bad. 控制器计算ECC

An unrecoverable hard error results in lost data.

对于简单磁盘:坏块可手工处理

对于复杂磁盘:

​ 控制器维护一个磁盘坏块链表,控制器可用备用块来逻辑地替换坏块 sector sparing(forwarding)

​ sector slipping


最后修改于 2020-02-28