「Advanced Format」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
37行目: 37行目:
 
== ソリッドステートドライブ ==
 
== ソリッドステートドライブ ==
   
  +
ほとんどの[[ソリッドステートドライブ]] (SSD) は、セクタサイズを 512 バイトと報告します。しかし、SSD はより大きなセクタ (典型的には 4 KiB、8 KiB、さらに大きいこともあります) を使用します。その結果として、ファイルシステムはネイティブなセクタサイズに自動的に最適化できません。パフォーマンスを最適化するには:
Most [[solid state drive]]s (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:
 
   
  +
* ファイルシステムを作成するときにセクタサイズを[[#ファイルシステム|手動で指定する]]
* [[#File systems|Manually specify]] the sector size when creating a file system,
 
  +
* デバイスによって報告されるネイティブなセクタサイズを[[#ネイティブなセクタサイズを設定する|変更する]]
* [[#Setting native sector size|Change]] the native sector size reported by the device.
 
   
 
=== NVMe ドライブのサポートされているセクタサイズを調べる ===
 
=== NVMe ドライブのサポートされているセクタサイズを調べる ===
   
  +
[[smartmontools]] を使って、サポートされているセクタサイズを確認してください:
Use [[smartmontools]] to check supported sector sizes:
 
   
 
{{hc|# smartctl -a ''device''|
 
{{hc|# smartctl -a ''device''|
57行目: 57行目:
 
=== ネイティブなセクタサイズを設定する ===
 
=== ネイティブなセクタサイズを設定する ===
   
  +
自動検出されたセクタサイズを手動でオーバーライドする代わりに、一部の SSD ではフォーマット時にセクタサイズを変更でき、真のセクタサイズに近い値を報告させることができます。
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 ====
 
==== NVMe ====
   
  +
[[NVMe]] デバイスがこれをサポートしているかどうか調べるには、''Identify Namespace'' コマンドを使ってください。
To see whether a given [[NVMe]] device supports this, use the ''Identify Namespace'' command.
 
   
 
{{hc|# nvme id-ns /dev/nvme0n1|
 
{{hc|# nvme id-ns /dev/nvme0n1|
69行目: 69行目:
 
}}
 
}}
   
  +
{{ic|nlbaf}} は、LBA フォーマットの数から 1 引いたものです。なので、この場合、フォーマットは1つだけがサポートされていること示しています。フォーマットのリストは出力の最後にあります。ここの {{ic|lbaf 0}} は、LBA フォーマット #0 を意味しています。9 という数値の {{ic|lbads}} (LBA データサイズ) は、セクタが 2<sup>9</sup> つまり 512 バイトであることを示しています。デバイスが 4 KiB セクタを利用できる場合、{{ic|lbads}} の値が 12 の別のエントリも表示されます。{{ic|rp}} (Relative Performance) 値は、どのフォーマットが最高のパフォーマンスを発揮できるかを示しています (ここでは、0 がベストであると示しています)。{{ic|ms}} は、(おそらく) セクタあたりの追加メタデータのバイト数であり、これは Linux であまり良くサポートされていないため、ここでは 0 の値を持つフォーマットを選択するのが最良です。
{{ic|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 {{ic|lbaf 0}} means LBA format #0. It has an {{ic|lbads}} (LBA data size) of 9, which means sectors are 2<sup>9</sup> or 512 bytes. If the device is capable of 4 KiB sectors, there will be another entry here with an {{ic|lbads}} of 12. The {{ic|rp}} (Relative Performance) value indicates which format will provide the best performance, with 0 being the best. {{ic|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 {{ic|nvme format}} and specify the preferred value with the {{ic|--lbaf}} parameter. If {{ic|nvme format}} fails, try putting the machine to sleep (e.g., with {{ic|systemctl suspend}}) and then try running {{ic|nvme format}} again after waking it. If {{ic|nvme format}} still fails, fiddling with your BIOS settings might help.
+
セクタサイズを変更するには、{{ic|nvme format}} を使い、{{ic|--lbaf}} パラメータで好ましい値を指定してください。{{ic|nvme format}} が失敗する場合、マシンを (例えば {{ic|systemctl suspend}} などで) スリープ状態にして、復帰させたあとにもう一度 {{ic|nvme format}} を実行してみてください。{{ic|nvme format}} が依然として失敗する場合、BIOS の設定をいじると解決するかもしれません。
   
 
==== SATA ====
 
==== SATA ====
   
  +
SATA デバイスの場合、メーカー固有のプログラムを使用する必要があります。すべての SATA デバイスがセクタサイズを変更できるわけではありません。
For SATA devices, manufacturer specific programs must be used. Not all SATA devices support having the sector size changed.
 
   
 
===== Intel =====
 
===== Intel =====
   
For Intel use the [https://downloadcenter.intel.com/download/29337/Intel-Memory-and-Storage-Tool-CLI-Command-Line-Interface-?product=83425 Intel Memory and Storage (MAS) Tool] ({{AUR|intel-mas-cli-tool}}) with the {{ic|1=-set PhysicalSectorSize=4096}} option.
+
Intel の場合、{{ic|1=-set PhysicalSectorSize=4096}} オプションと共に [https://downloadcenter.intel.com/download/29337/Intel-Memory-and-Storage-Tool-CLI-Command-Line-Interface-?product=83425 Intel Memory and Storage (MAS) Tool] ({{AUR|intel-mas-cli-tool}}) を使ってください。
   
 
===== Seagate =====
 
===== Seagate =====
   
For Seagate use {{AUR|seagate-seachest}}.
+
Seagate の場合、{{AUR|seagate-seachest}} を使ってください。
   
  +
すべてのドライブをスキャンし、適切なものを探してください。そして、見つけたドライブの情報を表示してください:
Scan all drives to find the correct one, and print info from the one you found:
 
   
 
# SeaChest_Basics --scan
 
# SeaChest_Basics --scan
 
# SeaChest_Basics -d /dev/sg''X'' -i
 
# SeaChest_Basics -d /dev/sg''X'' -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/sg''X'' --showSupportedFormats
 
# SeaChest_Format -d /dev/sg''X'' --showSupportedFormats
   
  +
4096 が一覧に載っている場合、論理セクタサイズを 4096 バイトに変更できます:
If 4096 is listed, you can change the logical sector size to it as follows:
 
   
 
# SeaChest_Format -d /dev/sg''X'' --setSectorSize=4096 --confirm this-will-erase-data
 
# SeaChest_Format -d /dev/sg''X'' --setSectorSize=4096 --confirm this-will-erase-data
   
  +
このコマンドは完了するまで2分かかります。その後、ドライブは 4K ネイティブセクタサイズを使用するようになります。
This will take a couple of minutes, after which your drive now uses a 4K native sector size.
 
   
 
== パーティションのアライメント ==
 
== パーティションのアライメント ==

2022年11月16日 (水) 21:57時点における版

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

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

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

ハードディスクドライブ – Advanced Format

Advanced Format とは、ハードディスクドライブ内の磁気ディスク上でデータを格納する際に、従来の512バイトセクタではなく4キロバイトセクタを使用するディスクセクターフォーマットの総称です。4096バイトセクタの背景には各トラックのビット密度を上げるという狙いがあります。データセクタの間には Sync/DAM と ECC (Error Correction Code) 情報が挟まっているので、その間隙の数を減らすのです。古いフォーマットでのフォーマット効率は 88.7% であったのに対し、Advanced Format では 97.3% のフォーマット効率を達成できます。

Advanced Format ドライブには2つの種類が存在します:

  • オレンジの "AF" ロゴが付いている Advanced Format ドライブ: 内部的には 4k セクタを使用しますが、4k セクタのサポートがないオペレーティングシステムとの互換性のためにエミュレーションレイヤーを提供します。
  • 青い "4Kn" ロゴが付いている Advanced Format 4k ネイティブドライブ: オペレーティングシステム (Windows 8 以降、Linux 2.6.31 以降) からのサポートを必要とします。このドライブには変換レイヤーが必要ないため、より安くなっています。しかし、古いツールと互換性がないかもしれません。

サポートされているセクタサイズを調べる

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

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

変換レイヤーのあるドライブ (上記を見てください) の場合は通常、論理ブロックサイズ 512 (後方互換性のため) と物理ブロックサイズ 4096 (そのドライブが Advanced Format ドライブであることを示す) が報告されます。

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

  • fdisk:
    # LC_ALL=C fdisk -l /dev/sdX | grep 'Sector size'
  • smartmontools:
    # smartctl -a /dev/sdX | grep 'Sector Size'
  • hdparm:
    # hdparm -I /dev/sdX | grep 'Sector size:'

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

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

ほとんどのソリッドステートドライブ (SSD) は、セクタサイズを 512 バイトと報告します。しかし、SSD はより大きなセクタ (典型的には 4 KiB、8 KiB、さらに大きいこともあります) を使用します。その結果として、ファイルシステムはネイティブなセクタサイズに自動的に最適化できません。パフォーマンスを最適化するには:

  • ファイルシステムを作成するときにセクタサイズを手動で指定する
  • デバイスによって報告されるネイティブなセクタサイズを変更する

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

smartmontools を使って、サポートされているセクタサイズを確認してください:

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

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

自動検出されたセクタサイズを手動でオーバーライドする代わりに、一部の SSD ではフォーマット時にセクタサイズを変更でき、真のセクタサイズに近い値を報告させることができます。

NVMe

NVMe デバイスがこれをサポートしているかどうか調べるには、Identify Namespace コマンドを使ってください。

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

nlbaf は、LBA フォーマットの数から 1 引いたものです。なので、この場合、フォーマットは1つだけがサポートされていること示しています。フォーマットのリストは出力の最後にあります。ここの lbaf 0 は、LBA フォーマット #0 を意味しています。9 という数値の lbads (LBA データサイズ) は、セクタが 29 つまり 512 バイトであることを示しています。デバイスが 4 KiB セクタを利用できる場合、lbads の値が 12 の別のエントリも表示されます。rp (Relative Performance) 値は、どのフォーマットが最高のパフォーマンスを発揮できるかを示しています (ここでは、0 がベストであると示しています)。ms は、(おそらく) セクタあたりの追加メタデータのバイト数であり、これは Linux であまり良くサポートされていないため、ここでは 0 の値を持つフォーマットを選択するのが最良です。

セクタサイズを変更するには、nvme format を使い、--lbaf パラメータで好ましい値を指定してください。nvme format が失敗する場合、マシンを (例えば systemctl suspend などで) スリープ状態にして、復帰させたあとにもう一度 nvme format を実行してみてください。nvme format が依然として失敗する場合、BIOS の設定をいじると解決するかもしれません。

SATA

SATA デバイスの場合、メーカー固有のプログラムを使用する必要があります。すべての SATA デバイスがセクタサイズを変更できるわけではありません。

Intel

Intel の場合、-set PhysicalSectorSize=4096 オプションと共に Intel Memory and Storage (MAS) Tool (intel-mas-cli-toolAUR) を使ってください。

Seagate

Seagate の場合、seagate-seachestAUR を使ってください。

すべてのドライブをスキャンし、適切なものを探してください。そして、見つけたドライブの情報を表示してください:

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

ドライブの情報が出力されるはずです。シリアル番号を確認してください。

そのドライブによってサポートされている論理ブロックサイズを確認してください:

# SeaChest_Format -d /dev/sgX --showSupportedFormats

4096 が一覧に載っている場合、論理セクタサイズを 4096 バイトに変更できます:

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

このコマンドは完了するまで2分かかります。その後、ドライブは 4K ネイティブセクタサイズを使用するようになります。

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

パーティションを正しくアライメントすることで、読み込み・変更・書き込みの過剰なサイクルを回避できます。家庭用のコンピュータでは、各パーティションの開始位置とサイズを 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進接頭辞で指定するようにしてください。

dm-crypt

この記事またはセクションは加筆を必要としています。
理由: Add example for plain dm-crypt. (議論: トーク:Advanced Format#)

As of Cryptsetup 2.4.0, luksFormat automatically detects the optimal encryption sector size for LUKS2 format [3].

However, for this to work, the device needs to report the correct default sector size, see #Setting native sector size.

After using cryptsetup luksFormat, you can check the sector size used by the LUKS2 volume with

# cryptsetup luksDump device | grep sector

If the default sector size is incorrect, you can force create a LUKS2 container with a 4K sector size and otherwise default options with:

# cryptsetup luksFormat --sector-size=4096 device

The command will abort on an error if the requested size does not match your device:

# cryptsetup luksFormat --sector-size 4096 device
(...)
Verify passphrase: 
Device size is not aligned to requested sector size.
ノート: See cryptsetup issue 585 for why the command may fail while the underlying drive does use 4K physical sectors.

If you encrypted your device with the wrong sector size, the device can be re-encrypted by running:

警告: The contained file system must have a block size of 4096 bytes or a multiple of it, otherwise it will break.
# cryptsetup reencrypt --sector-size=4096 device

ファイルシステム

mkfs.btrfs(8), mkfs.jfs(8), mkfs.nilfs2(8), mkfs.reiserfs(8) and mkswap(8) default to a 4096 byte sector size.

mkfs.ext4(8) defaults to 1024 byte sectors for file systems smaller than 512 MiB and 4096 byte sectors for 512 MiB and larger.

mkfs.xfs(8) defaults to 512 byte sectors, but will use 4096 for 512e and 4Kn disks.

mkfs.f2fs(8), mkfs.fat(8), mkfs.ntfs(8) and mkfs.udf(8) use the backing device's logical sector size. I.e. they will use 512 byte sectors for 512e disks and 4096 byte sectors for 4Kn disks.

If the storage device does not report the correct sector size, you can explicitly format the partitions according to the physical sector size.

In particular shingled magnetic recording (SMR) drives that are firmware-managed are severely and negatively impacted if using a logical sector size of 512 bytes if their physical sector size is of 4096 bytes. Those drives have different performance writing zones and remapping reallocation occurs while being idle, but during heavy active writes (e.g., RAID resilvering, backups, writing many small files, rsync, etc.), a different file system sector size could drop write speed to single digit megabytes/second, as the higher performance write areas get depleted, and the sector translation layer gets overworked on the shingled areas.

Here are some examples to set the 4096-byte sector size explicitly:

  • ext4:
    # mkfs.ext4 -b 4096 /dev/device
  • XFS:
    # mkfs.xfs -s size=4096 /dev/device
  • FAT:
    # mkfs.fat -S 4096 /dev/device
  • NTFS-3G:
    # mkfs.ntfs -Q -s 4096 /dev/device
  • UDF:
    # mkfs.udf -b 4096 /dev/device

参照