Difference between revisions of "Solid state drive"

From ArchWiki
Jump to navigation Jump to search
(→‎Continuous TRIM: Make it clearer which Samsung 8* drives are affected with the problem, and make it read much better)
m (→‎Continuous TRIM: fix capitalization)
(12 intermediate revisions by the same user not shown)
Line 24: Line 24:
 
Most SSDs support the [[wikipedia:TRIM|ATA_TRIM command]] for sustained long-term performance and wear-leveling. For a performance benchmark before and after filling an SSD with data, see [http://www.techspot.com/review/737-ocz-vector-150-ssd/page9.html].
 
Most SSDs support the [[wikipedia:TRIM|ATA_TRIM command]] for sustained long-term performance and wear-leveling. For a performance benchmark before and after filling an SSD with data, see [http://www.techspot.com/review/737-ocz-vector-150-ssd/page9.html].
  
As of Linux kernel version 3.8 onwards, the following filesystems support TRIM: [[Ext4]], [[Btrfs]], [[JFS]] [http://www.phoronix.com/scan.php?page=news_item&px=MTE5ODY], [[XFS]] [http://xfs.org/index.php/FITRIM/discard], [[F2FS]], VFAT.
+
As of Linux kernel version 3.8 onwards, the following filesystems support TRIM: [[Ext4]], [[Btrfs]], [[JFS]] [http://www.phoronix.com/scan.php?page=news_item&px=MTE5ODY], [[XFS]] [http://xfs.org/index.php/FITRIM/discard], [[F2FS]], VFAT. See also [[w:List_of_file_systems#File_systems_optimized_for_flash_memory.2C_solid_state_media|List of file systems optimized for SSD]].
  
 
As of {{Pkg|ntfs-3g}} version 2015.3.14, TRIM is supported for [[NTFS]] filesystem too [http://permalink.gmane.org/gmane.comp.file-systems.ntfs-3g.devel/1101].
 
As of {{Pkg|ntfs-3g}} version 2015.3.14, TRIM is supported for [[NTFS]] filesystem too [http://permalink.gmane.org/gmane.comp.file-systems.ntfs-3g.devel/1101].
Line 47: Line 47:
 
| {{Pkg|ntfs-3g}} || {{No}} || {{Yes}}
 
| {{Pkg|ntfs-3g}} || {{No}} || {{Yes}}
 
|}
 
|}
 +
 +
{{Warning|Users need to be certain that their SSD supports TRIM before attempting to use it. Data loss can occur otherwise!}}
  
 
To verify TRIM support, run:
 
To verify TRIM support, run:
Line 54: Line 56:
  
 
{{Note|There are different types of TRIM support defined by the specification. Hence, the output may differ depending what the drive supports. See [[w:TRIM#ATA]] for more information.}}
 
{{Note|There are different types of TRIM support defined by the specification. Hence, the output may differ depending what the drive supports. See [[w:TRIM#ATA]] for more information.}}
 
See also [[File systems]] and [[w:List_of_file_systems#File_systems_optimized_for_flash_memory.2C_solid_state_media]].
 
  
 
==== Periodic TRIM ====
 
==== Periodic TRIM ====
Line 67: Line 67:
 
==== Continuous TRIM ====
 
==== Continuous TRIM ====
  
{{Warning|1=Users need to be certain that their SSD supports TRIM before attempting to mount a partition with the {{ic|discard}} flag. Data loss can occur otherwise! Unfortunately, there are wide quality gaps of SSD's bios' to perform continuous TRIM, which is also why using the {{ic|discard}} mount flag is [http://thread.gmane.org/gmane.comp.file-systems.ext4/41974 recommended against] generally by filesystem developer Theodore Ts'o. If in doubt about your hardware, [[#Apply periodic TRIM via fstrim]] instead.
+
{{Warning|Unfortunately, there are wide quality gaps of SSD's bios' to perform continuous TRIM, which is also why using the {{ic|discard}} mount flag is [http://thread.gmane.org/gmane.comp.file-systems.ext4/41974 recommended against] generally by filesystem developer Theodore Ts'o. If in doubt about your hardware, apply [[#Periodic TRIM]] instead.}}
  
Also be aware of other [[WikiPedia:Trim_(computing)#Shortcomings|shortcomings]], most importantly that "TRIM commands [https://blog.algolia.com/when-solid-state-drives-are-not-that-solid/ have been linked] to serious data corruption in several devices, most notably Samsung 8* series." After the data corruption [https://github.com/torvalds/linux/blob/e64f638483a21105c7ce330d543fa1f1c35b5bc7/drivers/ata/libata-core.c#L4109-L4286 had been confirmed], the Linux kernel blacklisted queued TRIM command execution for a number of [https://github.com/torvalds/linux/blob/v4.5/drivers/ata/libata-core.c#L4223 popular devices] as of March 28, 2016. For affected Samsung 8 series drives, the drive incorrectly identifies it supports queued TRIM even though it does not. Firmware updated EVO 850's and newer EVO 840's or 840's with updated firmware and newer drives in the 8* series are all affected. Read [https://bugs.launchpad.net/ubuntu/+source/fstrim/+bug/1449005 trim does not work with Samsung 840 EVO after firmware update] on the Ubuntu bug tracker for more information.}}
+
{{Note|Before [[w:Serial_ATA#SATA_revision_3.1|SATA 3.1]] all TRIM commands were synchronous, so continuous trimming would produce frequent system freezes. In this case, applying [[#Periodic TRIM]] less often is better alternative. Similar issue holds also for a [https://github.com/torvalds/linux/blob/master/drivers/ata/libata-core.c#L4403-L4417 number of devices], for which queued TRIM command execution was blacklisted due to [https://blog.algolia.com/when-solid-state-drives-are-not-that-solid/ serious data corruption]. See [[Wikipedia:Trim (computing)#Shortcomings]] for details.}}
  
 
Using the {{ic|discard}} option for a mount in {{ic|/etc/fstab}} enables continuous TRIM in device operations:
 
Using the {{ic|discard}} option for a mount in {{ic|/etc/fstab}} enables continuous TRIM in device operations:

Revision as of 15:26, 29 July 2016

zh-CN:Solid State Drives zh-TW:Solid State Drives

Tango-inaccurate.pngThe factual accuracy of this article or section is disputed.Tango-inaccurate.png

Reason: What is a "PnP device"? Surely not plug and play... (Discuss in Talk:Solid state drive#)

Solid State Drives (SSDs) are not PnP devices. Special considerations such as partition alignment, choice of file system, TRIM support, etc. are needed to set up SSDs for optimal performance. This article attempts to capture referenced, key learnings to enable users to get the most out of SSDs under Linux. Users are encouraged to read this article in its entirety before acting on recommendations.

Usage

TRIM

Tango-edit-clear.pngThis article or section needs language, wiki syntax or style improvements. See Help:Style for reference.Tango-edit-clear.png

Reason: Merge with #Choice of filesystem (old section), explain why and how to choose the file system. (Discuss in Talk:Solid state drive#)

Most SSDs support the ATA_TRIM command for sustained long-term performance and wear-leveling. For a performance benchmark before and after filling an SSD with data, see [1].

As of Linux kernel version 3.8 onwards, the following filesystems support TRIM: Ext4, Btrfs, JFS [2], XFS [3], F2FS, VFAT. See also List of file systems optimized for SSD.

As of ntfs-3g version 2015.3.14, TRIM is supported for NTFS filesystem too [4].

File system Continuous TRIM
(discard option)
Periodic TRIM
(fstrim)
Ext3 No ?
Ext4 Yes Yes
Btrfs Yes Yes
JFS Yes Yes
XFS Yes Yes
F2FS Yes Yes
VFAT Yes No
ntfs-3g No Yes
Warning: Users need to be certain that their SSD supports TRIM before attempting to use it. Data loss can occur otherwise!

To verify TRIM support, run:

# hdparm -I /dev/sda | grep TRIM
        *    Data Set Management TRIM supported (limit 1 block)
Note: There are different types of TRIM support defined by the specification. Hence, the output may differ depending what the drive supports. See w:TRIM#ATA for more information.

Periodic TRIM

The util-linux package provides fstrim.service and fstrim.timer systemd unit files. Enabling the timer will activate the service weekly, which will then trim all mounted filesystems on devices that support the discard operation.

The timer relies on the timestamp of /var/lib/systemd/timers/stamp-fstrim.timer (which it will create upon first invocation) to know whether a week has elapsed since it last ran. Therefore there is no need to worry about too frequent invocations, in an anacron-like fashion.

To query the units activity and status, see journalctl. To change the periodicity of the timer or the command run, edit the provided unit files.

Continuous TRIM

Warning: Unfortunately, there are wide quality gaps of SSD's bios' to perform continuous TRIM, which is also why using the discard mount flag is recommended against generally by filesystem developer Theodore Ts'o. If in doubt about your hardware, apply #Periodic TRIM instead.
Note: Before SATA 3.1 all TRIM commands were synchronous, so continuous trimming would produce frequent system freezes. In this case, applying #Periodic TRIM less often is better alternative. Similar issue holds also for a number of devices, for which queued TRIM command execution was blacklisted due to serious data corruption. See Wikipedia:Trim (computing)#Shortcomings for details.

Using the discard option for a mount in /etc/fstab enables continuous TRIM in device operations:

/dev/sda2  /boot       ext4  defaults,noatime,discard   0  2
/dev/sda1  /boot/efi   vfat  defaults,noatime,discard   0  2
/dev/sda3  /           ext4  defaults,noatime,discard   0  2

The main benefit of continuous TRIM is speed; an SSD can perform more efficient garbage collection. However, results vary and particularly earlier SSD generations may also show just the opposite effect. Also for this reason, some distributions decided against using it (e.g. Ubuntu: see this article and the related blueprint).

Note: There is no need for the discard flag if you run fstrim periodically.

On the ext4 filesystem, the discard flag can also be set as a default mount option using tune2fs:

# tune2fs -o discard /dev/sdXY

Using the default mount options instead of an entry in /etc/fstab is useful for external drives, because such partition will be mounted with the default options also on other machines. There is no need to edit /etc/fstab on every machine.

Note: The default mount options are not listed in /proc/mounts.

LVM

Change the value of issue_discards option from 0 to 1 in /etc/lvm/lvm.conf.

Note: Enabling this option will "issue discards to a logical volumes's underlying physical volume(s) when the logical volume is no longer using the physical volumes' space (e.g. lvremove, lvreduce, etc)" (see man lvm.conf and/or inline comments in /etc/lvm/lvm.conf). As such it does not seem to be required for "regular" TRIM requests (file deletions inside a filesystem) to be functional.

dm-crypt

Warning: The discard option allows discard requests to be passed through the encrypted block device. This improves performance on SSD storage but has security implications. See Dm-crypt/TRIM support for SSD for more information.

For non-root filesystems, configure /etc/crypttab to include discard in the list of options for encrypted block devices located on a SSD (see Dm-crypt/System configuration#crypttab).

For the root filesystem, follow the instructions from Dm-crypt/TRIM support for SSD to add the right kernel parameter to the bootloader configuration.

Maximizing performance

Follow the tips in Maximizing performance#Storage devices to maximize the performance of your drives.

Security

Hdparm shows "frozen" state

Some motherboard BIOS' issue a "security freeze" command to attached storage devices on initialization. Likewise some SSD (and HDD) BIOS' are set to "security freeze" in the factory already. Both result in the device's password security settings to be set to frozen, as shown in below output:

:~# hdparm -I /dev/sda
Security: 
 	Master password revision code = 65534
 		supported
 	not	enabled
 	not	locked
 		frozen
 	not	expired: security count
 		supported: enhanced erase
 	4min for SECURITY ERASE UNIT. 2min for ENHANCED SECURITY ERASE UNIT.

Operations like formatting the device or installing operating systems are not affected by the "security freeze".

The above output shows the device is not locked by a HDD-password on boot and the frozen state safeguards the device against malwares which may try to lock it by setting a password to it at runtime.

If you intend to set a password to a "frozen" device yourself, a motherboard BIOS with support for it is required. A lot of notebooks have support, because it is required for hardware encryption, but support may not be trivial for a desktop/server board. For the Intel DH67CL/BL motherboard, for example, the motherboard has to be set to "maintenance mode" by a physical jumper to access the settings (see [5], [6]).

Warning: Do not try to change the above lock security settings with hdparm unless you know exactly what you are doing.

If you intend to erase the SSD, see Securely wipe disk#hdparm and #SSD memory cell clearing below.

SSD memory cell clearing

On occasion, users may wish to completely reset an SSD's cells to the same virgin state they were at the time the device was installed thus restoring it to its factory default write performance. Write performance is known to degrade over time even on SSDs with native TRIM support. TRIM only safeguards against file deletes, not replacements such as an incremental save.

The reset is easily accomplished in a three step procedure denoted on the SSD memory cell clearing wiki article. If the reason for the reset is to wipe data, you may not want to rely on the SSD bios to perform it securely. See Securely wipe disk#Flash memory for further information and examples to perform a wipe.

Hardware encryption

As noted in #Hdparm shows frozen state setting a password for a storage device (SSD/HDD) in the BIOS may also initialize the hardware encryption of devices supporting it. If the device also conforms to the OPAL standard, this may also be achieved without a respective BIOS feature to set the passphrase, see Self-Encrypting Drives.

Troubleshooting

It is possible that the issue you are encountering is a firmware bug which is not Linux specific, so before trying to troubleshoot an issue affecting the SSD device, you should first check if updates are available for:

Even if it is a firmware bug it might be possible to avoid it, so if there are no updates to the firmware or you hesitant on updating firmware then the following might help.

Resolving NCQ errors

Some SSDs and SATA chipsets do not work properly with Linux Native Command Queueing (NCQ). The tell-tale dmesg errors look like this:

[ 9.115544] ata9: exception Emask 0x0 SAct 0xf SErr 0x0 action 0x10 frozen
[ 9.115550] ata9.00: failed command: READ FPDMA QUEUED
[ 9.115556] ata9.00: cmd 60/04:00:d4:82:85/00:00:1f:00:00/40 tag 0 ncq 2048 in
[ 9.115557] res 40/00:18:d3:82:85/00:00:1f:00:00/40 Emask 0x4 (timeout)

To disable NCQ on boot, add libata.force=noncq to the kernel command line in the bootloader configuration. To disable NCQ only for disk 0 on port 1 use: libata.force=1.00:noncq

Alternatively, you may disable NCQ for a specific drive without rebooting via sysfs:

# echo 1 > /sys/block/sdX/device/queue_depth

If this (and also updating the firmware) does not resolves the problem or cause other issues, then file a bug report.

Resolving SATA power management related errors

Some SSDs (e.g. Transcend MTS400) are failing when SATA Active Link Power Management, ALPM, is enabled. ALPM is disabled by default and enabled by a power saving daemon (e.g. TLP, Laptop Mode Tools).

If you starting to encounter SATA related errors when using such daemon then you should try to disable ALPM by setting its state to max_performance for both battery and AC powered profiles.

See also