A typical bad sector transaction might be as follows ：
· The operating system is trying to access a logical block 87.
· The controller calculates ECC Value , Found that the block was broken , It notifies the operating system of this result .
· The next time the operating system restarts , You can run a special program to tell SCSI The controller replaces the bad block with a spare block .
· after , Whenever the system tries to access a logical block 87 when , This request is translated into the address of the sector replaced by the controller .
- 12.6 Exchange space management
- 12.7 RAID structure （ Redundant array of disks ）
- A system has a lot of disks , It has the opportunity to improve data reading and writing speed （ Because disk operations can be done in parallel ）. and , This setup also gives the system the opportunity to improve the reliability of data storage , Because redundant information can be stored on multiple disks . therefore , A damaged disk does not cause data loss . Here's a variety of disk organization techniques , Generally referred to as disk redundant array （RAID） technology , Usually used to improve performance and reliability .
- The solution to the reliability problem is to introduce redundancy .
- Copy each disk mirror technique mirroring
- Banding striping Using multiple disks , By spreading data across multiple disks , It can also improve the transmission rate . The simplest form is , Data slicing . （ Improve performance through parallel processing , But it doesn't improve reliability ）
- RAID Level
- Mirrors provide high reliability , But expensive , Dispersed （ Banding ） Provides high data transfer rates , But it doesn't improve reliability .
- 12.8 Stable storage implementation
- Stable storage ： Data stored on stable storage is never lost . In order to achieve this kind of storage , Need to have multiple storage devices with independent error mode （ Usually a disk ） Copy the required information on .
- Disk write There are three possible scenarios ： Successfully completed , Part of the mistake , Totally wrong .
- The redirection caused by this controller may invalidate the disk scheduling algorithm of the operating system . So , Most disks are formatted with a small number of spare blocks for each cylinder , There's also a spare cylinder . When bad blocks need to be remapped , The controller uses spare sectors of the same cylinder as much as possible .
- Another scheme for sector backup , Some controllers use sector sliding （sector slipping） To replace the bad sector . Here's an example ： Suppose the logic block 17 Go bad , The first block available in the spare sector 202 after . that , Sector gliding will take everything from 17~202 Slide one sector down , That's sector 202 Copy to spare sector ,201 To 202,200 To 201 etc. , Until the sector 18 Copy to sector 19. In this way, sliding the sector makes the sector 18 It's empty , In this way, the sector can be 17 Mapping to it .
- 12.1 Introduction to the structure of mass memory
- 11.1.1 disk
- Reading and writing head “ flight ” On the surface of each disk . Head and arm （disk arm） Connected to a , The magnetic arm can move all the heads together as a whole . The surface of the disk is logically divided into circular tracks （track）, The track is further divided into sectors （sector）. The collection of tracks at the same magnetic arm position forms a cylinder （cylinder）. Each disk drive has thousands of concentric cylinders , Each track can contain hundreds of sectors . The storage capacity of commonly used disk drives is determined by GB Calculated .
- When the disk is in use , The drive motor spins the disk at high speed . Most drives rotate per second 60~200 circle . There are two parts to disk speed . Transmission rate （transfer rate） It's the data transfer rate between the drive and the computer . Location time （positioning time）, Sometimes called random access time （random access time）, By seeking time （seek time）（ The time it takes to move the arm to the desired cylinder ） And spin wait time （rotational latency）（ Wait for the required sector to rotate under the magnetic arm ） form . A typical disk can transfer at a rate of megabytes per second , The seek time and spin wait time are milliseconds .
- Because the magnetic head is very thin （ A few microns ） On the air layer of , So the head is in danger of contacting the disk surface . Although the disk is coated with a thin protective layer , But the head can still damage the disk surface , This phenomenon is called head collision （head crash）. Head collision cannot be repaired , At this point, the entire disk must be replaced .
- 11.1.2 Magnetic tape
- 11.1.1 disk
- 12.2 Disk structure
- Modern disk drives can be seen as an array of one-dimensional logical blocks , The logical block is the smallest transmission unit . The size of a logical block is usually 512B, Although some disks can be low-level format to choose different logical block size , Such as 1024B,
- By mapping , At least in theory, the logical block number can be converted to the cylinder number in the disk 、 The track number in the cylinder 、 An old disk address made up of sector numbers in a track . in fact , It's not easy to perform this transformation , There are two reasons for this . First of all , Most disks have some defective sectors , Therefore, the mapping must replace these defective sectors with other free sectors on the disk . second , Yes, some disks , The number of sectors per track is not constant .
- 12.3 Disk attachment
- There are two ways for computers to access disk storage . One way is through I/O port （ Or host attached storage （host-attached storage））, Small systems often use this way . Another way is through the remote host of distributed file system , This is called network attached storage （network-attached storage）.
- 12.3.1 Host attached storage
- Via local I/O Port access storage . A typical desktop uses I/O Bus structure
- SCSI It's a bus structure .
- Network attached storage RPC Remote procedure call .
- Storage area network SAN
- 12.4 Disk scheduling
- One of the tasks of an operating system is to use the hardware efficiently . For disk drives , Meeting this requirement means faster access speed and wider disk bandwidth . The visit time consists of two main parts ： Seek time and rotation delay . The seek time is the time when the magnetic arm moves the head to the cylinder containing the target sector . Rotation delay Is the time that the disk needs to turn the target sector under the head . Disk bandwidth Is the total number of bytes delivered divided by the total time from the beginning of the service request to the end of the last delivery . Disks can be scheduled by using the appropriate access order I/O request , Improve access speed and bandwidth .
- 11.4.1 FCFS Dispatch
- First come, first served
- 12.4.2 SSTF Dispatch shortest-seek-time-first
- Shortest seek time first algorithm Before moving the head far away to process other requests , It may be reasonable to process requests close to the current head position first .SSTF The algorithm selects the shortest seek time request from the current head position . Because the seek time increases with the number of cylinders the head passes through ,SSTF Select the pending request closest to the current head position .
- 12.4.3 SCAN Dispatch
- scan Scanning algorithm about SCAN Algorithm , The magnetic arm moves from one end of the disk to the other , At the same time, as the head moves across each cylinder , Processing service requests located on the cylinder . When we get to the other end , The head changes direction of movement , Processing continues . The head scans the disk back and forth . Sometimes called elevator algorithm .
- 12.4.4 C-SCAN Dispatch
- C-SCAN（circular SCAN,C-SCAN） Scheduling is SCAN Variants of scheduling , It mainly provides a more uniform waiting time . And SCAN equally ,C-SCAN Move the head from one end of the disk to the other end of the disk , As the mobile continues to process requests . however , When the head moves to the other end , It will immediately go back to disk and start , Return without processing the request .C-SCAN The scheduling algorithm basically regards the cylinder as a chain , The last cylinder will be connected with the first cylinder .
- 12.4.5 LOOK Dispatch
- As mentioned above ,SCAN and C-SCAN Move the head across the width of the disk . in fact , Neither of these algorithms is implemented in this way . Usually , The head moves only to the farthest request in one direction . next , It's going back in a second , Instead of continuing to the end of the disk . In this form SCAN and C-SCAN be called LOOK and C-LOOK Dispatch , It's because they're moving in one direction and they're looking at （look） Whether there is a request .
- SSTF be better than FCFS SCAN and C-SCAN For systems with high disk load, it performs better , It's impossible to starve to death .
- 12.5 Disk management
- Disk initialization , Disk boot Bad block recovery .
- 12.5.1 Disk format
- Before the disk can store data , It must be divided into sectors for the disk controller to read and write . This process is called low-level formatting （ Or physical formatting ）
- ECC Error correction code error-correcting code
- 1、 Low level formatting
- 2、 Partition Divide a disk into partitions consisting of one or more cylinders
- 3、 Logical formatting （ Create file system ）. The operating system stores the initial file system data structure on disk . These data structures include free and allocated space （FAT or inode) And an initially empty directory .
- 12.5.2 Guide block
- For most computers , Bootstrap programs are stored in read-only memory （ROM） in . This location is more convenient , because ROM It doesn't need to be initialized and is in a fixed position , This makes it easier for the processor to start executing when it is powered on or rebooted .
- Most systems are just starting ROM Keep a small bootloader in , Its function is to further from the disk into a more complete bootstrap program . This more complete bootstrap program can be easily modified ： The new version can be written to disk . This complete bootstrap program is stored on the boot block of the disk , The boot block is located in a fixed location on the disk . A disk with a boot partition is called a boot disk （boot disk）, Disk or system （system disk）.
- Start up steps ：
- First power up guide And then run the system ROM The code on , To start And then from MBR（master boot record Master boot record ） Read the boot code in the .MBR Contains a list of hard disk partitions and a flag indicating the system boot partition .
- The system determines the boot partition , Read the first sector of the partition （ The so-called boot sector （boot sector）） And continue with the rest of the startup process , This includes loading various subsystems and system services .
- 12.5.3 Bad block
- Its controller maintains a disk bad block list . The list is initialized when it is low-level formatted at the factory , And the disk is constantly updated throughout the use process . Low level formatting puts some blocks aside as a backup , The operating system doesn't see these blocks . The controller can logically replace the bad block with a spare block . This program is called Sector backup （sector sparing） Or forward （forwarding）.
Participation of this paper Tencent cloud media sharing plan , You are welcome to join us , share .
本文为[The struggling rabbit of florist]所创，转载请带上原文链接，感谢