Linux command – hdparm

Loading

t , T – benchmark & comparison

透過指令 #hdparm 這是一個比較簡單的方式來看目前硬碟傳送的速度.
常用來測試的參數.
-T : 會使用到 cache 來測試硬碟速度.
-t : 不使用 cache 來測試硬碟速度,所得到的值較為標準.
–direct : 使用 Kernel 參數 O_DIRECT 來進行測試. Direct I/O 不使用系統提供的讀取和寫入 cache ,讓讀取和寫入都直接到存儲裝置.
先不用 cache 來試試看速度.

[root@localhost ~]# hdparm -t /dev/sda
/dev/sda:
Timing buffered disk reads: 306 MB in 3.01 seconds = 101.50 MB/sec
[root@localhost ~]# hdparm -t --direct /dev/sda
/dev/sda:
Timing O_DIRECT disk reads: 306 MB in 3.01 seconds = 101.50 MB/sec

使用上 Cache 速度上會提升很多,所以不建議來當測試值.

[root@localhost ~]# hdparm -T /dev/sda
/dev/sda:
Timing cached reads: 15000 MB in 1.99 seconds = 7519.43 MB/sec

W – Get/set drive´s write-caching

write-caching 有區分為 write back 和 write through

  • write-through cache
    write-through cache, every write to the cache causes a synchronous write to the backing store.
    使用 write-through 的 cache,,資料寫入cache時也會同步寫入儲存裝置
  • write-back
    Alternatively, in a write-back (or write-behind) cache, writes are not immediately mirrored to the store. Instead, the cache tracks which of its locations have been written over and marks these locations as dirty. The data in these locations are written back to the backing store when those data are evicted from the cache, an effect referred to as a lazy write.
    而 write-back 是將資料量儲存到一定的量之後,會依據同區塊的資料一次整批寫回去.裡面有提到 dirty ,他是在記憶體裡面 cache 的一個 bit 用來指示這筆資料已經被 CPU 修改過但是尚未回寫到儲存裝置中.

通常使用 write-back 會比 write-through 來得有效率,但 write-back 需要承擔斷電時cache裡的資料遺失的風險.

IDE 和 SATA 的硬碟也有所謂的 write back 和 write through 不過在 Linux 我們只能將 disk cache 的功能開啟或是關閉 無法更改他的模式,必須在 BIOS 下做修改.
在 #dmesg 可以看到目前的 cache 模式為何.

[root@benjr ~]# dmesg |grep -i write
sda: Write Protect is off
SCSI device sda: drive cache: write through
sda: Write Protect is off
SCSI device sda: drive cache: write through

透過 #hdparm -W0/1 可以將 cache 功能關閉

[root@benjr ~]# hdparm -W0 /dev/sda
/dev/sda:
setting drive write-caching to 0 (off)
[root@benjr ~]# hdparm -W1 /dev/sda
/dev/sda:
setting drive write-caching to 1 (on)

security – 硬碟資料抹除

還沒有實際試過 (先記錄方式).
透過 security erase 可以讓硬碟回覆到原本的效能水準,首先要檢查硬碟是否有支援 security set 指令.

[root@benjr ~]# hdparm -I /dev/sdb 

要先設定 security password 才能執行 security erase.

[root@benjr ~]# hdparm --security-set-pass 1234 /dev/sdb
[root@benjr ~]# hdparm --security-erase 1234 /dev/sdb

如果是要單純做硬碟資料抹除,還有另外一支程式 #shred 可以使用.

沒有解決問題,試試搜尋本站其他內容

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料