Difference between revisions of "Solid state drive"

From ArchWiki
Jump to navigation Jump to search
(Verify TRIM Support: Deterministic read data after TRIM is just one kind of Trim. See [https://wiki.archlinux.org/index.php?title=Talk:Solid_State_Drives&oldid=354620 discussion])
m (Crucial: update link to crucial firmware support)
Line 319: Line 319:
=== Crucial ===
=== Crucial ===
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/support/firmware.aspx here] and downloading the "Manual Boot File."  Owners of an M4 Crucial model, may check if a firmware upgrade is needed with {{ic|smartctl}}.
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}}.
{{hc|$ smartctl --all /dev/sd'''X'''|
{{hc|$ smartctl --all /dev/sd'''X'''|

Revision as of 23:18, 26 January 2015

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

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.

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.


Advantages over HDDs

  • Fast read speeds - 2-3x faster than modern desktop HDDs (7,200 RPM using SATA2 interface).
  • 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.
  • 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.
  • No moving parts.
  • Minimal heat production.
  • 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.


  • Per-storage cost (close to a dollar per GB, vs. around a dime or two per GB for rotating media).
  • 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 [1][2][3] 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 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

There are several key features to look for prior to purchasing a contemporary SSD.

  • Native 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

Partition alignment

See Partitioning#Partition alignment.


Most SSDs support the ATA_TRIM command for sustained long-term performance and wear-leveling. For more including some before and after benchmark, see this tutorial.

As of linux kernel version 3.7, the following filesystems support TRIM: Ext4, Btrfs, JFS, VFAT, XFS.

VFAT only supports TRIM by Mount Flag 'discard', not by fstrim.

The Choice of Filesystem section of this article offers more details.

Verify TRIM Support

# hdparm -I /dev/sda | grep TRIM
        *    Data Set Management TRIM supported (limit 1 block)

To have a better understanding of "limit 1 block" or "limit 8 block", see wikipedia:TRIM#ATA

Enable TRIM by Mount Flags

Using this flag in one's /etc/fstab enables the benefits of the TRIM command stated above.

/dev/sda1  /       ext4   defaults,noatime,discard   0  1
/dev/sda2  /home   ext4   defaults,noatime,discard   0  2
  • TRIM is not by default activated when using block-device encryption on a SSD; for more information see Dm-crypt/TRIM support for SSD.
  • There is no need for the discard flag if you run fstrim periodically.
  • Using the 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 discard flag. Data loss can occur otherwise!

Apply TRIM via cron

Note: This method does not work for VFAT filesystems.

Enabling TRIM on supported SSDs is definitely recommended. But sometimes it may cause some SSDs to 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 (cronie) includes an anacron implementation which, by default, is set up for hourly, daily, weekly, and monthly jobs. Note that 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 /etc/cron.daily, /etc/cron.weekly, etc. Appropriate nice and ionice values are recommended if this method is chosen. If implemented, remove the discard option from /etc/fstab.

Note: Use the discard mount option as a first choice. This method should be considered second to the normal implementation of TRIM.

Apply TRIM via a systemd service

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.

Enable TRIM With tune2fs (Discouraged)

One can set the trim flag statically with tune2fs:

# tune2fs -o discard /dev/sdXY
Warning: This method will cause the discard option to not show up with mount.

Enable TRIM for 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.

Enable TRIM for 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.

I/O Scheduler

Consider switching from the default CFQ scheduler (Completely Fair Queuing) to NOOP or 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.

The CFQ scheduler is enabled by default on Arch. Verify this by viewing the contents /sys/block/sdX/queue/scheduler:

$ cat /sys/block/sdX/queue/scheduler
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/sdX/queue/scheduler


$ sudo tee /sys/block/sdX/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 elevator=noop 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:

# set deadline scheduler for non-rotating disks
ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="0", ATTR{queue/scheduler}="deadline"

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/sdX/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 .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 swappiness of the system to some very low value (for example 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:

:~# hdparm -I /dev/sda
 	Master password revision code = 65534
 	not	enabled
 	not	locked
 	not	expired: security count
 		supported: enhanced erase

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 [4], [5]).

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 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.

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)

These may be resolved by one of the following methods:

  1. Update the firmware on the SSD. See SSD#Firmware_Updates.
  2. Update the BIOS/UEFI on the motherboard. See Flashing_BIOS_from_Linux.
  3. Disable NCQ on boot. Add libata.force=noncq to the kernel command line in the Bootloader configuration.

If these do not resolve the problem or cause other issues, file a bug report.

Tips for minimizing disk reads/writes

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.

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 [6] when considering whether any particular strategy to limit disk writes is actually needed.

Use iotop and sort by disk writes to see how much and how frequently are programs writing to the disk.

Tip: iotop can be run in batch mode instead of the default interactive mode using the -b option. -o is used to show only processes actually doing I/O, and -qqq is to suppress column names and I/O summary. See man iotop for more options.
# iotop -boqqq

Intelligent partition scheme

  • For systems with both an SSD and an HDD, consider relocating the /var partition to a magnetic disc on the system rather than on the SSD itself to avoid read/write wear.

noatime mount option

Merge-arrows-2.pngThis article or section is a candidate for merging with fstab#atime options.Merge-arrows-2.png

Notes: This should be described only in one place, just link to fstab afterwards. (Discuss in Talk:Solid state drive#)

Using this flag in one's /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 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.

Note: The write time information to a file will continue to be updated anytime the file is written to with this option enabled.
/dev/sda1  /       ext4   defaults,noatime   0  1
/dev/sda2  /home   ext4   defaults,noatime   0  2
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 relatime option instead of 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.

Locate frequently used files to RAM

Browser profiles

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.

The AUR contains several packages to automate this process, for example profile-sync-daemonAUR.


For the same reasons a browser's profile can be relocated to RAM, so can highly used directories such as /srv/http (if running a web server). A sister project to profile-sync-daemonAUR is anything-sync-daemonAUR, which allows users to define any directory to sync to RAM using the same underlying logic and safe guards.

Compiling in tmpfs

Intentionally compiling in tmpfs is great to minimize disk reads/writes. For more information, refer to Makepkg#Improving_compile_times.

Disabling journaling on the filesystem

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, Ted Tso advocates that journaling can be enabled with minimal extraneous read/write cycles under most circumstances:

Amount of data written (in megabytes) on an ext4 file system mounted with noatime.

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."

Note: The make clean example from the table above typifies the importance of intentionally doing compiling in tmpfs as recommended in the preceding section of this article!

Choice of Filesystem


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.


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 discard mount option in fstab (or with tune2fs -o discard /dev/sdaX). See the official in kernel tree documentation for further information on ext4.


Many users do not realize that in addition to ext4 and btrfs, 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 XFS wiki.


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 Linux news sites. It is apparent that it can be enabled via the discard mount option, or by using the method of batch TRIMs with fstrim.

Other filesystems

There are other filesystems specifically designed for SSD, for example F2fs.

Firmware Updates


ADATA has a utility available for Linux (i686) on their support page 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.


Crucial provides an option for updating the firmware with an ISO image. These images can be found after selecting the product here and downloading the "Manual Boot File." 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:
See the following web pages for firmware updates:

Users seeing this warning are advised to backup all sensible data and consider upgrading immediately.


Kingston has a Linux utility to update the firmware of Sandforce controller based drives: 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: support page.


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 has a command line utility available for Linux (i686 and x86_64) on their forum here.


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 here.

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.

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 this post for reference.


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).

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.

I could not find a single page listing the firmware updates yet (site is a mess IMHO), but here are some relevant links:

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

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

See also