Difference between revisions of "Solid state drive"

From ArchWiki
Jump to: navigation, search
(Pre-Purchase Considerations: add accuracy template per IRC discussion)
m (fixed typo)
 
(247 intermediate revisions by 55 users not shown)
Line 1: Line 1:
 
[[Category:Storage]]
 
[[Category:Storage]]
[[it:Solid State Drives]]
+
[[it:Solid state drive]]
[[ja:Solid State Drives]]
+
[[ja:ソリッドステートドライブ]]
[[ru:Solid State Drives]]
+
[[ru:Solid state drive]]
[[zh-CN:Solid State Drives]]
+
[[zh-hans:Solid state drive]]
[[zh-TW:Solid State Drives]]
+
[[zh-hant:Solid state drive]]
 
{{Related articles start}}
 
{{Related articles start}}
{{Related|SSD Benchmarking}}
+
{{Related|Solid state drive/NVMe}}
{{Related|SSD memory cell clearing}}
+
{{Related|Solid state drive/Memory cell clearing}}
{{Related|profile-sync-daemon}}
+
{{Related|Benchmarking/Data storage devices}}
 +
{{Related|Improving performance#Storage devices}}
 +
{{Related|Flashcache}}
 
{{Related articles end}}
 
{{Related articles end}}
 +
This article covers special topics for operating [[Wikipedia:Solid-state drive|solid state drives]] (SSDs) and other flash-memory based storage devices. If you want to partition an SSD for a specific purpose, it may be useful to consider the [[Wikipedia:List of file systems#File systems optimized for flash memory, solid state media|List of file systems optimized for flash memory]]. For general usage, you should simply choose your preferred [[filesystem]].
  
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 ==
  
{{Note|This article is targeted at users running Linux, but much of the content is also relevant to other operating systems like BSD, Mac OS X or Windows.}}
+
=== TRIM ===
  
== Overview ==
+
Most SSDs support the [[wikipedia:TRIM|ATA_TRIM command]] for sustained long-term performance and wear-leveling. A [https://www.techspot.com/review/737-ocz-vector-150-ssd/page9.html techspot article] shows performance benchmark examples of before and after filling an SSD with data.
  
=== Advantages over HDDs ===
+
As of Linux kernel version 3.8 onwards, support for TRIM was continually added for the different [[filesystems]]. See the following table for an indicative overview:
  
*Fast read speeds - 2-3x faster than modern desktop HDDs (7,200 RPM using SATA2 interface).
+
{| class="wikitable"
*Sustained read speeds - no decrease in read speed across the entirety of the device. HDD performance tapers off as the drive heads move from the outer edges to the center of HDD platters.
+
! File system !! Continuous TRIM <br> ({{ic|discard}} option) !! Periodic TRIM <br> (''fstrim'') !! References<br> and notes
*Minimal access time - approximately 100x faster than an HDD. For example, 0.1 ms (100 us) vs. 12-20 ms (12,000-20,000 us) for desktop HDDs.
+
|-
*High degree of reliability.
+
| [[Ext3]] || {{No}} || {{META Table cell|?}} ||
*No moving parts.
+
|-
*Minimal heat production.
+
| [[Ext4]] || {{Yes}} || {{Yes}} || [https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/filesystems/ext4.txt#n344]
*Minimal power consumption - fractions of a W at idle and 1-2 W while reading/writing vs. 10-30 W for a HDD depending on RPMs.
+
|-
*Light-weight - ideal for laptops.
+
| [[Btrfs]] || {{Yes}} || {{Yes}} ||
 +
|-
 +
| [[JFS]] || {{Yes}} || {{Yes}} || [https://www.phoronix.com/scan.php?page=news_item&px=MTE5ODY]
 +
|-
 +
| [[XFS]] || {{Yes}} || {{Yes}} || [http://xfs.org/index.php/FITRIM/discard]
 +
|-
 +
| [[F2FS]] || {{Yes}} || {{Yes}} ||
 +
|-
 +
| [[VFAT]] || {{Yes}} || {{Yes}} || ''fstrim'' is supported since kernel 4.19
 +
|-
 +
| [[NTFS-3G]] || {{No}} || {{Yes}} || since version 2015.3.14, [http://permalink.gmane.org/gmane.comp.file-systems.ntfs-3g.devel/1101]
 +
|}
  
=== Limitations ===
+
{{Warning|Users need to be certain that their SSD supports TRIM before attempting to use it. Data loss can occur otherwise!}}
  
*Per-storage cost (close to a dollar per GB, vs. around a dime or two per GB for rotating media).
+
To verify TRIM support, run:
*Capacity of marketed models is lower than that of HDDs.
 
*Large cells require different filesystem optimizations than rotating media. The flash translation layer hides the raw flash access which a modern OS could use to optimize access.
 
*Partitions and filesystems need some SSD-specific tuning. Page size and erase page size are not autodetected.
 
*Cells wear out. Consumer MLC cells at mature 50nm processes can handle 10000 writes each; 35nm generally handles 5000 writes, and 25nm 3000 (smaller being higher density and cheaper). If writes are properly spread out, are not too small, and align well with cells, this translates into a lifetime write volume for the SSD that is a multiple of its capacity. Daily write volumes have to be balanced against life expectancy. However, tests [http://techreport.com/review/25889/the-ssd-endurance-experiment-500tb-update][http://techreport.com/review/26523/the-ssd-endurance-experiment-casualties-on-the-way-to-a-petabyte][http://techreport.com/review/27436/the-ssd-endurance-experiment-two-freaking-petabytes] performed on recent hardware suggest that SSD wear is negligible, with the lifetime expectancy of SSDs comparable to those of HDDs even with artificially high write-volumes.
 
*Firmwares and controllers are complex. They occasionally have bugs. Modern ones consume power comparable with HDDs. They [https://lwn.net/Articles/353411/ implement] the equivalent of a log-structured filesystem with garbage collection. They translate SATA commands traditionally intended for rotating media. Some of them do on the fly compression. They spread out repeated writes across the entire area of the flash, to prevent wearing out some cells prematurely. They also coalesce writes together so that small writes are not amplified into as many erase cycles of large cells. Finally they move cells containing data so that the cell does not lose its contents over time.
 
*Performance can drop as the disk gets filled. Garbage collection is not universally well implemented, meaning freed space is not always collected into entirely free cells.
 
  
=== Pre-Purchase Considerations ===
+
# lsblk --discard
  
{{Accuracy|Would be nice to get some sources here, particularly on the "75% occupancy"}}
+
And check the values of DISC-GRAN (discard granularity) and DISC-MAX (discard max bytes) columns. Non-zero values indicate TRIM support.
  
There are several key features to look for prior to purchasing a contemporary SSD.
+
Alternatively, [[install]] {{Pkg|hdparm}} package and run:
*Native [[wikipedia:TRIM|TRIM]] support is a vital feature that both prolongs SSD lifetime and reduces loss of performance for write operations over time.
 
*Buying the right sized SSD is key. As with all filesystems, target <75 % occupancy for all SSD partitions to ensure efficient use by the kernel.
 
  
== Tips for Maximizing SSD Performance ==
+
{{hc|# hdparm -I /dev/sda {{!}} grep TRIM|
=== Partition alignment ===
+
        *    Data Set Management TRIM supported (limit 1 block)
 +
}}
  
See [[Partitioning#Partition alignment]].
+
{{Note|There are different types of TRIM support defined by the specification. Hence, the output may differ depending what the drive supports. See [[Wikipedia:TRIM#ATA]] for more information.}}
  
=== TRIM ===
+
==== Periodic TRIM ====
  
Most SSDs support the [[wikipedia:TRIM|ATA_TRIM command]] for sustained long-term performance and wear-leveling. For more including some before and after benchmark, see [https://sites.google.com/site/lightrush/random-1/howtoconfigureext4toenabletrimforssdsonubuntu this] tutorial.
+
The {{Pkg|util-linux}} package provides {{ic|fstrim.service}} and {{ic|fstrim.timer}} [[systemd]] unit files. [[Enabling]] the timer will activate the service weekly. The service executes {{man|8|fstrim}} on all mounted filesystems on devices that support the ''discard'' operation.
  
As of linux kernel version 3.7, the following filesystems support TRIM: [[Ext4]], [[Btrfs]], [[JFS]], VFAT, [[XFS]].
+
The timer relies on the timestamp of {{ic|/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.
  
VFAT only supports TRIM by Mount Flag 'discard', not by fstrim.
+
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.
  
The [[#Choice of Filesystem|Choice of Filesystem]] section of this article offers more details.
+
==== Continuous TRIM ====
  
==== Verify TRIM Support ====
+
{{Note|There is no need to enable continuous TRIM if you run {{ic|fstrim}} periodically. If you want to use TRIM, use either periodic TRIM or continuous TRIM.}}
  
# hdparm -I /dev/sda | grep TRIM
+
Instead of issuing TRIM commands once in a while (by default once a week if using {{ic|fstrim.timer}}), it is also possible to issue TRIM commands each time files are deleted instead. The latter is known as the continuous TRIM.
        *    Data Set Management TRIM supported (limit 1 block)
 
  
Note that there are different types of TRIM support defined by the specification. Hence, the output may differ depending what the drive supports. See [[wikipedia:TRIM#ATA]] for more information.
+
{{Warning|Before [[Wikipedia:Serial ATA#SATA revision 3.1|SATA 3.1]] all TRIM commands were non-queued, 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://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/ata/libata-core.c#n4522 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]. In such case, depending on the device, the system may be forced to send non-queued TRIM commands the SSD instead of queued TRIM. See [[Wikipedia:Trim (computing)#Shortcomings]] for details.}}
  
==== Enable TRIM by Mount Flags ====
+
{{Note|Continuous TRIM is not the most preferred way to issue TRIM commands among the Linux community. For example, Ubuntu enables periodic TRIM by default [https://askubuntu.com/questions/1034169/is-trim-enabled-on-my-ubuntu-18-04-installation], Debian does not recommend using continuous TRIM [https://wiki.debian.org/SSDOptimization#Mounting_SSD_filesystems] and Red Hat recommends using periodic TRIM over using continuous TRIM if feasible. [https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Storage_Administration_Guide/ch02s04.html]}}
  
Using this flag in one's {{ic|/etc/fstab}} enables the benefits of the TRIM command stated above.
+
Using the {{ic|discard}} option for a mount in {{ic|/etc/fstab}} enables continuous TRIM in device operations:
  
  /dev/sda1  /       ext4   defaults,noatime,'''discard'''  0  1
+
  /dev/sda1  /           ext4 defaults,'''discard'''  0  1
/dev/sda2  /home  ext4  defaults,noatime,'''discard'''  0  2
 
  
{{Note|
+
{{Note|1=Specifying the discard mount option in {{ic|/etc/fstab}} does not work with an XFS {{ic|/}} partition. According to [https://bbs.archlinux.org/viewtopic.php?id=143254 this thread], it has to be set using the {{ic|1=rootflags=discard}} [[kernel parameter]].}}
* TRIM is not by default activated when using block-device encryption on a SSD; for more information see [[Dm-crypt/Specialties#Discard.2FTRIM_support_for_solid_state_drives_.28SSD.29|Dm-crypt/TRIM support for SSD]].
 
* There is no need for the {{ic|discard}} flag if you run {{ic|fstrim}} periodically.
 
* Using the {{ic|discard}} flag for an ext3 root partition will result in it being mounted read-only.}}
 
{{Warning|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!}}
 
  
==== Apply TRIM via cron ====
+
On the ext4 filesystem, the {{ic|discard}} flag can also be set as a [[Access_Control_Lists#Enabling_ACL|default mount option]] using ''tune2fs'':
  
{{Note|This method does not work for VFAT filesystems.}}
+
  # tune2fs -o discard /dev/sd'''XY'''
Enabling TRIM on supported SSDs is definitely recommended.  But sometimes it may cause some SSDs to [https://patrick-nagel.net/blog/archives/337 perform slowly] during deletion of files.  If this is the case, one may choose to use fstrim as an alternative.
 
  # fstrim -v /
 
The partition for which fstrim is to be applied must be mounted, and must be indicated by the mount point. 
 
 
 
If this method seems like a better alternative, it might be a good idea to have this run from time to time using cron.  To have this run daily, the default cron package ({{pkg|cronie}}) includes an anacron implementation which, by default, is set up for hourly, daily, weekly, and monthly jobs.  Note that [[Cron#Activation_and_autostart|cronie systemd service]] is not enabled by default in new Arch installs. To add to the list of daily cron tasks, simply create a script that takes care of the desired actions and put it in {{ic|/etc/cron.daily}}, {{ic|/etc/cron.weekly}}, etc.  Appropriate nice and ionice values are recommended if this method is chosen.  If implemented, remove the {{ic|discard}} option from {{ic|/etc/fstab}}.
 
  
{{Note|Use the {{ic|discard}} mount option as a first choice. This method should be considered second to the normal implementation of TRIM.}}
+
Using the default mount options instead of an entry in {{ic|/etc/fstab}} is particularly useful for external drives, because such partition will be mounted with the default options also on other machines. This way, there is no need to edit {{ic|/etc/fstab}} on every machine.
  
==== Apply TRIM via a systemd service====
+
{{Note|The default mount options are not listed in {{ic|/proc/mounts}}.}}
  
The {{Pkg|util-linux}} package provides {{ic|fstrim.service}} and {{ic|fstrim.timer}} [[systemd]] unit files. [[systemd#Using units|Enabling]] the timer will activate the service weekly, which will then trim all mounted filesystems on devices that support the discard operation.
+
==== Trim an entire device ====
  
==== Enable TRIM With tune2fs (Discouraged) ====
+
If you want to trim your entire SSD at once, e.g. for a new install, or you want to sell your SSD, you can use the blkdiscard command, which will instantly discard all blocks on a device.
  
One can set the trim flag statically with tune2fs:
+
{{Warning|all data on the device will be lost!}}
  
  # tune2fs -o discard /dev/sd'''XY'''
+
  # blkdiscard /dev/sd''X''
  
{{Warning|This method will cause the {{ic|discard}} option to [https://bbs.archlinux.org/viewtopic.php?id&#61;137314 not show up] with {{ic|mount}}.}}
+
==== LVM ====
 
 
==== Enable TRIM for LVM ====
 
  
 
Change the value of {{ic|issue_discards}} option from 0 to 1 in {{ic|/etc/lvm/lvm.conf}}.
 
Change the value of {{ic|issue_discards}} option from 0 to 1 in {{ic|/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 {{ic|man lvm.conf}} and/or inline comments in {{ic|/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.}}
+
{{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|5|lvm.conf}} and/or inline comments in {{ic|/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.}}
  
==== Enable TRIM for dm-crypt ====
+
==== 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/Specialties#Discard.2FTRIM_support_for_solid_state_drives_.28SSD.29|Dm-crypt/TRIM support for SSD]] for more information.}}
+
{{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/Specialties#Discard/TRIM support for solid state drives (SSD)]] for more information.}}
  
For non-root filesystems, configure {{ic|/etc/crypttab}} to include {{ic|discard}} in the list of options for encrypted block devices located on a SSD (see [[Dm-crypt/System configuration#crypttab]]).
+
For non-root filesystems, configure {{ic|/etc/crypttab}} to include {{ic|discard}} in the list of options for encrypted block devices located on an SSD (see [[dm-crypt/System configuration#crypttab]]).
  
For the root filesystem, follow the instructions from [[Dm-crypt/Specialties#Discard.2FTRIM_support_for_solid_state_drives_.28SSD.29|Dm-crypt/TRIM support for SSD]] to add the right kernel parameter to the bootloader configuration.
+
For the root filesystem, follow the instructions from [[dm-crypt/Specialties#Discard/TRIM support for solid state drives (SSD)]] to add the right kernel parameter to the bootloader configuration.
  
=== I/O Scheduler ===
+
=== Maximizing performance ===
  
Consider switching from the default [[wikipedia:CFQ|CFQ]] scheduler (Completely Fair Queuing) to [[wikipedia:NOOP_scheduler|NOOP]] or [[wikipedia:Deadline_scheduler|Deadline]]. The latter two offer performance boosts for SSDs. The NOOP scheduler, for example, implements a simple queue for all incoming I/O requests, without re-ordering and grouping the ones that are physically closer on the disk. On SSDs seek times are identical for all sectors, thus invalidating the need to re-order I/O queues based on them.
+
Follow the tips in [[Improving performance#Storage devices]] to maximize the performance of your drives.
  
The CFQ scheduler is enabled by default on Arch. Verify this by viewing the contents {{ic|/sys/block/sd'''X'''/queue/scheduler}}:
+
=== Security ===
  
{{hc|$ cat /sys/block/sd'''X'''/queue/scheduler|
+
==== Hdparm shows "frozen" state ====
noop deadline [cfq]
 
}}
 
 
 
The scheduler currently in use is denoted from the available schedulers by the brackets.
 
 
 
Users can change this on the fly without the need to reboot with:
 
 
 
# echo noop > /sys/block/sd'''X'''/queue/scheduler
 
 
 
or:
 
 
 
$ sudo tee /sys/block/sd'''X'''/queue/scheduler <<< noop
 
 
 
This method is non-persistent (eg. change will be lost upon rebooting).  Confirm the change was made by viewing the contents of the file again and ensuring "noop" is between brackets.
 
 
 
==== Kernel parameter (for a single device) ====
 
 
 
If the sole storage device in the system is an SSD, consider setting the I/O scheduler for the entire system via the {{ic|1=elevator=noop}} [[Kernel parameters|kernel parameter]].
 
 
 
==== Using udev for one device or HDD/SSD mixed environment ====
 
 
 
Though the above will undoubtedly work, it is probably considered a reliable workaround.  Ergo, it would be preferred to use the system that is responsible for the devices in the first place to implement the scheduler.  In this case it is udev, and to do this, all one needs is a simple [[udev]] rule.
 
 
 
To do this, create the following:
 
 
 
{{hc|/etc/udev/rules.d/60-schedulers.rules|<nowiki>
 
# set deadline scheduler for non-rotating disks
 
ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="0", ATTR{queue/scheduler}="deadline"
 
 
 
</nowiki>}}
 
 
 
Of course, set Deadline/CFQ to the desired schedulers.  Changes should occur upon next boot.  To check success of the new rule:
 
 
 
$ cat /sys/block/sd'''X'''/queue/scheduler  # where '''X''' is the device in question
 
 
 
{{Note|In the example sixty is chosen because that is the number udev uses for its own persistent naming rules. Thus, it would seem that block devices are at this point able to be modified and this is a safe position for this particular rule. But the rule can be named anything so long as it ends in {{ic|.rules}}.)}}
 
 
 
=== Swap Space on SSDs ===
 
 
 
One can place a swap partition on an SSD. Most modern desktops with an excess of 2 Gigs of memory rarely use swap at all. The notable exception is systems which make use of the hibernate feature.
 
 
 
A recommended tweak for SSDs using a swap partition is to reduce the [[Swap#Swappiness|swappiness]] of the system to some very low value (for example {{ic|1}}), and thus avoiding writes to swap.
 
 
 
=== 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:  
 
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:  
  
{{hc|head=:~# hdparm -I /dev/sda |output=
+
{{hc|head=# hdparm -I /dev/sda |output=
 
  Security:  
 
  Security:  
 
  Master password revision code = 65534
 
  Master password revision code = 65534
Line 181: Line 131:
 
  not expired: security count
 
  not expired: security count
 
  supported: enhanced erase
 
  supported: enhanced erase
  4min for SECURITY ERASE UNIT. 2min for ENHANCED SECURITY ERASE UNIT. }}
+
  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".  
 
Operations like formatting the device or installing operating systems are not affected by the "security freeze".  
Line 187: Line 138:
 
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.  
 
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 [[Wikipedia:Hardware-based_full_disk_encryption|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 [http://sstahlman.blogspot.in/2014/07/hardware-fde-with-intel-ssd-330-on.html?showComment=1411193181867#c4579383928221016762], [https://communities.intel.com/message/251978#251978]).  
+
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 [[Wikipedia:Hardware-based_full_disk_encryption|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 [https://sstahlman.blogspot.in/2014/07/hardware-fde-with-intel-ssd-330-on.html?showComment=1411193181867#c4579383928221016762], [https://communities.intel.com/message/251978#251978]).  
  
 
{{Warning|Do not try to change the above '''lock''' security settings with {{ic|hdparm}} unless you know exactly what you are doing.}}
 
{{Warning|Do not try to change the above '''lock''' security settings with {{ic|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]].
+
If you intend to erase the SSD, see [[Securely wipe disk#hdparm]] and [[#SSD memory cell clearing]] below.
  
=== SSD Memory Cell Clearing ===
+
==== 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 [http://www.anandtech.com/storage/showdoc.aspx?i=3531&p=8 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.
+
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 [https://www.anandtech.com/show/2738/8 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.
 
 
 
=== 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
+
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.
[ 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)
 
  
These may be resolved by one of the following methods:
+
==== Hardware encryption ====
  
# Update the firmware on the SSD. See [[SSD#Firmware_Updates]].
+
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]].
# Update the BIOS/UEFI on the motherboard. See [[Flashing_BIOS_from_Linux]].
 
# Disable NCQ on boot. Add {{ic|1=libata.force=noncq}} to the kernel command line in the [[Bootloader]] configuration.
 
  
If these do not resolve the problem or cause other issues, [[Reporting_Bug_Guidelines | file a bug report]].
+
== Troubleshooting ==
  
== Tips for minimizing disk reads/writes ==
+
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:
  
An overarching theme for SSD usage should be 'simplicity' in terms of locating high-read/write operations either in RAM (Random Access Memory) or on a physical HDD rather than on an SSD. Doing so will add longevity to an SSD. This is primarily due to the large erase block size (512 KiB in some cases); a lot of small writes result in huge effective writes.
+
* The [[#Firmware|SSD's firmware]]
 +
* The [[Flashing_BIOS_from_Linux|motherboard's BIOS/UEFI firmware]]
  
{{Note|A 32GB SSD with a mediocre 10x write amplification factor, a standard 10000 write/erase cycle, and '''10GB of data written per day''', would get an '''8 years life expectancy'''. It gets better with bigger SSDs and modern controllers with less write amplification. Also compare [http://techreport.com/review/25889/the-ssd-endurance-experiment-500tb-update] when considering whether any particular strategy to limit disk writes is actually needed.}}
+
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.
  
Use {{Pkg|iotop}} and sort by disk writes to see how much and how frequently are programs writing to the disk.
+
=== Resolving NCQ errors ===
  
{{Tip|''iotop'' can be run in batch mode instead of the default interactive mode using the {{ic|-b}} option. {{ic|-o}} is used to show only processes actually doing I/O, and {{ic|-qqq}} is to suppress column names and I/O summary. See {{ic|man iotop}} for more options.
+
Some SSDs and SATA chipsets do not work properly with Linux Native Command Queueing (NCQ). The tell-tale dmesg errors look like this:
# iotop -boqqq
 
}}
 
  
=== Intelligent partition scheme ===
+
[ 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)
  
*For systems with both an SSD and an HDD, consider relocating the {{ic|/var}} partition to a magnetic disc on the system rather than on the SSD itself to avoid read/write wear.
+
To disable NCQ on boot, add {{ic|1=libata.force=noncq}} to the kernel command line in the [[bootloader]] configuration. To disable NCQ only for disk 0 on port 9 use: {{ic|1=libata.force=9.00:noncq}}
  
=== noatime mount option ===
+
Alternatively, you may disable NCQ for a specific drive without rebooting via sysfs:
  
{{Merge|fstab#atime options|This should be described only in one place, just link to [[fstab]] afterwards.}}
+
# echo 1 > /sys/block/sdX/device/queue_depth
  
Using this flag in one's {{ic|/etc/fstab}} halts the logging of read accesses to the file system via an update to the atime information associated with the file.  The importance of the {{ic|noatime}} setting is that it eliminates the need by the system to make writes to the file system for files which are simply being read.  Since writes can be somewhat expensive as mentioned in previous section, this can result in measurable performance gains.
+
If this (and also updating the firmware) does not resolves the problem or cause other issues, then [[Reporting bug guidelines|file a bug report]].
  
{{Note|The write time information to a file will continue to be updated anytime the file is written to with this option enabled.}}
+
=== Resolving SATA power management related errors ===
  
/dev/sda1  /      ext4  defaults,'''noatime'''  0  1
+
Some SSDs (e.g. Transcend MTS400) are failing when SATA Active Link Power Management, [[wikipedia:Aggressive Link Power Management|ALPM]], is enabled.
/dev/sda2  /home  ext4  defaults,'''noatime'''  0  2
+
ALPM is disabled by default and enabled by a power saving daemon (e.g. [[TLP]], [[Laptop Mode Tools]]).
  
{{Note|This setting will cause issues with some programs such as [[Mutt]], as the access time of the file will eventually be previous than the modification time, which would make no sense. Using the {{ic|relatime}} option instead of {{ic|noatime}} will ensure that the atime field will never be prior to the last modification time of a file.  Alternatively, using the maildir storage format also solves this mutt issue.}}
+
If you are starting to encounter SATA related errors when using such a daemon, you should try to disable ALPM by setting its state to {{ic|max_performance}} for both battery and AC powered profiles.
  
=== Locate frequently used files to RAM ===
+
== Firmware ==
  
==== Browser profiles ====
+
=== ADATA ===
  
One can ''easily'' mount browser profile(s) such as chromium, firefox, opera, etc. into RAM via tmpfs and also use rsync to keep them synced with HDD-based backups. In addition to the obvious speed enhancements, users will also save read/write cycles on their SSD by doing so.
+
ADATA has a utility available for Linux (i686) on their [http://www.adata.com.tw/index.php?action=ss_main&page=ss_content_driver&lan=en support page]. The link to latest firmware will appear after selecting the model. The latest Linux update utility is packed with firmware and needs to be run as root. One may need to set correct permissions for binary file first.
  
The AUR contains several packages to automate this process, for example {{AUR|profile-sync-daemon}}.
+
=== Crucial ===
  
==== Others ====
+
Crucial provides an option for updating the firmware with an ISO image. These images can be found after selecting the product on their [http://www.crucial.com/usa/en/support-ssd SSD support page] and downloading the "Manual Boot File." 
  
For the same reasons a browser's profile can be relocated to RAM, so can highly used directories such as {{ic|/srv/http}} (if running a web server). A sister project to {{AUR|profile-sync-daemon}} is {{AUR|anything-sync-daemon}}, which allows users to define '''any''' directory to sync to RAM using the same underlying logic and safe guards.
+
{{Note|ISO images provided by Crucial do not seem to be hybrid. If you will use just the {{ic|dd}} command to copy the image to some device, the [[MBR]] will not be present, making such device unbootable.}}
  
=== Compiling in tmpfs ===
+
Owners of an M4 Crucial model, may check if a firmware upgrade is needed with {{ic|smartctl}}.
  
Intentionally compiling in [[tmpfs]] is great to minimize disk reads/writes. For more information, refer to [[Makepkg#Improving_compile_times]].
+
{{hc|$ smartctl --all /dev/sd'''X'''|
 +
==> WARNING: This drive may hang after 5184 hours of power-on time:
 +
http://www.tomshardware.com/news/Crucial-m4-Firmware-BSOD,14544.html
 +
See the following web pages for firmware updates:
 +
http://www.crucial.com/support/firmware.aspx
 +
http://www.micron.com/products/solid-state-storage/client-ssd#software
 +
}}
  
=== Disabling journaling on the filesystem ===
+
Users seeing this warning are advised to backup all sensible data and '''consider upgrading immediately'''. Check [http://www.rojtberg.net/1008/updating-crucial-mx100-firmware-with-ubuntu/ this instructions] to update Crucial MX100 firmware by using the ISO image and Grub.
  
Using a journaling filesystem such as ext4 on an SSD '''without''' a journal is an option to decrease read/writes. The obvious drawback of using a filesystem with journaling disabled is data loss as a result of an ungraceful dismount (i.e. post power failure, kernel lockup, etc.). With modern SSDs, [http://tytso.livejournal.com/61830.html Ted Tso] advocates that journaling can be enabled with minimal extraneous read/write cycles under most circumstances:
+
=== Intel ===
  
'''Amount of data written (in megabytes) on an ext4 file system mounted with {{ic|noatime}}.'''
+
Intel has a Linux live system based [https://downloadcenter.intel.com/download/18363 Firmware Update Tool] for operating systems that are not compatible with its [https://downloadcenter.intel.com/download/18455 Intel® Solid-State Drive Toolbox] software.
  
{| class="wikitable"
+
=== Kingston ===
! operation !! journal !! w/o journal !! percent change
 
|-
 
!git clone
 
|367.0
 
|353.0
 
|3.81 %
 
|-
 
!make
 
|207.6
 
|199.4
 
|3.95 %
 
|-
 
!make clean
 
|6.45
 
|3.73
 
|42.17 %
 
|}
 
  
''"What the results show is that metadata-heavy workloads, such as make clean, do result in almost twice the amount data written to disk. This is to be expected, since all changes to metadata blocks are first written to the journal and the journal transaction committed before the metadata is written to their final location on disk. However, for more common workloads where we are writing data as well as modifying filesystem metadata blocks, the difference is much smaller."''
+
KFU tool is available on the AUR for the Sandforce based drives, {{AUR|kingston_fw_updater}}.
  
{{Note|The make clean example from the table above typifies the importance of intentionally doing compiling in tmpfs as recommended in the [[#Compiling in tmpfs|preceding section]] of this article!}}
+
=== Mushkin ===
  
== Choice of Filesystem ==
+
The lesser known Mushkin brand solid state drives also use Sandforce controllers, and have a Linux utility (nearly identical to Kingston's) to update the firmware.
  
=== Btrfs ===
+
=== OCZ ===
  
[[wikipedia:Btrfs|Btrfs]] support has been included with the mainline 2.6.29 release of the Linux kernel. Some feel that it is not mature enough for production use while there are also early adopters of this potential successor to ext4. Users are encouraged to read the [[Btrfs]] article for more info.
+
OCZ has a [https://www.ocz.com/us/download/clout Command Line Online Update Tool (CLOUT)] available for Linux. The AUR provides {{AUR|ocz-ssd-utility}}, {{AUR|ocztoolbox}} and {{AUR|oczclout}}.
  
=== Ext4 ===
+
=== Samsung ===
  
[[wikipedia:Ext4|Ext4]] is another filesystem that has support for SSD. It is considered as stable since 2.6.28 and is mature enough for daily use. ext4 users must explicitly enable the TRIM command support using the {{ic|discard}} mount option in [[fstab]] (or with {{ic|tune2fs -o discard /dev/sdaX}}).
+
Samsung notes that update methods other than using their Magician Software are "not supported," but it is possible. The Magician Software can be used to make a USB drive bootable with the firmware update. Samsung provides pre-made [https://www.samsung.com/semiconductor/minisite/ssd/download/tools.html bootable ISO images] that can be used to update the firmware. Another option is to use Samsung's {{AUR|samsung_magician-consumer-ssd}}, which is available in the AUR. Magician only supports Samsung-branded SSDs; those manufactured by Samsung for OEMs (e.g., Lenovo) are not supported.
See the [http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=Documentation/filesystems/ext4.txt official in kernel tree documentation] for further information on ext4.
 
  
=== XFS ===
+
{{Note|Samsung does not make it obvious at all that they actually provide these. They seem to have 4 different firmware update pages, and each references different ways of doing things.}}
  
Many users do not realize that in addition to ext4 and btrfs, [[wikipedia:XFS|XFS]] has TRIM support as well.  This can be enabled in the usual ways.  That is, the choice may be made of either using the discard option mentioned above, or by using the fstrim command.  More information can be found on the [http://xfs.org/index.php/FITRIM/discard XFS wiki].
+
Users preferring to run the firmware update from a live USB created under Linux (without using Samsung's "Magician" software under Microsoft Windows) can refer to [http://fomori.org/blog/?p=933 this post] for reference.
  
=== JFS ===
+
==== Native upgrade ====
  
As of Linux kernel version 3.7, proper TRIM support has been added.  So far, there is not a great wealth of information of the topic but it has certainly been picked up by [http://www.phoronix.com/scan.php?page=news_item&px=MTE5ODY Linux news sites.] It is apparent that it can be enabled via the {{ic|discard}} mount option, or by using the method of batch TRIMs with fstrim.
+
{{Style|Assumes use of [[udisks]]; loop mounts can be done directly via [[mount]]}}
  
=== Other filesystems ===
+
Alternatively, the firmware can be upgraded natively, without making a bootable USB stick, as shown below.
  
There are other filesystems specifically [[wikipedia:List_of_flash_file_systems#File_systems_optimized_for_flash_memory.2C_solid_state_media|designed for SSD]], for example [[F2fs]].
+
First visit the [https://www.samsung.com/semiconductor/minisite/ssd/download/tools.html Samsung downloads page] and download the latest firmware for Windows, which is available as a disk image. In the following, {{ic|Samsung_SSD_840_EVO_EXT0DB6Q.iso}} is used as an example file name, adjust it accordingly.
  
== Firmware Updates ==
+
Setup the disk image:
  
=== ADATA ===
+
$ udisksctl loop-setup -r -f Samsung_SSD_840_EVO_EXT0DB6Q.iso
  
ADATA has a utility available for Linux (i686) on their support page [http://www.adata.com.tw/index.php?action=ss_main&page=ss_content_driver&lan=en here]. The link to latest firmware will appear after selecting the model.  The latest Linux update utility is packed with firmware and needs to be run as root. One may need to set correct permissions for binary file first.
+
This will make the ISO available as a loop device, and display the device path. Assuming it was {{ic|/dev/loop0}}:
  
=== Crucial ===
+
$ udisksctl mount -b /dev/loop0
  
Crucial provides an option for updating the firmware with an ISO image. These images can be found after selecting the product [http://www.crucial.com/usa/en/support-ssd here] and downloading the "Manual Boot File."  Owners of an M4 Crucial model, may check if a firmware upgrade is needed with {{ic|smartctl}}.
+
Get the contents of the disk:
  
{{hc|$ smartctl --all /dev/sd'''X'''|
+
$ mkdir Samsung_SSD_840_EVO_EXT0DB6Q
==> WARNING: This drive may hang after 5184 hours of power-on time:
+
$ cp -r /run/media/$USER/CDROM/isolinux/ Samsung_SSD_840_EVO_EXT0DB6Q
http://www.tomshardware.com/news/Crucial-m4-Firmware-BSOD,14544.html
 
See the following web pages for firmware updates:
 
http://www.crucial.com/support/firmware.aspx
 
http://www.micron.com/products/solid-state-storage/client-ssd#software
 
}}
 
  
Users seeing this warning are advised to backup all sensible data and '''consider upgrading immediately'''.
+
Unmount the iso:
  
=== Kingston ===
+
$ udisksctl unmount -b /dev/loop0
 +
$ cd Samsung_SSD_840_EVO_EXT0DB6Q/isolinux
  
Kingston has a Linux utility to update the firmware of Sandforce controller based drives:  [http://www.kingston.com/en/ssd SSD support page].  Click the images on the page to go to a support page for your SSD model.  Support specifically for, e.g. the SH100S3 SSD, can be found here:  [http://www.kingston.com/en/support/technical/downloads?product=sh100s3&filename=sh100_503fw_win support page].
+
There is a FreeDOS image here that contains the firmware. Mount the image as before:
  
=== Mushkin ===
+
$ udisksctl loop-setup -r -f btdsk.img
 +
$ udisksctl mount -b /dev/loop1
 +
$ cp -r /run/media/$USER/C04D-1342/ Samsung_SSD_840_EVO_EXT0DB6Q
 +
$ cd Samsung_SSD_840_EVO_EXT0DB6Q/C04D-1342/samsung
  
The lesser known Mushkin brand Solid State drives also use Sandforce controllers, and have a Linux utility (nearly identical to Kingston's) to update the firmware.
+
Get the disk number from magician:
  
=== OCZ ===
+
# magician -L
  
OCZ has a command line utility available for Linux (i686 and x86_64) on their forum [http://www.ocztechnology.com/ssd_tools/ here].
+
Assuming it was 0:
  
=== Samsung ===
+
# magician --disk 0 -F -p DSRD
  
Samsung notes that update methods other than by using their Magician Software is "not supported", but it is possible. Apparently the Magician Software can be used to make a USB drive bootable with the firmware update.  The easiest method, though, is to use the bootable ISO images they provide for updating the firmware. They can be grabbed from [http://www.samsung.com/global/business/semiconductor/samsungssd/downloads.html here].
+
Verify that the latest firmware has been installed:
  
{{Note|Samsung does not make it obvious at all that they actually provide these. They seem to have 4 different firmware update pages each referencing different ways of doing things.}}
+
# magician -L
  
Users preferring to run the firmware update from a live USB-Stick created under Linux (without using Samsung's "Magician" software under Microsoft Windows), see [http://fomori.org/blog/?p=933 this post] for reference.
+
Finally reboot.
  
 
=== SanDisk ===
 
=== SanDisk ===
  
SanDisk makes '''ISO firmware images''' to allow SSD firmware update on operating systems that are unsupported by their SanDisk SSD Toolkit. One must choose the firmware for the right ''SSD model'', as well as for the ''capacity'' that it has (e.g. 60GB, '''or''' 256GB). After burning the adequate ISO firmware image, simply restart the PC to boot with the newly created CD/DVD boot disk (may work from a USB stick).
+
SanDisk makes ISO firmware images to allow SSD firmware update on operating systems that are unsupported by their SanDisk SSD Toolkit.
 +
 
 +
One must choose the firmware for the correct ''SSD model'', '''and''' the correct ''capacity'' that it has (e.g. 60GB, '''or''' 256GB). After burning the ISO firmware image, simply restart the PC to boot with the newly created CD/DVD boot disk (may work from a USB stick).
  
 
The iso images just contain a linux kernel and an initrd. Extract them to {{ic|/boot}} partition and boot them with [[GRUB]] or [[Syslinux]] to update the firmware.
 
The iso images just contain a linux kernel and an initrd. Extract them to {{ic|/boot}} partition and boot them with [[GRUB]] or [[Syslinux]] to update the firmware.
  
I could not find a single page listing the firmware updates yet (site is a mess IMHO), but here are some relevant links:
+
See also:
 +
 
 +
SanDisk Extreme SSD [https://kb.sandisk.com/app/answers/detail/a_id/10127 Firmware Release notes] and [https://kb.sandisk.com/app/answers/detail/a_id/10476 Manual Firmware update version R211]
  
SanDisk Extreme SSD [http://kb.sandisk.com/app/answers/detail/a_id/10127 Firmware Release notes] and [http://kb.sandisk.com/app/answers/detail/a_id/10476 Manual Firmware update version R211]  
+
SanDisk Ultra SSD [https://kb.sandisk.com/app/answers/detail/a_id/10192 Firmware release notes] and [https://kb.sandisk.com/app/answers/detail/a_id/10477 Manual Firmware update version 365A13F0]
  
SanDisk Ultra SSD [http://kb.sandisk.com/app/answers/detail/a_id/10192 Firmware release notes] and [http://kb.sandisk.com/app/answers/detail/a_id/10477 Manual Firmware update version 365A13F0]
+
SanDisk Ultra+ SSD [https://kb.sandisk.com/app/answers/detail/a_id/12763 Firmware release notes] and [https://kb.sandisk.com/app/answers/detail/a_id/12762 Manual Firmware update version X2316RL] - use {{ic|smartctl -a /dev/sdX}} to determine if a "H2" or "HP" model is used.
  
 
== See also ==
 
== See also ==
  
* [http://www.reddit.com/r/archlinux/comments/rkwjm/what_should_i_keep_in_mind_when_installing_on_ssd/ Discussion on Reddit about installing Arch on an SSD]
+
* [https://www.reddit.com/r/archlinux/comments/rkwjm/what_should_i_keep_in_mind_when_installing_on_ssd/ Discussion on Reddit about installing Arch on an SSD]
* See the [[Flashcache]] article for advanced information on using solid-state with rotational drives for top performance.
 
* [http://lifehacker.com/5837769/make-sure-your-partitions-are-correctly-aligned-for-optimal-solid-state-drive-performance Speed Up Your SSD By Correctly Aligning Your Partitions] (using GParted)
 
 
* [http://permalink.gmane.org/gmane.comp.file-systems.btrfs/19446 Re: Varying Leafsize and Nodesize in Btrfs]
 
* [http://permalink.gmane.org/gmane.comp.file-systems.btrfs/19446 Re: Varying Leafsize and Nodesize in Btrfs]
 
* [http://thread.gmane.org/gmane.comp.file-systems.btrfs/19650/focus=19667 Re: SSD alignment and Btrfs sector size]
 
* [http://thread.gmane.org/gmane.comp.file-systems.btrfs/19650/focus=19667 Re: SSD alignment and Btrfs sector size]
* [http://forums.anandtech.com/showthread.php?t=2266113 Erase Block (Alignment) Misinformation?]
+
* [https://forums.anandtech.com/threads/erase-block-alignment-misinformation.2266113/ Erase Block (Alignment) Misinformation?]
* [http://superuser.com/questions/492084/is-alignment-to-erase-block-size-needed-for-modern-ssds Is alignment to erase block size needed for modern SSD's?]
+
* [https://superuser.com/questions/492084/is-alignment-to-erase-block-size-needed-for-modern-ssds Is alignment to erase block size needed for modern SSD's?]
 
* [http://thread.gmane.org/gmane.comp.file-systems.btrfs/15646 Btrfs support for efficient SSD operation (data blocks alignment)]
 
* [http://thread.gmane.org/gmane.comp.file-systems.btrfs/15646 Btrfs support for efficient SSD operation (data blocks alignment)]
* [http://serverfault.com/questions/356534/ssd-erase-block-size-lvm-pv-on-raw-device-alignment SSD, Erase Block Size & LVM: PV on raw device, Alignment]
+
* [https://serverfault.com/questions/356534/ssd-erase-block-size-lvm-pv-on-raw-device-alignment SSD, Erase Block Size & LVM: PV on raw device, Alignment]

Latest revision as of 17:21, 24 November 2018

This article covers special topics for operating solid state drives (SSDs) and other flash-memory based storage devices. If you want to partition an SSD for a specific purpose, it may be useful to consider the List of file systems optimized for flash memory. For general usage, you should simply choose your preferred filesystem.

Usage

TRIM

Most SSDs support the ATA_TRIM command for sustained long-term performance and wear-leveling. A techspot article shows performance benchmark examples of before and after filling an SSD with data.

As of Linux kernel version 3.8 onwards, support for TRIM was continually added for the different filesystems. See the following table for an indicative overview:

File system Continuous TRIM
(discard option)
Periodic TRIM
(fstrim)
References
and notes
Ext3 No ?
Ext4 Yes Yes [1]
Btrfs Yes Yes
JFS Yes Yes [2]
XFS Yes Yes [3]
F2FS Yes Yes
VFAT Yes Yes fstrim is supported since kernel 4.19
NTFS-3G No Yes since version 2015.3.14, [4]
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:

# lsblk --discard

And check the values of DISC-GRAN (discard granularity) and DISC-MAX (discard max bytes) columns. Non-zero values indicate TRIM support.

Alternatively, install hdparm package and 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 Wikipedia: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. The service executes fstrim(8) on 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

Note: There is no need to enable continuous TRIM if you run fstrim periodically. If you want to use TRIM, use either periodic TRIM or continuous TRIM.

Instead of issuing TRIM commands once in a while (by default once a week if using fstrim.timer), it is also possible to issue TRIM commands each time files are deleted instead. The latter is known as the continuous TRIM.

Warning: Before SATA 3.1 all TRIM commands were non-queued, 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. In such case, depending on the device, the system may be forced to send non-queued TRIM commands the SSD instead of queued TRIM. See Wikipedia:Trim (computing)#Shortcomings for details.
Note: Continuous TRIM is not the most preferred way to issue TRIM commands among the Linux community. For example, Ubuntu enables periodic TRIM by default [5], Debian does not recommend using continuous TRIM [6] and Red Hat recommends using periodic TRIM over using continuous TRIM if feasible. [7]

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

/dev/sda1  /           ext4  defaults,discard   0  1
Note: Specifying the discard mount option in /etc/fstab does not work with an XFS / partition. According to this thread, it has to be set using the rootflags=discard kernel parameter.

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 particularly useful for external drives, because such partition will be mounted with the default options also on other machines. This way, there is no need to edit /etc/fstab on every machine.

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

Trim an entire device

If you want to trim your entire SSD at once, e.g. for a new install, or you want to sell your SSD, you can use the blkdiscard command, which will instantly discard all blocks on a device.

Warning: all data on the device will be lost!
# blkdiscard /dev/sdX

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 lvm.conf(5) 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/Specialties#Discard/TRIM support for solid state drives (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 an SSD (see dm-crypt/System configuration#crypttab).

For the root filesystem, follow the instructions from dm-crypt/Specialties#Discard/TRIM support for solid state drives (SSD) to add the right kernel parameter to the bootloader configuration.

Maximizing performance

Follow the tips in Improving 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 [8], [9]).

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 9 use: libata.force=9.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 are starting to encounter SATA related errors when using such a daemon, you should try to disable ALPM by setting its state to max_performance for both battery and AC powered profiles.

Firmware

ADATA

ADATA has a utility available for Linux (i686) on their support page. The link to latest firmware will appear after selecting the model. The latest Linux update utility is packed with firmware and needs to be run as root. One may need to set correct permissions for binary file first.

Crucial

Crucial provides an option for updating the firmware with an ISO image. These images can be found after selecting the product on their SSD support page and downloading the "Manual Boot File."

Note: ISO images provided by Crucial do not seem to be hybrid. If you will use just the dd command to copy the image to some device, the MBR will not be present, making such device unbootable.

Owners of an M4 Crucial model, may check if a firmware upgrade is needed with smartctl.

$ smartctl --all /dev/sdX
==> WARNING: This drive may hang after 5184 hours of power-on time:
http://www.tomshardware.com/news/Crucial-m4-Firmware-BSOD,14544.html
See the following web pages for firmware updates:
http://www.crucial.com/support/firmware.aspx
http://www.micron.com/products/solid-state-storage/client-ssd#software

Users seeing this warning are advised to backup all sensible data and consider upgrading immediately. Check this instructions to update Crucial MX100 firmware by using the ISO image and Grub.

Intel

Intel has a Linux live system based Firmware Update Tool for operating systems that are not compatible with its Intel® Solid-State Drive Toolbox software.

Kingston

KFU tool is available on the AUR for the Sandforce based drives, kingston_fw_updaterAUR.

Mushkin

The lesser known Mushkin brand solid state drives also use Sandforce controllers, and have a Linux utility (nearly identical to Kingston's) to update the firmware.

OCZ

OCZ has a Command Line Online Update Tool (CLOUT) available for Linux. The AUR provides ocz-ssd-utilityAUR, ocztoolboxAUR and oczcloutAUR.

Samsung

Samsung notes that update methods other than using their Magician Software are "not supported," but it is possible. The Magician Software can be used to make a USB drive bootable with the firmware update. Samsung provides pre-made bootable ISO images that can be used to update the firmware. Another option is to use Samsung's samsung_magician-consumer-ssdAUR, which is available in the AUR. Magician only supports Samsung-branded SSDs; those manufactured by Samsung for OEMs (e.g., Lenovo) are not supported.

Note: Samsung does not make it obvious at all that they actually provide these. They seem to have 4 different firmware update pages, and each references different ways of doing things.

Users preferring to run the firmware update from a live USB created under Linux (without using Samsung's "Magician" software under Microsoft Windows) can refer to this post for reference.

Native upgrade

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

Reason: Assumes use of udisks; loop mounts can be done directly via mount (Discuss in Talk:Solid state drive#)

Alternatively, the firmware can be upgraded natively, without making a bootable USB stick, as shown below.

First visit the Samsung downloads page and download the latest firmware for Windows, which is available as a disk image. In the following, Samsung_SSD_840_EVO_EXT0DB6Q.iso is used as an example file name, adjust it accordingly.

Setup the disk image:

$ udisksctl loop-setup -r -f Samsung_SSD_840_EVO_EXT0DB6Q.iso

This will make the ISO available as a loop device, and display the device path. Assuming it was /dev/loop0:

$ udisksctl mount -b /dev/loop0

Get the contents of the disk:

$ mkdir Samsung_SSD_840_EVO_EXT0DB6Q
$ cp -r /run/media/$USER/CDROM/isolinux/ Samsung_SSD_840_EVO_EXT0DB6Q

Unmount the iso:

$ udisksctl unmount -b /dev/loop0
$ cd Samsung_SSD_840_EVO_EXT0DB6Q/isolinux

There is a FreeDOS image here that contains the firmware. Mount the image as before:

$ udisksctl loop-setup -r -f btdsk.img
$ udisksctl mount -b /dev/loop1
$ cp -r /run/media/$USER/C04D-1342/ Samsung_SSD_840_EVO_EXT0DB6Q
$ cd Samsung_SSD_840_EVO_EXT0DB6Q/C04D-1342/samsung

Get the disk number from magician:

# magician -L

Assuming it was 0:

# magician --disk 0 -F -p DSRD

Verify that the latest firmware has been installed:

# magician -L

Finally reboot.

SanDisk

SanDisk makes ISO firmware images to allow SSD firmware update on operating systems that are unsupported by their SanDisk SSD Toolkit.

One must choose the firmware for the correct SSD model, and the correct capacity that it has (e.g. 60GB, or 256GB). After burning the ISO firmware image, simply restart the PC to boot with the newly created CD/DVD boot disk (may work from a USB stick).

The iso images just contain a linux kernel and an initrd. Extract them to /boot partition and boot them with GRUB or Syslinux to update the firmware.

See also:

SanDisk Extreme SSD Firmware Release notes and Manual Firmware update version R211

SanDisk Ultra SSD Firmware release notes and Manual Firmware update version 365A13F0

SanDisk Ultra+ SSD Firmware release notes and Manual Firmware update version X2316RL - use smartctl -a /dev/sdX to determine if a "H2" or "HP" model is used.

See also