高性能Linux: SSD分區對齊問題

分區對齊

分區對齊意味着分區與數據存儲設備(例如硬盤,固態驅動器(SSD)或RAID卷)的合理的邊界對齊。正確的分區對齊可確保數據訪問期間的理想性能。不正確的分區對齊將導致性能降低,尤其是SSD(內部頁面大小爲4,096或8,192字節),具有4,096字節扇區和RAID卷的硬盤。

分區歷史

過去,第一個分區始終在LBA(Logical Block Address)地址63處開始,該地址對應於第64個扇區(另請參見CHS和LBA硬盤尋址)。這種(邏輯)扇區的大小爲512字節。這對於普通硬盤(物理扇區大小爲512字節)是可接受的。就外部訪問而言,物理扇區大小爲4,096字節的較新硬盤實際上模擬了512字節的扇區大小,但在內部它們使用4,096字節。即使SSD也可以使用4096或8192字節的頁面大小。從LBA地址63開始的分區就是這些新硬盤和SSD的問題。

如果使用典型塊大小爲4096字節的文件系統格式化分區,則文件系統的4096字節塊將不會直接適用於硬盤的4096字節扇區或8192字節扇區的SSD頁面。當寫入4096字節的文件系統塊時,必須修改兩個4096字節的扇區或頁面。
不正確的分區對齊

正確的分區對齊

爲了避免這些問題,建議在1M字節邊界處進行對齊。當前的尋址系統被劃分爲512字節的邏輯扇區,這樣做將對應於2,048個扇區。
正確的分區對齊

Linux上如何做分區對齊

通過停用DOS兼容模式和設置扇區單元可以實現正確的對齊(分區將從LBA地址2,048開始。對於頁面大小爲4096字節的SSD,在開始時將有256個空頁。磁盤分區將在第257頁處開始)。
下面是使用fdisk進行分區,其中使用-c參數來停用dos兼容模式,-u參數用來使用扇區作爲數據單元。

root@ubuntu-10-04:~# fdisk -c -u /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xfae13403.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): p

Disk /dev/sdb: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 cylinders, total 312581808 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xfae13403

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First sector (2048-312581807, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-312581807, default 312581807): +10G

Command (m for help): p

Disk /dev/sdb: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 cylinders, total 312581808 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xfae13403

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    20973567    10485760   83  Linux

Command (m for help): 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章