跳转至

8. Physical Storage Systems

约 2384 个字 预计阅读时间 12 分钟

Abstract

  • Classification of Physical Storage Media
  • Storage Hierarchy
  • Magnetic Disks
    • Disk Interface Standards
    • Performance Measures of Disks
    • Optimization of Disk-Block Access
  • Flash Storage & SSD
  • Storage Class Memory(NVM)

8.1 Storage Hierarchy

  • volatile storage(易失存储)

    loses contents when power is switched off. (断电时丢失内容)

    如:内存、CPU中的高速缓存

  • non-volatile storage(非易失存储)

    Contents persist even when power is switched off(即使电源关闭,内容仍然存在).

    如:磁盘、硬盘、闪存、固态硬盘、光盘

主要从 speed, cost, reliability 衡量

image-20240422133241247

cache -> main memory -> flash memory(闪存) -> magnetic disk(磁盘) -> optical disk(光盘) -> magnetic tapes(磁带)

从高层往低层走,存储设备变得更慢,更便宜和更大。

  • primary storage: Fastest media but volatile (cache, main memory).

    主存储:速度最快但易失性的介质(缓存、主内存)

  • secondary storage: next level in hierarchy, non-volatile, moderately fast access time

    二级存储:层次结构的下一级,非易失性,访问时间适中 (闪存,磁盘)

    also called on-line storage 连在计算机系统中,随时可以访问到的

  • tertiary storage: lowest level in hierarchy, non-volatile, slow access time

    三级存储:层次结构最低,非易失性,访问时间慢(磁带、光盘)

    also called off-line storage 三级存储主要是用于备份,要访问数据较为不便

  • NVM (non-volatile memory) 访问和内存(memory)一样,以字节寻址,而且掉电能保持数据。

8.2 Magnetic Disks

一个磁盘有上十万个 track(磁道),

一个磁道又有上千个 sector(扇区,是计算机和磁盘交换数据的最小单位).

柱面:同一个磁道上,多个磁盘共同组成一个柱面

arm assembly 用来寻道,读写头共进退,寻找数据在哪个磁道上。等对应扇区旋转到读写头,才开始传输数据。

同样磁道组成的柱面。对于大文件,最好存在同一个柱面上,这样可以并行读写。

例题:假如一共有五片磁盘,有5G的数据需要存储,如何存储最优?

显然对于大数据,应当将数据存在同一个柱面上,arm assembly在定位时,会定位到相同的位置,此时一次定位就能找到所有需要的数据

  • Read-write head

  • Surface of platter divided into circular tracks(磁道)

    盘片表面分为圆形轨道(磁道)

  • Each track is divided into sectors(扇区)

    每个轨道都分为扇区(扇区)

  • To read/write a sector

    • disk arm swings to position head on right track

      圆盘臂摆动以将头部定位在正确的轨道上

    • platter spins continually; data is read/written as sector passes under head

      盘片不断旋转;当扇区在 head 下传递时,数据被读取/写入

  • Cylinder(柱面) i consists of ith track of all the platters

  • Disk controller(磁盘控制器)– interfaces between the computer system and the disk drive hardware.

    Disk controller(磁盘控制器)– 计算机系统和磁盘驱动器硬件之间的接口

    写入的时候需要校验,故写入的速度较慢

