SSD Over-Provisioning mit hdparm
Solid-State Drives (SSDs) haben eine sogenannte Spare Area - einen Datenbereich, der für das Betriebssystem nicht direkt sichtbar ist. Diese Spare Area nützt die SSD unter anderem für Wear Leveling. Eine Vergrößerung der Spare Area (Over-Provisioning) kann die Performance und Lebensdauer einer SSD erhöhen. Dieser Artikel zeigt die Vergrößerung der Spare Area einer SATA SSD mit hdparm unter Linux mittels der Aktivierung der Host Protected Area (ATA8-ACS SET MAX ADDRESS
). Die nutzbare Netto-Kapazität der SSD verringert sich dadurch. Alternative Over-Provisioning Methoden und weitere Informationen zeigt der Abschnitt Spare Area des Artikels zu Solid-State Drives.
Voraussetzungen
Die verwendete SSD muss HPA unterstützen, da es sich bei HPA um ein optionales ATA-Feature handelt.[1]
Mit der SATA Revision 3.2 wurde HPA außerdem abgekündigt.[2] Neuere SSDs unterstützen HPA daher ggf. nicht mehr.
Vorbereitung
Vor dem Vergrößern der Spare Area müssen alle Blöcke der SSD gelöscht sein. Nur so kann der SSD Controller die ausgeblendeten Datenbereiche tatsächlich für Wear Leveling nutzen.
Alle Blöcke der SSD sind gelöscht, wenn
- sich die SSD im Auslieferungszustand befindet oder
- ein Secure Erase oder manuelles TRIM (je nach SSD) durchgeführt wird.
Host Protected Area aktivieren
Warnung: Aktivieren Sie die Host Protected Area nur bei SSDs die keine Daten enthalten, ansonsten droht Datenverlust.
Im Normalzustand ist die Host Protected Area (HPA) deaktiviert. Somit zeigt die SSD ihre normale Netto-Kapazität (angezeigt in Anzahl an 512 Byte Sektoren), in diesem Beispiel eine Intel 320 Series 160 GB SSD:
root@ubuntu-10-10:~# hdparm -N /dev/sdb /dev/sdb: max sectors = 312581808/312581808, HPA is disabled root@ubuntu-10-10:~#
Diese 312.581.808 Sektoren entsprechen * 512 Byte genau 160.041.885.696 Bytes, also genau der normalen Netto-Kapazität dieser SSD.
hdparm -Np aktiviert die Host Protected Area. Dabei wird die Anzahl an sichtbar bleibenden Sektoren direkt nach der -Np Option angegeben (ohne Leerzeichen dazwischen). Als weitere Parameter sind die Optionen --yes-i-know-what-i-am-doing und der Devicename notwendig:
root@ubuntu-10-10:~# hdparm -Np281323627 /dev/sdb /dev/sdb: setting max visible sectors to 281323627 (permanent) Use of -Nnnnnn is VERY DANGEROUS. You have requested reducing the apparent size of the drive. This is a BAD idea, and can easily destroy all of the drive's contents. Please supply the --yes-i-know-what-i-am-doing flag if you really want this. Program aborted. root@ubuntu-10-10:~# hdparm -Np281323627 --yes-i-know-what-i-am-doing /dev/sdb /dev/sdb: setting max visible sectors to 281323627 (permanent) max sectors = 281323627/312581808, HPA is enabled root@ubuntu-10-10:~#
Ein weiterer Aufruf von hdparm -N bestätigt die aktivierte HPA:
root@ubuntu-10-10:~# hdparm -N /dev/sdb /dev/sdb: max sectors = 281323627/312581808, HPA is enabled root@ubuntu-10-10:~#
Problem HPA unlocked
Zahlreiche Linux Distributionen haben den libata Parameter ignore_hpa aktiviert.[3] Dadurch wird die HPA beim nächsten Hochfahren oder hot-plug (bei eSATA) deaktiviert, was zu zahlreichen Problemen führen kann.[4]
Ob ignore_hpa aktiviert ist, stellt man mit folgendem Kommando fest:
cat /sys/module/libata/parameters/ignore_hpa
Wird hier "1" ausgegeben, wird HPA automatisch deaktiviert sobald eine SSD mit HPA angeschlossen wird. Das folgende Beispiel zeigt /var/log/messages eines Ubuntu 10.10, die SSD wird hier per eSATA angeschlossen. Die vierte Zeile zeigt das Deaktivieren von HPA (HPA unlocked):
Jun 1 10:07:17 ubuntu-10-10 kernel: [ 116.644752] ata6: hard resetting link Jun 1 10:07:18 ubuntu-10-10 kernel: [ 117.583941] ata6: SATA link up 3.0 Gbps (SStatus 123 SControl 300) Jun 1 10:07:18 ubuntu-10-10 kernel: [ 117.584645] ata6.00: ACPI cmd f5/00:00:00:00:00:a0 (SECURITY FREEZE LOCK) filtered out Jun 1 10:07:18 ubuntu-10-10 kernel: [ 117.606303] ata6.00: HPA unlocked: 281323627 -> 312581808, native 312581808 Jun 1 10:07:18 ubuntu-10-10 kernel: [ 117.606310] ata6.00: ATA-8: INTEL SSDSA2CW160G3, 4PC10302, max UDMA/133 Jun 1 10:07:18 ubuntu-10-10 kernel: [ 117.606314] ata6.00: 312581808 sectors, multi 1: LBA48 NCQ (depth 31/32) Jun 1 10:07:18 ubuntu-10-10 kernel: [ 117.607145] ata6.00: ACPI cmd f5/00:00:00:00:00:a0 (SECURITY FREEZE LOCK) filtered out Jun 1 10:07:18 ubuntu-10-10 kernel: [ 117.607576] ata6.00: configured for UDMA/133 Jun 1 10:07:18 ubuntu-10-10 kernel: [ 117.608514] ata6.00: configured for UDMA/133 Jun 1 10:07:18 ubuntu-10-10 kernel: [ 117.608522] ata6: EH complete Jun 1 10:07:18 ubuntu-10-10 kernel: [ 117.608699] scsi 5:0:0:0: Direct-Access ATA INTEL SSDSA2CW16 4PC1 PQ: 0 ANSI: 5 Jun 1 10:07:18 ubuntu-10-10 kernel: [ 117.608953] sd 5:0:0:0: Attached scsi generic sg2 type 0 Jun 1 10:07:18 ubuntu-10-10 kernel: [ 117.608992] sd 5:0:0:0: [sdb] 312581808 512-byte logical blocks: (160 GB/149 GiB) Jun 1 10:07:18 ubuntu-10-10 kernel: [ 117.609079] sd 5:0:0:0: [sdb] Write Protect is off Jun 1 10:07:18 ubuntu-10-10 kernel: [ 117.609128] sd 5:0:0:0: [sdb] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA Jun 1 10:07:18 ubuntu-10-10 kernel: [ 117.609373] sdb: Jun 1 10:07:18 ubuntu-10-10 kernel: [ 117.610090] sd 5:0:0:0: [sdb] Attached SCSI disk
Betroffene Linux Systeme
Von diesem Verhalten sind zahlreiche Linux Distributionen betroffen, z.B.:
- Ubuntu 10.10
Ein Patch von Tejun Heo (mit einem on-demand HPA unlocking) löst das Problem.[5][6] Neuere Linux Kernel und Linux Distributionen haben diesen Patch integriert, darunter z.B.
- Ubuntu 11.04
Bei Ubuntu 11.04 funktioniert die Verwendung der HPA (HPA detected):
root@ubuntu:~# tail -f /var/log/kern.log Jun 1 08:54:32 ubuntu kernel: [ 213.433902] ata7: exception Emask 0x10 SAct 0x0 SErr 0x4050000 action 0xe frozen Jun 1 08:54:32 ubuntu kernel: [ 213.433909] ata7: irq_stat 0x00400040, connection status changed Jun 1 08:54:32 ubuntu kernel: [ 213.433914] ata7: SError: { PHYRdyChg CommWake DevExch } Jun 1 08:54:32 ubuntu kernel: [ 213.433926] ata7: hard resetting link Jun 1 08:54:32 ubuntu kernel: [ 214.182197] ata7: SATA link up 3.0 Gbps (SStatus 123 SControl 300) Jun 1 08:54:32 ubuntu kernel: [ 214.182631] ata7.00: HPA detected: current 281323627, native 312581808 Jun 1 08:54:32 ubuntu kernel: [ 214.182640] ata7.00: ATA-8: INTEL SSDSA2CW160G3, 4PC10302, max UDMA/133 Jun 1 08:54:32 ubuntu kernel: [ 214.182645] ata7.00: 281323627 sectors, multi 1: LBA48 NCQ (depth 31/32) Jun 1 08:54:32 ubuntu kernel: [ 214.183140] ata7.00: configured for UDMA/133 Jun 1 08:54:32 ubuntu kernel: [ 214.202174] ata7: EH complete Jun 1 08:54:32 ubuntu kernel: [ 214.202317] scsi 6:0:0:0: Direct-Access ATA INTEL SSDSA2CW16 4PC1 PQ: 0 ANSI: 5 Jun 1 08:54:32 ubuntu kernel: [ 214.202601] sd 6:0:0:0: [sdd] 281323627 512-byte logical blocks: (144 GB/134 GiB) Jun 1 08:54:32 ubuntu kernel: [ 214.202679] sd 6:0:0:0: Attached scsi generic sg4 type 0 Jun 1 08:54:32 ubuntu kernel: [ 214.202761] sd 6:0:0:0: [sdd] Write Protect is off Jun 1 08:54:32 ubuntu kernel: [ 214.202768] sd 6:0:0:0: [sdd] Mode Sense: 00 3a 00 00 Jun 1 08:54:32 ubuntu kernel: [ 214.202823] sd 6:0:0:0: [sdd] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA Jun 1 08:54:32 ubuntu kernel: [ 214.203555] sdd: Jun 1 08:54:32 ubuntu kernel: [ 214.204000] sd 6:0:0:0: [sdd] Attached SCSI disk ^C root@ubuntu:~# cat /proc/partitions major minor #blocks name 7 0 1258132 loop0 8 0 976762584 sda 8 1 19530752 sda1 8 2 1 sda2 8 5 1998848 sda5 8 6 878905344 sda6 8 48 140661813 sdd root@ubuntu:~# fdisk -l /dev/sdd Disk /dev/sdd: 144.0 GB, 144037697024 bytes 255 heads, 63 sectors/track, 17511 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xafd4e895 Device Boot Start End Blocks Id System root@ubuntu:~#
Automatisches Deaktivieren der HPA bei betroffenen Linux Systemen unterbinden
Temporär
Temporär kann ignore_hpa über das sysfs Filesystem deaktiviert werden. Diese temporäre Änderung ist hilfreich wenn eine SSD mit HPA per eSATA kurzzeitig an einen Rechner angeschlossen wird. Für SSDs, die bereits beim Hochfahren des Rechners angeschlossen sind, ist eine permanente Lösung (siehe unten) nötig. Die temporäre Einstellung bleibt bis zum nächsten Reboot gültig:
root@ubuntu-10-10:~# cd /sys/module/libata/parameters root@ubuntu-10-10:/sys/module/libata/parameters# cat ignore_hpa 1 root@ubuntu-10-10:/sys/module/libata/parameters# echo 0 > ignore_hpa root@ubuntu-10-10:/sys/module/libata/parameters# cat ignore_hpa 0 root@ubuntu-10-10:/sys/module/libata/parameters#
Die HPA wird nun richtig verwendet (HPA detected: current 281323627, native 312581808):
Jun 1 11:20:13 ubuntu-10-10 kernel: [ 70.824850] ata6: hard resetting link Jun 1 11:20:14 ubuntu-10-10 kernel: [ 71.764776] ata6: SATA link up 3.0 Gbps (SStatus 123 SControl 300) Jun 1 11:20:14 ubuntu-10-10 kernel: [ 71.765573] ata6.00: ACPI cmd f5/00:00:00:00:00:a0 (SECURITY FREEZE LOCK) filtered out Jun 1 11:20:14 ubuntu-10-10 kernel: [ 71.765980] ata6.00: HPA detected: current 281323627, native 312581808 Jun 1 11:20:14 ubuntu-10-10 kernel: [ 71.765989] ata6.00: ATA-8: INTEL SSDSA2CW160G3, 4PC10302, max UDMA/133 Jun 1 11:20:14 ubuntu-10-10 kernel: [ 71.765993] ata6.00: 281323627 sectors, multi 1: LBA48 NCQ (depth 31/32) Jun 1 11:20:14 ubuntu-10-10 kernel: [ 71.766845] ata6.00: ACPI cmd f5/00:00:00:00:00:a0 (SECURITY FREEZE LOCK) filtered out Jun 1 11:20:14 ubuntu-10-10 kernel: [ 71.767284] ata6.00: configured for UDMA/133 Jun 1 11:20:14 ubuntu-10-10 kernel: [ 71.768148] ata6.00: configured for UDMA/133 Jun 1 11:20:14 ubuntu-10-10 kernel: [ 71.768157] ata6: EH complete Jun 1 11:20:14 ubuntu-10-10 kernel: [ 71.768374] scsi 5:0:0:0: Direct-Access ATA INTEL SSDSA2CW16 4PC1 PQ: 0 ANSI: 5 Jun 1 11:20:14 ubuntu-10-10 kernel: [ 71.768663] sd 5:0:0:0: [sdb] 281323627 512-byte logical blocks: (144 GB/134 GiB) Jun 1 11:20:14 ubuntu-10-10 kernel: [ 71.768679] sd 5:0:0:0: Attached scsi generic sg2 type 0 Jun 1 11:20:14 ubuntu-10-10 kernel: [ 71.768772] sd 5:0:0:0: [sdb] Write Protect is off Jun 1 11:20:14 ubuntu-10-10 kernel: [ 71.768807] sd 5:0:0:0: [sdb] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA Jun 1 11:20:14 ubuntu-10-10 kernel: [ 71.769104] sdb: Jun 1 11:20:14 ubuntu-10-10 kernel: [ 71.770897] sd 5:0:0:0: [sdb] Attached SCSI disk
Permanent
Je nachdem ob libata fest in den Kernel einkompiliert wurde oder als Modul vorliegt kann ignore_hpa folgendermaßen permanent deaktiviert werden:
Bei libata im Kernel:[7]
- Kernel-Option
libata.ignore_hpa=0
in der Bootloader Konfiguration ergänzen
Bei libata als Modul:[8]
bash -c 'echo options libata ignore_hpa=0 > /etc/modprobe.d/libata.conf'
(als root oder per sudo)
Einzelnachweise
- ↑ Host Protected Area (de.wikipedia.org)
- ↑ Parted Magic Secure Erase (community.spiceworks.com, 03.02.2015): Our newest SSDs now support the SATA interface version 3.2. In this version, the HPA and DCO have been retired. The DCO has been replaced by something called AMAC, for Accessible Max Address Configuration. AMAC settings will also persist through a SECURITY ERASE (or the SANITIZE commands).
- ↑ (PATCH 1/3) ide: add "ignore_hpa" module parameter (kerneltrap.org)
- ↑ Bug #380138 in linux (Ubuntu): “Do NOT disable HPA by default -> leads to data loss” (bugs.launchpad.net)
- ↑ (PATCH 8/8) libata: implement on-demand HPA unlocking (lkml.org)
- ↑ libata: implement on-demand HPA unlocking (kerneltrap.org)
- ↑ Bug #380138 in linux (Ubuntu): “Do NOT disable HPA by default -> leads to data loss” (bugs.launchpad.net), Comment 13
- ↑ Bug #380138 in linux (Ubuntu): “Do NOT disable HPA by default -> leads to data loss” (bugs.launchpad.net), Comment 15
Autor: Werner Fischer Werner Fischer arbeitet im Product Management Team von Thomas-Krenn. Er evaluiert dabei neueste Technologien und teilt sein Wissen in Fachartikeln, bei Konferenzen und im Thomas-Krenn Wiki. Bereits 2005 - ein Jahr nach seinem Abschluss des Studiums zu Computer- und Mediensicherheit an der FH Hagenberg - heuerte er beim bayerischen Server-Hersteller an. Als Öffi-Fan nutzt er gerne Bus & Bahn und genießt seinen morgendlichen Spaziergang ins Büro.
|