Advanced Format

提供: ArchWiki
2022年11月15日 (火) 17:08時点におけるAshMyzk (トーク | 投稿記録)による版 (→‎パーティションのアライメント: 同期)
ナビゲーションに移動 検索に移動

すべてのストレージデバイスには、使うことのできる最小の記憶単位が存在します。この利用可能な最小単位は一般にセクタと呼ばれており、従来のストレージデバイスの回転部品を最小に分割したものでした (ソリッドステートドライブはメモリセルを使用し、最小単位はページです)。[1] を参照してください。

異なるストレージデバイスは、異なるセクタサイズを使用します。2011 年以降、最近のハードディスクドライブは通常 (512 バイトではなく) 4 KiB セクタを使用します。ソリッドステートドライブは、複数のフォーマットをサポートしていることがあります。

異なる「レイヤー」(つまり、デバイス / スタックされたブロックデバイス / ファイルシステム) 間で同じセクタサイズを使用するべきです。同じセクタサイズを使わない場合、ファームウェアがファイルシステムのセクタと物理ドライブのセクタとの間でマッピングを行わなければなりません。これは通常、変換レイヤーによって透過的に行われますが、これは回避可能なオーバーヘッドであり、そうすることでパフォーマンスが向上します。

4k セクタを使用している HDD のモデル

2011年6月現在、"Advanced Format" または 4k セクタをサポートしている HDD の数は以下のように限られています。

以下のリストに記載されているドライブは全て物理セクタのサイズが4096バイトです。ただし全てのドライブがセクタサイズを正しく OS に報告するわけではありません。(ATA-8 規格の新しいフィールドで) 報告される実際の値を、表の中では報告される物理セクタサイズとして示しています。パーティショニングツールはこの値を使ってアライメントを行うため、間違ってアライメントされる問題が起こらないようにセクタサイズを 4096 にする必要があります。

論理セクタサイズはデータの転送に使われるセクタサイズです。この値はディスクの LBA セクタの数だけ倍加されてディスクの容量になります。そのため、論理セクタが4096バイトのディスクでは、論理セクタが512バイトの同じ容量のドライブと比べて最大 LBA が少なくなります。(2009年以前にリリースされた) 旧式のオペレーティングシステムとの互換性は論理セクタが512バイトのドライブの方が良好ですが、発揮できるパフォーマンスは論理セクタが4096バイトのドライブの方が少しだけ上になります (例: NCQ バッファにより多くの読み書きリクエストを収納できる)。

メーカー モデル 容量 報告されるセクタサイズ (バイト)
論理 物理
3.5"
Samsung HD204UI 2.0 TB 512 512
Seagate ST3500413AS 500.0 GB 512 512
Seagate ST500DM002 500.0 GB 512 4096
Seagate ST1000DL002 1.0 TB 512 4096
Seagate ST1000DM003 1.0 TB 512 4096
Seagate ST1000DM010 1.0 TB 512 4096
Seagate ST2000DL003 2.0 TB 512 512
Seagate ST2000DM001 2.0 TB 512 4096
Seagate ST3000DM001 3.0 TB 512 4096
Seagate ST4000DM000 4.0 TB 512 4096
Seagate ST4000DM005 4.0 TB 512 4096
Seagate ST4000VN000 4.0 TB 512 4096
Western Digital WD3000F9YZ 2.0 TB 512 4096
Western Digital WD30EZRX 3.0 TB 512 4096
Western Digital WD20EZRX 2.0 TB 512 4096
Western Digital WD30EZRSDTL 3.0 TB
Western Digital WD25EZRSDTL 2.5 TB
Western Digital WD20EARX 2.0 TB 512 4096
Western Digital WD20EFRX 2.0 TB 512 4096
Western Digital WD30EFRX 3.0 TB 512 4096
Western Digital WD40EFRX 4.0 TB 512 4096
Western Digital WD60EFRX 6.0 TB 512 4096
Western Digital WD10EARS 1.0 TB
Western Digital WD15EARS 1.5 TB 512 4096
Western Digital WD20EARS 2.0 TB 512 4096 または 512
Western Digital WD10EURS 1.0 TB
Western Digital WD8000AARS 800.0 GB
Western Digital WD6400AARS 640.0 GB
2.5"
Samsung ST1000LM024 1.0 TB 512 4096
Samsung ST2000LM003 2.0 TB 512 4096
Seagate ST320LT007 320 GB 512 4096
Seagate ST9750420AS 750 GB 512 4096
Seagate ST1000LM014 1.0 TB 512 4096
Seagate ST4000LM016 4.0 TB 512 4096
Western Digital WD10JPVT 1.0 TB 512 4096
Western Digital WD10TPVT 1.0 TB
Western Digital WD7500BPVT 750.0 GB
Western Digital WD7500KPVT 750.0 GB
Western Digital WD6400BPVT 640.0 GB
Western Digital WD5000BPVT 500.0 GB
Western Digital WD3200BPVT 320.0 GB
Western Digital WD2500BPVT 250.0 GB 512 4096
Western Digital WD1600BPVT 160.0 GB
Western Digital WD7500BPKX 750.0 GB 512 4096
TOSHIBA MQ01ABD100 1.0 TB 512 4096
TOSHIBA MQ01ABC150 1.5 TB 512 4096
ノート: これを読んだらぜひ表に HDD を追加してください。

