ATA Trim
Mit dem ATA Trim Kommando teilt das Betriebssystem einer SSD mit welche Datenbereiche nicht mehr benötigt werden und damit als gelöscht angesehen werden können. Wenn die gesamte Kapazatität einer SSD genutzt wird erhöht ATA Trim die Performance und Lebensdauer der SSD. Ist ATA Trim nicht möglich (wie etwa beim Einsatz von RAID Controllern) bringt ein Over-Provisioning ähnliche Vorteile - allerdings mit etwas verminderter nutzbarer Kapazität (z.B. 90%).[1]
Inhaltsverzeichnis |
Voraussetzungen
Damit ATA Trim funktioniert muss es von folgenden Komponenten unterstützt werden:
- von der SSD selbst
- vom Betriebssystem (z.B. Windows 7[2], Linux Kernel ab Version 2.6.33[3])
- vom Dateisystem
ATA Trim mit RAID Controllern
Mitte August 2010 sind uns noch keine RAID-Controller bekannt, die ATA TRIM für SSDs in RAID-Volumes unterstützen.[4][5] Das Firmware/Driver RAID von Intel unterstützt ab Rapid Storage Technology 9.6 das TRIM Kommando ausschließlich für Laufwerke (im AHCI Modus und im RAID Modus), die nicht Teil eines RAID-Volumes sind.[6] Künftig will Intel für RAID 0 Verbünde ebenfalls ATA Trim unterstützen.[7]
ATA Trim bei Linux Swap Devices
Swap Devices unter Linux unterstützen Discard:[8][9][10]
- der Linux Kernel unterstützt Discard für Trim für Swap-Devices ab Kernel 2.6.29
- da manche SSDs bei sofortigem Discard Performance-Einbußen zeigen, ist der laufende Discard seit Kernel 2.6.36 nun optional (-d Option von swapon)
- beim erstmaligen Aufruf von swapon wird aber weiterhin unabhängig von der -d Option der gesamte Swap-Bereich per Discard getrimmt
ATA Trim mit Linux Device Mapper
Ab Kernel 2.6.36 haben folgende Targets Support für Discard:
- dm-delay
- dm-linear
- dm-mpath
- dm-stripe (raid0)
Ab Kernel 2.6.38 zusätzlich:
- dm-mirror (raid1)
Ab Kernel 3.1 zusätzlich:
- dm-crypt (optional)
ATA Trim mit Linux LVM
LVM basiert seit Linux Kernel 2.6 auf dem Device Mapper und verwendet dabei das dm-linear Target (siehe LVM Grundlagen - LVM und Device Mapper).
Damit unterstützt LVM seit Kernel 2.6.36 ATA Trim.
ATA Trim mit Linux Software RAID
Status November 2012
- ATA Trim mit Linux Software RAID ist ab Linux Kernel 3.7 möglich.
Status August 2012
- Shaohua Li hat ein Patchset eingereicht, das Support für discard (ATA TRIM) bringen soll: (patch 0/7 v2) MD linear/0/1/10/5 TRIM support
Status Juli 2011
- Linux Software RAID (md) hat keinen eingebauten discard-Support und unterstützt damit kein TRIM. Die Nutzung von dm-mirror des Device Mappers zur Datenspiegelung ist jedoch mit discard-Support etwa ab RHEL 6.1 möglich. Red Hat rät von der Verwendung von Linux Software RAID mit den RAID Leveln 1, 4, 5 und 6 ab, da bei der RAID-Initialisierung RAID Managment Utilities wie mdadm alle Blöcke des Storage Devices beschreiben um die korrekte Funktionalität von Prüfsummen sicherzustellen. Da die SSD damit voll beschrieben ist, sinken Lebensdauer und Performance der SSD.[11] Abhilfe wäre hier ein großzügiges SSD Over-Provisioning mit hdparm.
- Chris Caputo hat ein Skript geschrieben (raid1ext4trim.sh-1.4), das ein manuelles ATA Trim für Ext4 Dateisysteme auf einem Software RAID 1 ermöglicht.[12][13] Die Slaves Devices des RAIDs müssen dabei aber vollständige SSDs sein (z.B. /dev/sda) und dürfen keine Partitionen sein (z.B. /dev/sda1). Das Skript liegt hdparm bei und ist Unterverzeichnis hdparm-9.37/wiper/contrib/ des Quelltextpakets abgelegt.
Mögliche künftige Entwicklungen:
- Im Juni und Juli 2011 gab es eine Diskussion zum möglichen discard-Support von Linux Software RAID. Siehe dazu Linux Software RAID Roadmap.
Beispiel raid1ext4trim.sh-1.4
Das folgende Beispiel zeigt raid1ext4trim.sh-1.4 angewandt auf ein RAID 1 mit Metadaten-Version 1.0:
[root@localhost ~]# /root/raid1ext4trim.sh-1.4 /dev/md0 /mnt raid1ext4trim.sh-1.4: TRIM utility for live RAID1 ext4 SATA SSDs, version 1.4, by Chris Caputo, based on Mark Lord's wiper.sh. Reserve defaulting to 10 megabytes. Creating temporary file (107219596 KB '/mnt/raid1ext4trim.sh-1.4_TMPFILE.12054') ... TRIMable constituents of md0: sda sdb This will be a DRY-RUN only. Use --commit to do it for real. Simulating TRIM operations... TRIM beginning on sda... (dry-run) trimming 214439200 sectors from 3504 ranges TRIM finished successfully on sda. TRIM beginning on sdb... (dry-run) trimming 214439200 sectors from 3504 ranges TRIM finished successfully on sdb. Removing temporary file '/mnt/raid1ext4trim.sh-1.4_TMPFILE.12054'... Done. [root@localhost ~]# /root/raid1ext4trim.sh-1.4 --commit /dev/md0 /mnt raid1ext4trim.sh-1.4: TRIM utility for live RAID1 ext4 SATA SSDs, version 1.4, by Chris Caputo, based on Mark Lord's wiper.sh. Reserve defaulting to 10 megabytes. Creating temporary file (107219596 KB '/mnt/raid1ext4trim.sh-1.4_TMPFILE.12137') ... TRIMable constituents of md0: sda sdb Beginning TRIM operations... TRIM beginning on sda... /dev/sda: trimming 31080445 sectors from 512 ranges succeeded /dev/sda: trimming 31375361 sectors from 512 ranges succeeded /dev/sda: trimming 31358977 sectors from 512 ranges succeeded /dev/sda: trimming 31440896 sectors from 512 ranges succeeded /dev/sda: trimming 31440896 sectors from 512 ranges succeeded /dev/sda: trimming 31309822 sectors from 512 ranges succeeded /dev/sda: trimming 26432803 sectors from 432 ranges succeeded TRIM finished successfully on sda. TRIM beginning on sdb... /dev/sdb: trimming 31080445 sectors from 512 ranges succeeded trimming 31375361 sectors from 512 ranges succeeded trimming 31358977 sectors from 512 ranges succeeded trimming 31440896 sectors from 512 ranges succeeded trimming 31440896 sectors from 512 ranges succeeded trimming 31309822 sectors from 512 ranges succeeded trimming 26432803 sectors from 432 ranges succeeded TRIM finished successfully on sdb. Removing temporary file '/mnt/raid1ext4trim.sh-1.4_TMPFILE.12137'... Done. [root@localhost ~]#
Angewandt auf ein RAID 1 mit Metadaten-Version 1.2 funktioniert das Skript nicht, da das Skript davon ausgeht dass die Daten jeweils am Beginn der darunter liegenden Devices beginnen:
[root@localhost ~]# /root/raid1ext4trim.sh-1.4 --verbose /dev/md0 /mnt raid1ext4trim.sh-1.4: TRIM utility for live RAID1 ext4 SATA SSDs, version 1.4, by Chris Caputo, based on Mark Lord's wiper.sh. Reserve defaulting to 10 megabytes. Creating temporary file (105760448 KB '/mnt/raid1ext4trim.sh-1.4_TMPFILE.11462') ... Direct I/O of last extent of tmpfile on sda doesn't match that of md0. Excluding. Direct I/O of last extent of tmpfile on sdb doesn't match that of md0. Excluding. No constituent of md0 array has a matching checksum. Aborting. Removing temporary file '/mnt/raid1ext4trim.sh-1.4_TMPFILE.11462'... Aborted. [root@localhost ~]#
Online oder Batched
ATA Trim kann entweder sofort zur Laufzeit beim Löschen von Dateien die entsprechenden Daten auf der SSD löschen (unter Linux als Online Discard[14][15] bezeichnet) oder zyklisch manuell durch Hilfsprogramme nicht mehr benötigte Blöcke freigeben (unter Linux mit FITRIM ioctl als Batched Discard bezeichnet), wie die Tabelle zeigt:
| Betriebssystem / Dateisystem | automatisches ATA TRIM (Daten werden sofort gelöscht) |
manuelles ATA TRIM (Daten werden mit einem Tool gelöscht) |
|---|---|---|
| Windows Vista Windows XP Windows Server 2008 Windows Server 2003 |
- | ja, über Herstellertools wie die Intel Solid State Drive Toolbox |
| Windows 7 Windows Server 2008 R2 |
ja[16][17] | ja, über Herstellertools wie die Intel Solid State Drive Toolbox |
| Linux / Ext4 | ja, Online Discard ab Kernel 2.6.33 (erfordert Ext4 Option discard) |
ja, über wiper.sh[18] (nutzt hdparm)[19] oder Batched Discard ab Kernel 2.6.37 über fstrim[20][21][22] (in util-linux 2.19 und neuer enthalten)[23] |
| Linux / Btrfs | ja, Online Discard ab Linux Kernel 2.6.32 (das Libata Subsystem unterstützt Discard ab Kernel 2.6.33) (erfordert Btrfs Option discard) |
ja, Batched Discard ab Kernel 2.6.39 |
Beispiel: ATA Trim in Ubuntu 10.10
Damit Sie ATA Trim nutzen können, muss die SSD selbst ATA TRIM unterstützen, wie auch in diesem Beispiel hier (der * zeigt, dass die Option verfügbar ist):
root@ubuntu-10-10:~# hdparm -I /dev/sda | grep -i trim * Data Set Management TRIM supported * Deterministic read ZEROs after TRIM root@ubuntu-10-10:~#
Standardkonfiguration ohne ATA Trim
In diesem Test schreiben wir die Buchstabenkette ABCDEFGHIJKLMNOPQRSTUVWXYZ in eine Datei. Beim Lesen des Sektors mit hdparm werden die entsprechenden ASCII-Codes[24] im Hex-Format sichtbar.
Anmerkung: bei manchen SSDs (z.B. Intel 320 Series SSDs) ist nach dem echo Kommando Aufruf von sync notwendig, damit hdparm --fibmap LBA Grenzen ausgibt.
root@ubuntu-10-10:~# echo "ABCDEFGHIJKLMNOPQRSTUVWXYZ" > /root/testfile1.txt
root@ubuntu-10-10:~# hdparm --fibmap /root/testfile1.txt
/root/testfile1.txt:
filesystem blocksize 4096, begins at LBA 61052928; assuming 512 byte sectors.
byte_offset begin_LBA end_LBA sectors
0 66989472 66989479 8
root@ubuntu-10-10:~# hdparm --read-sector 66989472 /dev/sda
/dev/sda:
reading sector 66989472: succeeded
4241 4443 4645 4847 4a49 4c4b 4e4d 504f
5251 5453 5655 5857 5a59 000a 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
[...]
root@ubuntu-10-10:~# rm /root/testfile1.txt
root@ubuntu-10-10:~# sync
root@ubuntu-10-10:~# hdparm --read-sector 66989472 /dev/sda
/dev/sda:
reading sector 66989472: succeeded
4241 4443 4645 4847 4a49 4c4b 4e4d 504f
5251 5453 5655 5857 5a59 000a 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
[...]
root@ubuntu-10-10:~#
Konfiguration mit ATA Trim mit Online Discard
Mit der aktivierten ext4 Mount Option discard schickt das ext4 Dateisystem discard/TRIM Kommandos an das darunter liegende Storage Device. Die Option muss derzeit allerdings noch manuell in /etc/fstab aktiviert werden, da discard in der Standardkonfiguration deaktiviert ist:[25]
- discard: Controls whether ext4 should issue discard/TRIM commands to the underlying block device when blocks are freed. This is useful for SSD devices and sparse/thinly-provisioned LUNs, but it is off by default until sufficient testing has been done.
Die Option discard kann einfach als Option in /etc/fstab ergänzt werden:
[...] # / was on /dev/sda3 during installation UUID=1b7be627-fcb5-43b4-a9fb-72c112041c53 / ext4 errors=remount-ro,discard 0 1 [...]
Nach einem Reboot ist die Option für die /-Partition nun aktiv:
root@ubuntu-10-10:~# mount /dev/sda3 on / type ext4 (rw,errors=remount-ro,discard,commit=600) [...] root@ubuntu-10-10:~#
Beim Löschen von Dateien werden die entsprechenden Daten nun tatsächlich auf der SSD entfernt:
root@ubuntu-10-10:~# echo "ABCDEFGHIJKLMNOPQRSTUVWXYZ" > /root/testfile2.txt
root@ubuntu-10-10:~# sync
root@ubuntu-10-10:~# hdparm --fibmap /root/testfile2.txt
/root/testfile2.txt:
filesystem blocksize 4096, begins at LBA 61052928; assuming 512 byte sectors.
byte_offset begin_LBA end_LBA sectors
0 73902760 73902767 8
root@ubuntu-10-10:~# hdparm --read-sector 73902760 /dev/sda
/dev/sda:
reading sector 73902760: succeeded
4241 4443 4645 4847 4a49 4c4b 4e4d 504f
5251 5453 5655 5857 5a59 000a 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
[...]
root@ubuntu-10-10:~# rm /root/testfile2.txt
root@ubuntu-10-10:~# sync
root@ubuntu-10-10:~# hdparm --read-sector 73902760 /dev/sda
/dev/sda:
reading sector 73902760: succeeded
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
[...]
root@ubuntu-10-10:~#
Weitere Informationen zu ATA Trim unter Linux
- SSD discard (trim) support (openSUSE Support Database)
- Ubuntu 10.04 LTS enthält Kernel 2.6.32 und wird keinen backported Online Discard Support bekommen: Trim support missing from Linux kernel (bugs.launchpad.net)
- Does Ubuntu have support for the TRIM command for use with SSD? (askubuntu.com)
- wiper.sh and TRIM on an SSD (ubuntuforums.org)
- How to enable TRIM? (askubuntu.com)
- HOWTO: Configure Ext4 to Enable TRIM Support for SSDs on Ubuntu and Other Distributions (lightrush's Web Nest, 17.10.2010)
- Performance evaluation of Linux Discard Support (Präsentation von Lukas Czerner (Red Hat), 12.02.2011)
- Enabling and Testing SSD TRIM Support Under Linux (techgage.com, 06.05.2011)
- TRIM (wiki.ubuntuusers.de)
Einzelnachweise
- ↑ Re: Software RAID and TRIM (Linux Raid Mailing List) As long as your SSDs have some over-provisioning (or you only partition something like 90% of the drive), and it's got good garbage collection, then TRIM will have minimal effect.
- ↑ http://blogs.msdn.com/b/e7/archive/2009/05/05/support-and-q-a-for-solid-state-drives-and.aspx
- ↑ http://www.heise.de/open/artikel/ATA-Trim-DRBD-Block-Layer-Virtualisierung-und-Tracing-936993.html
- ↑ http://www.heise.de/ct/hotline/Kein-Trim-Befehl-im-SSD-RAID-991529.html
- ↑ SSD TRIM und Adaptec RAID Controller (Adaptec Support Knowledgebase ASK Answer ID 16999)
- ↑ Intel® Rapid Storage Technology: RAID features by chipset/controller hub (intel.com)
- ↑ Intel plant ATA-Trim-Unterstützung im RAID-Treiber (heise.de, 22.11.2011)
- ↑ swap: discard while swapping only if SWAP_FLAG_DISCARD
- ↑ discard change to swapon(2) and swapon(8) (Hugh Dickins, util-linux-ng mailing list, 24.10.2010)
- ↑ Re: discard change to swapon(2) and swapon(8) (Hugh Dickins, util-linux-ng mailing list, 09.11..2010)
- ↑ Chapter 22. Solid-State Disk Deployment Guidelines Red Hat Enterprise Linux 6, Storage Administration Guide (docs.redhat.com)
- ↑ script for TRIM on RAID1 full-disk arrays with live ext4 filesystems (Linux RAID Mailing List)
- ↑ hdparm: Detail: 3007001 - TRIM on RAID1 full-disk arrays with live ext4 filesystems (SourceForge.net)
- ↑ Kernel realtime discard support
- ↑ Patchwork (2/6) libata: Report supported TRIM payload size The bigger problem for now is that the block layer does not export a way to pass in a vectorized list of ranges to discard.
- ↑ http://en.wikipedia.org/wiki/TRIM#Operating_system_and_SSD_support
- ↑ http://www.heise.de/newsticker/meldung/SSD-Hersteller-optimieren-Firmware-fuer-Windows-7-2-Update-842820.html
- ↑ http://sourceforge.net/projects/hdparm/files/
- ↑ Re: (PATCH 2/6) libata: Report supported TRIM payload size (linux-scsi mailing list, Greg Freemyer, 19.08.2010) The fundamental problem with hdparm is that because it bypasses most of the kernel i/o stack, it is not compatible with DM/LVM, but I think its a great prototype of what the kernel could do eventually.
- ↑ http://lwn.net/Articles/383933/
- ↑ http://www.heise.de/open/artikel/Kernel-Log-Was-2-6-37-bringt-2-Dateisysteme-1144739.html
- ↑ http://fstrim.sourceforge.net/
- ↑ fstrim: add new command
- ↑ http://de.wikipedia.org/wiki/American_Standard_Code_for_Information_Interchange#ASCII-Tabelle
- ↑ http://www.kernel.org/doc/Documentation/filesystems/ext4.txt
Autor: Werner Fischer