8.2.1 Performance Measures of Disks

  • Access time(访问时间) – the time it takes from when a read or write request is issued to when data transfer begins. (从发出读取或写入请求到数据传输开始所需的时间) Consists of:

    • Seek time(寻道时间)– time it takes to reposition the arm over the correct track. (将arm重新定位在正确轨道上所需的时间
      • Average seek time is 1/2 the worst case seek time.
    • Rotational latency(旋转延迟) – time it takes for the sector to be accessed to appear under the head. (访问扇区旋转到读写头下方所需的时间
      • Average latency is 1/2 of the worst case latency.
  • Data-transfer rate(数据传输率) – the rate at which data can be retrieved from or stored to the disk.

    定位到正确的磁道与扇区后,才开始进行数据传输,对应有数据传输率。

内存传输是以块为单位的。即使是想要访问一个 byte, 也需要把这个 byte 所在的 4k 内存读进来。

  • Disk block is a logical unit for storage allocation and retrieval (4K或者16K)

    • Smaller blocks: more transfers from disk
    • Larger blocks: more space wasted due to partially filled blocks

    磁盘以数据块为单位进行存储和传输

  • Sequential access pattern(顺序访问模式)

Successive requests are for successive disk blocks(连续的磁盘块)

Disk seek required only for first block 仅第一个块需要磁盘查找

连续的读写请求只需要第一次访问磁盘

  • Random access pattern(随机访问模式)

    速度慢,希望尽量多一些顺序访问。

    改进方法:可以用一个日志把要修改的数据记录下来,后面再进行修改,尽量用顺序访问替换随机访问。

    连续请求适用于磁盘上任何位置的块

    Each access requires a seek 每次访问都需要一个seek Transfer rates are low since a lot of time is wasted in seeks 传输率很低,因为大量时间浪费在寻找上

  • I/O operations per second (IOPS ,每秒I/O操作数)

    Number of random block reads that a disk can support per second.

    可以支持随机读写的次数,判断读写性能主要的指标

  • Mean time to failure (MTTF,平均故障时间)

    the average time the disk is expected to run continuously without any failure.

    磁盘预计连续运行且不发生故障的平均时间。

8.2.2 Optimization of Disk-Block Access

  • Buffering: in-memory buffer to cache disk blocks (内存中缓冲区,用于缓存磁盘块

    假设我们只读磁盘中的一个Byte,也要把磁盘中的一个块(很多连续的扇区)读到内存中去。将一个块读入到内存中(耗时较长),如果直接将这个块丢弃,是很可惜的。

    因此,可以将这个数据块缓存在内存中。希望后面的数据访问也在这个块中读取,从而加快读取数据的速度。相关的数据可以放在一起,下次就在缓冲区里找

  • Read-ahead(Prefetch): Read extra blocks from a track in anticipation that they will be requested soon

    预取,读取某数据块时预测邻近几个数据块也会被访问,于是就一起取到内存中。要有依据地预取,不然无用的数据会占用缓存。

  • Disk-arm-scheduling algorithms re-order block requests so that disk arm movement is minimized

    磁盘臂调度算法对块请求进行重新排序,以便将磁盘臂移动降至最低

    elevator algorithm (电梯算法)

    image-20240422140552165

    按照电梯算法,来移动读写头,使之位于不同的磁道上。重新将读写头收到的请求进行排序,以最小化读写头的移动

  • File organization

    • Allocate blocks of a file in as contiguous a manner as possible

      预先分配得到的内存是连续的

    • Files may get fragmented(碎片化)

      • Sequential access to a fragmented file results in increased disk arm movement

        连读访问碎片化的文件结构,会导致磁盘臂移动增加

      • Some systems have utilities to defragment the file system, in order to speed up file access

        对文件系统进行碎片整理(将分散在磁盘中的文件碎片重新写在一个连续的块中的实用程序,以加快文件访问速度

  • Nonvolatile write buffers(非易失性写缓存)

    一般情况下,要向磁盘中写入数据,需要等待向磁盘中写入完成再进行下一步操作。

    speed up disk writes by writing blocks to a non-volatile RAM buffer immediately

    现在我们把要写的数据先写到一个快速的非易失的缓存里,如 NVM, Non-volatile RAM:battery backed up RAM就可以立即执行下一步操作,NVM 再择机将数据写回到磁盘。.

  • Log disk(日志磁盘)

    a disk devoted to writing a sequential log of block updates

    把对磁盘块的修改,以日志的形式,记在一个专门的日志磁盘中,这个磁盘只支持顺序访问

    写入的时候存在优化,如使用电梯算法(磁盘臂的调用)

8.3 Flash Storage

闪存(固态硬盘)

  • NAND flash

    • requires page-at-a-time read (page: 512 bytes to 4 KB)

      顺序读写和随机读写差不多,每次按照页进行读操作

    • Page can only be written once

      在对数据进行重新写入之前,需要先擦除数据

  • SSD(Solid State Disks)

    Use standard block-oriented disk interfaces, but store data on multiple flash storage devices internally

    使用标准的面向块的磁盘接口,但将数据存储在内部的多个闪存设备上

    millisecond 毫秒 microsecond 微秒

功耗方面:磁盘的功耗高于固态硬盘(机械运动更耗能)

磁盘的修改是in place(当前位置直接修改)

固态硬盘的修改是先擦除,再重新写(erase -> rewrite)可能有这样的情况:我们反复读写、擦去某几个块,这会导致它们坏的很快。

所以SSD要研究磨损均衡

我们访问上层的时候存在一个逻辑页号,映射到物理页号的映射方式是可以变化的。假如我们访问一个逻辑页号是经常访问的数据,那么我们可以通过改变物理页号映射方式达到磨损均衡

  • Remapping of logical page addresses to physical page addresses avoids waiting for erase 逻辑页到物理页的映射

  • Flash translation table tracks mapping

    • also stored in a label field of flash page

    • remapping carried out by flash translation layer

  • wear leveling(磨损均衡)

    evenly distributed erase operators across physical blocks

    均匀分布在物理块上的擦除

SSD:固态硬盘 HHD:混合硬盘 HDD:传统硬盘

NVM 的Read/Write Latency 读写延迟比内存(DRAM)长,均能够字节寻址。SSD和HDD均采用block寻址

Persistence 即掉电是否能保持原数据。Endurance耐久度,表示可以使用的时间

SSD不耐久,擦除次数有限,NVM也不耐久

NVM的作用:

  1. 缓冲:Nonvolatile write buffers(非易失性写缓存)把要写的数据先写到一个快速的非易失的缓存里
  2. 用作 Log Disk