HDD が 4k セクタを使用しているかどうか判断する方法

ハードディスク (例: /dev/sdX) の物理・論理セクタサイズは以下の sysfs エントリで確認することができます:

$ cat /sys/class/block/sdX/queue/physical_block_size
$ cat /sys/class/block/sdX/queue/logical_block_size

以下のツールは (ドライブが正しい値を報告しているのを前提として) ドライブの物理セクタを報告します:

  • smartmontools (5.41 から; smartmontools -a, 情報セクション)
  • hdparm (9.12 から; hdparm -I, 設定セクション)

USB 接続のディスクでも上記のツールは使えます (USB ブリッジが SAT、別名 SCSI/ATA Translation または ANSI INCITS 431-2007 に対応している場合)。

ソリッドステートドライブ

Most solid state drives (SSDs) report their sector size as 512 bytes, even though they use larger sectors - typically 4 KiB, 8 KiB, or sometimes larger. As a result, file systems cannot automatically optimize for the native sector size. To avoid sub-optimal performance, one can either:

  • Manually specify the sector size when creating a file system,
  • Change the native sector size reported by the device.

NVMe ドライブのサポートされているセクタサイズを調べる

Use smartmontools to check supported sector sizes:

# smartctl -a device
...
Supported LBA Sizes (NSID 0x1)
Id Fmt  Data  Metadt  Rel_Perf
 0 +     512       0         2
 1 -    4096       0         1
...

ネイティブのセクタサイズを設定する

As an alternative to manually overriding the auto-detected sector size, some SSDs can have their sector size changed during formatting, so that they report a number closer to their true sector size.

NVMe

To see whether a given NVMe device supports this, use the Identify Namespace command.

# nvme id-ns /dev/nvme0n1
nlbaf   : 0
[...]
lbaf  0 : ms:0   lbads:9  rp:0 (in use)

nlbaf is the number of LBA formats minus 1, so here there is only one format supported. The list of formats is at the end of the output. Here lbaf 0 means LBA format #0. It has an lbads (LBA data size) of 9, which means sectors are 29 or 512 bytes. If the device is capable of 4 KiB sectors, there will be another entry here with an lbads of 12. The rp (Relative Performance) value indicates which format will provide the best performance, with 0 being the best. ms is (probably) the number of extra metadata bytes per sector, and this is not well supported under Linux so best to select a format with a value of 0 here.

To change the sector size, use nvme format and specify the preferred value with the --lbaf parameter. If nvme format fails, try putting the machine to sleep (e.g., with systemctl suspend) and then try running nvme format again after waking it. If nvme format still fails, fiddling with your BIOS settings might help.

SATA

For SATA devices, manufacturer specific programs must be used. Not all SATA devices support having the sector size changed.

Intel

For Intel use the Intel Memory and Storage (MAS) Tool (intel-mas-cli-toolAUR) with the -set PhysicalSectorSize=4096 option.

Seagate

For Seagate use seagate-seachestAUR.

Scan all drives to find the correct one, and print info from the one you found:

# SeaChest_Basics --scan
# SeaChest_Basics -d /dev/sgX -i

Should print out information about the drive. Make sure to check the serial number.

Check the logical block sizes supported by the drive:

# SeaChest_Format -d /dev/sgX --showSupportedFormats

If 4096 is listed, you can change the logical sector size to it as follows:

# SeaChest_Format -d /dev/sgX --setSectorSize=4096 --confirm this-will-erase-data

This will take a couple of minutes, after which your drive now uses a 4K native sector size.

パーティションのアライメント

パーティションを正しくアライメントすることで、読み込み・変更・書き込みの過剰なサイクルを回避できます。家庭用のコンピュータでは、各パーティションの開始位置とサイズを 1 MiB (1 048 576 バイト) 境界にアライメントするのが一般的です。これは、一般的に使用されているすべてのサイズ (1 MiB、512 KiB、128 KiB、4 KiB、512 B) で割り切ることができるので、一般的なページサイズとブロックサイズのシナリオすべてをカバーします。

警告: パーティションのアライメントを誤ると、dm-crypt/LUKS で 4096 バイトセクタを使用できなくなります。[2] を見てください。
  • fdisk、cfdisk、sfdisk はアライメントを自動的に管理します。
  • gdisk と cgdisk はアライメントを自動的に管理します。
    • sgdisk はデフォルトで、パーティションの開始位置のみをアライメントします。パーティションのサイズや終了位置のアライメントも有効化するには、-I/--align-end オプションを使ってください。
  • Parted はパーティションの開始位置のみをアライメントし、サイズと終了位置はアライメントしません。パーティションを作成するときは、パーティションの終了位置をメビバイトかより大きな IEC 2進接頭辞で指定するようにしてください。