Kipper
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # OS筆記-Chapter 12: Mass-Storage Systems ###### tags: `OS` --- #### 目錄 * 總論 [Chapter 1: Introduction](https://hackmd.io/NoZq3J7IQvOQpcbo_tctjA) [Chapter 2: Operating-System Structures](https://hackmd.io/OKykRLBESI6v9a13HgS35A) * 行程管理 [Chapter 3: Processes](https://hackmd.io/HOqN-iQ3RIKIC-NB9QjBIQ) [Chapter 4: Threads](https://hackmd.io/qzAIHeSASmKuecdkqidmHw) [Chapter 5: CPU Scheduling](https://hackmd.io/IT5g2wHzTdOtMSDXPVEpOw) [Chapter 6: Process Synchronization](https://hackmd.io/rv-PNe3ESxi08PElyUTc4Q) [Chapter 7: Deadlocks](https://hackmd.io/Uu0jDK-rSyKNKq690y146g) * 記憶體管理 [Chapter 8: Main Memory](https://hackmd.io/4KS_yPkBQzGZfHDisPciog) [Chapter 9: Virtual Memory](https://hackmd.io/yirxZFn8Rz2wT56AAR7Sxw) * 儲存裝置 [Chapter 10: File-System Interface](https://hackmd.io/aNPWKsFhTlGc-WFgQ__KRg) [Chapter 11: File System Implementation](https://hackmd.io/bFcrlmefQsGp6hZdbI1MHQ) <font color="red">Chapter 12: Mass-Storage Systems</font> [Chapter 13: I/O Systems](https://hackmd.io/VNwXrhJPSo-l_t9tUBhYIg) * 保護和安全 [Chapter 14: Protection](https://hackmd.io/izkd4JwXRwub_ZmhSMTlNw) [Chapter 15: Security](https://hackmd.io/ofyvDidvQf-PxLMMZYhtsg) --- ### 大量儲存體結構的概觀 * 磁碟(magnetic disk) * 以磁性錄製方式來儲存訊息 * 讀寫磁頭連接在磁臂(disk arm)上 * 磁盤(platter)的表面邏輯的分割成磁軌(track) * 磁軌分割成磁區(sector) * 磁臂位置的磁軌組成磁柱(cylinder) ![](https://i.imgur.com/sYA6DVl.png) * 以每分鐘多少轉為單位(RPM,rotation per minute) * 磁碟速度 * 傳遞速率(transfer rate):資料在磁碟機與電腦間流動速率 * 定位時間(positioning time)/隨機存取時間(random-access time)包含 * 搜尋時間(seek time):移動磁臂到所要的磁軌的時間 * 旋轉潛伏期(rotational latency):磁頭旋轉到磁區的時間 * 磁頭損壞不能修復 * 磁碟是可移式的(removable),可視需求更換 * 磁碟機以一組稱為I/O匯流排(I/O bus)的現連接到電腦 * ATA、SATA、eSATA、FC、USB等等 * 資料經由稱為控制器(controller)的特殊電子處理器在匯流排上傳遞 * 磁碟控制器(disk controller):構成磁碟機 * 主機控制器(host controller):在匯流排的電腦尾端的控制器 * 固態硬碟(SSD,solid-state disk) * 比傳統硬碟快 * 生命週期短、單位容量貴 * 沒有磁頭 * 是一種非揮發性的記憶體 * 磁帶(magnetic tape) * 隨機存取速度非常慢 * 通常用來存放備份 * 利用磁頭與一個捲軸 ### 磁碟結構(Disk Structure) * 以一個大型邏輯區段(logical block)的一維陣列來定址 * 以低階格式化(low-level formatted)的方式來選擇不同邏輯區段大小 * 一維陣列依序對映到磁碟的磁區 * 對映的困難 * 大部分的磁碟會有一些損壞的磁區,但是對映會用磁碟上別處的替代備用磁區 * 有些磁碟上每一個磁軌的磁區數並不是常數 * 為了使得磁頭移過的資料速率保持固定 * 磁頭由磁碟內側到外側時,轉速會加快 * 固定角速度(CAV,constant angular velocity) ### 磁碟連結(Disk Attachment) * 以兩種方式存取磁碟儲存裝置 * I/O阜/主機連結儲存裝置(host-attached storage) * 網路連結儲存裝置(network-attached storage) * 主機連結儲存裝置 * 可使用IDE、ATA、SATA、SCSI、fibre channel等I/O匯流排架構 * 光纖通道(FC,fibre channel)有兩種變形的架構 * 儲存體區域網路(SAN,storage-area network) ![](https://i.imgur.com/GgdVv6M.png) * 仲裁迴路(FC-AL,arbitrated loop) * 網路連結儲存體(NAS,network-attached storage) * 客戶經由遠端程序呼叫的介面存取網路連結儲存體 * iSCSI使用網路IP協定來實現SCSI協定 ![](https://i.imgur.com/M8KXuvY.png) ### 磁碟排班(Disk Scheduling) * 存取時間 * 搜尋時間(seek time):移動磁臂到所要的磁軌的時間 * 旋轉潛伏期(rotational latency):磁頭旋轉到磁區的時間 * 磁碟頻寬(bandwidth):傳送位元組總數除以第一個服務要求到最後傳送完成之間所需的總時間 * 先來先做排班(FCFS,first come first served) * 不能提供最快的服務,因為還有辦法減少磁頭移動次數 ![](https://i.imgur.com/duvbDWa.png) * 最短尋找時間先做演算法(SSTF,shortest-seek-time-first) * 找出佇列之中與現在磁頭位置之軌距差最小者 * 可能會產生飢餓 ![](https://i.imgur.com/Tc6RbWb.png) * 並非最佳化,若先移至37->14->65->...->183,能簡短總距離 * 掃描排班(SCAN algorithm) * 又稱升降梯演算法(elevator algorithm) * 往磁碟的一端開始服務,到達一端時,在往反方向的另一端開始服務 ![](https://i.imgur.com/ol9tw8O.png) * 循環掃描排班(C-SCAN,circular SCAN) * 假設個要求視常態分佈,所以當到達一端時,往反方向時不會服務(因為最近被服務) ![](https://i.imgur.com/y7ywiic.png) * LOOK排班 * 與SCAN排班雷同,但不須移至一端只需一至最後一個要求 * C-LOOK排班 ![](https://i.imgur.com/Ge1v60q.png) * 磁碟排班演算法的選擇 * 取決於要求的多寡與型態 * 只有一個要求的話,每種排班演算法都看起來像FCFS * 受檔案配置方式的影響 * 檔案在磁碟上的位置是連續或鏈結等等 ### 磁碟管理(Disk Management) * 磁碟格式化 * 低階格式化(low-level formatting)/實體格式化(physical formatting) * 對磁碟的每一個磁區填入一種特定的資料結構 * 通常由標頭、資料區(通常512Byte,但可選擇)、結尾所組成 * 包含錯誤更正碼(ECC,error-correcting code) * 作業系統需要紀錄它自己在磁碟上的資料結構,使用兩步驟來完成 * 分割(partition)成一個或多個磁柱群,作業系統視每一個分割為一個分離的磁碟 * 邏輯格式化(logical formatting):製作一個檔案系統 * 啟動區段(boot block) * 作業系統核心由唯讀記憶體(ROM,read-only memory)上的靴帶式程式載入 * 但要改靴帶式程式碼時,需要更改ROM的晶片,所以ROM上靴帶式程式改為從硬碟上載入完整的靴帶式程式 * 完整的靴帶式程式存放在磁碟上的位置稱為啟動區段,該磁碟稱為啟動磁碟(boot disk)/系統磁碟(system disk) * Windows上ROM上的程式指示讀取主要啟動磁區(MBR,master boot record),MBR指示系統由哪一個分割啟動 ![](https://i.imgur.com/nGfvZVD.png) * 毀損區段(bad block) * 作業系統無法配置 * 磁碟格式化時,發現毀損區段,並標計無法使用 * 毀損區段的資料會移失 * 磁區備份(sector sparing)/磁區轉換(sector forwarding):低階格式化設計了一些作業系統無法看到的額外備份磁碟區 * 磁區順延(sector slipping):以順延的方式完成毀損磁區的置換 * 若17磁區毀損,備份磁區從202開始,將201移置202,200移置201,直到能將17移置18 ### 置換空間管理(Swap-Space Management) * 使用硬碟的置換空間作為記憶體的延伸 * 置換空間的大小取決於備份時所需要的量 * 太大,浪費硬碟空間 * 太小,行程不夠備份 * 置換空間的位置 * 放在檔案系統中,視為一個大型檔案 * 沒有效率,因為檔案系統的搜尋需要時間 * 檔案系統還要多於的磁碟存取 * 放在原始磁碟分割(raw disk) * Linux系統中置換的資料結構 * 每個置換區域由一系列4KB分頁槽(page slot)組成 * 置換對映圖(swap map):連結每一個置換區域的整數計數器陣列 * 計數器數值表示置換分頁對映到的行程 ![](https://i.imgur.com/ceOIZbN.png) ### 不昂貴磁碟的重複陣列(RAID,redundant array of inexpensive disk) * RAID * 不昂貴(I,inexpensive):以前RAID由小型便宜的磁碟機組成,被視為大型昂貴磁碟機的替代品 * 獨立(I,independent):現在RAID被使用是因為他們的高可靠度和較高的資料傳送速率 * 藉由重複(redundancy)改進可靠度 * 假設一台磁碟機的平均失效時間(mean time to failure)為100000小時,100台磁碟機陣列中某一台磁碟機的平均失效時間100000/100=1000小時 * 鏡射(mirrored volume) * 複製磁碟 * 每次寫入都會在兩台磁碟機一起執行 * 兩台同時壞掉資料才會移失 * 假設一台的修復時間為10小時,平均資料移失時間為(100000)²/(2* 10) * 加入非揮發性RAM(NVRAM,nonvolatile RAM)快取到RAID陣列 * 在電源失效時,保護資料移失 * 藉由並行改善效能 * 資料分割(data striping)的最簡單格式是將每一個位元組分成為源分散在許多台磁碟機,這種分割稱為位元層次的分割(bit-level striping) * 將檔案第i個位元寫到第i個磁碟機中 * 有i台磁碟機,則視為i被大小且i被存取速率的磁碟機 * 也可在區段層次分割(block-level striping) * 將第n個區段放在第n台磁碟機 * RAID層次(RAID level) * RAID 0 * 區段層次分割 * 每次I/O一台磁碟機處理 * 沒有重複 ![](https://i.imgur.com/0S3luM1.png) * RAID 1 * 鏡射 ![](https://i.imgur.com/ZGLlmDT.png) * RAID 2 * 記憶體型態的錯誤更正碼 * 同位位元紀錄每個位元組中1的個數是奇或偶數 ![](https://i.imgur.com/qFTiSZl.png) * RAID 3 * 位元交錯的同位位元 * 每次I/O多台處理,單一區段以RAID 0的N倍速率傳輸 * 但同時只能處理一個I/O ![](https://i.imgur.com/iBGhkSk.png) * RAID 4 * 區段交錯的同位位元 * 可同時只能處理多個I/O * 資料與同位位元能同時寫入 ![](https://i.imgur.com/ka0LBXI.png) * RAID 5 * 區段交錯的分散式同位位元 * 把資料和同位位元分散到磁碟機 ![](https://i.imgur.com/xveasw2.png) * RAID 6 * P+Q重複 * 與RAID 5雷同 * 每4個位元資料,就有兩位元額外資料 * 能忍受兩台磁碟機同時壞掉 ![](https://i.imgur.com/aFYXKj3.png) * RAID 0+1 * 提供比RAID 5更好的性能 * 一台磁碟機壞掉,整體分割存取就無法進行,只剩下其他分割可以使用 ![](https://i.imgur.com/wtEmHGP.png) * RAID 1+0 * 提供比RAID 5更好的性能 * 一台磁碟機壞掉,其他鏡社組依然和其他的磁碟機可以使用 ![](https://i.imgur.com/AZM5EZL.png) * RAID製作 * 以軟體製作,部分的RAID非常慢 * 以主機匯流排轉接卡(HBA,host bus-adapter)硬體上製作,沒有彈性 * 在儲存陣列的硬體製作,可以產生不同層的RAID * 儲存陣列可以有多重連接或SAN的部分 * 由磁碟虛擬裝置在SAN連階層上製作 * 熱備份(hot spare)的磁碟機用來在其他磁碟機壞掉時,能做為其替代品 * 選擇一個RAID層次 * RAID 0用於高性能 * RAID 1重建最快 * RAID 0+1與RAID 1+0兼顧性能與可靠度 * RAID 5適合儲存大量資料 * RAID的問題 * RAID不保證資料是可以使用的,只保護實體媒體的錯誤 * Solaris ZFS檔案系統使用檢查碼(checksum)來解決這些問題 * 檢查碼不與被檢查的區段放在一起,而是與指標一起儲存在區段中 ![](https://i.imgur.com/WJ4caF6.png) * 資料有問題,則檢查碼將是不正確的 * 將RAID集結成一個儲存池(pool),一個池可以保有一個或多個ZFS檔案系統 ![](https://i.imgur.com/nQnD76y.png) ### 穩定儲存體製作(Stable-Storage Implementation) * 穩定儲存體的資料決不會移失 * 將資料複製到擁有獨立失效模式的儲存裝置 * 確保更新時失效,不至於留下所有複製都在毀損狀態 * 磁碟寫入遭成三種結果 * 成功完全:資料正確的寫入磁碟中 * 部分失敗:失敗發生在傳送的中間,因此只有一些磁區已經寫入新的資料,而且在寫入過程中發生失敗的磁區可能已經損毀了 * 全部失敗:失敗發生在開始寫入前,磁碟上之前的資料仍然保持原狀 * 為了在發生錯誤時,能復原這個區段,系統必須 * 為每一個邏輯區段保有兩段實體區段 * 資料寫入第一段成功後,把相同資料寫入第二段 * 兩次都寫入完成,才能宣布操作完成

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully