Trim Enabler 4 2 – Write Faster To Any Ssd



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 is supported for RAID (0,1,4,5 & 10) volumes when using the third-party SoftRAID® application, including TRIM support with non-Apple SSD devices. (Note: TRIM for non-Apple SSD devices must be specifically enabled using the terminal command 'sudo trimforce enable'). This means the SSD does a lot of erasing and wiping, which causes a fast wear of the flash memory chips and shortens the longevity of the SSD. However, if an SDD has TRIM, there is no need to worry about the above situation, because TRIM eliminates any necessary copying of discarded or invalid data pages to save time and improve SSD performance. As solid state drives became more affordable, the TRIM command was introduced to facilitate “garbage collection” of deleted data, allowing the SSD to reset those “unused” blocks back to an “empty” state. This allows for better performance for many SSDs. With TRIM enabled, SSD drives do not have to delete the entire block of data and instead, deleting only the required page is suffice. Thus, TRIM significantly increases the speed of writing data on SSD drives. It also increases the overall lifespan of an SSD drive. Figure 1: Two SSD devices, SATA on the left and m.2 on the right, with a penny for size comparison. There are also multiple types of memory technology used in SSD devices. NVMe (Non-Volatile Memory express) is the fastest. Several weeks ago, I purchased an Intel 512 GB m.2 NVMe SSD for a customer project that never fully matured.

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 systemContinuous TRIM
(discard option)
Periodic TRIM
(fstrim)
References
and notes
BtrfsYesYes
Ext3No?
Ext4YesYes[1]
F2FSYesYes
JFSYesYes[2]
NILFS2YesYes
NTFS-3GNoYessince version 2015.3.14, [3]
VFATYesYesfstrim is supported since kernel 4.19
XFSYesYes[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:

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

Alternatively, installhdparm package and run:

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.timersystemd 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, see ata_device_blacklist in Linux source code, 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)#Disadvantages 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][dead link 2020-04-03 ⓘ]
Trim Enabler 4 2 – Write Faster To Any Ssd

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

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=discardkernel parameter.

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

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.

LVM

TRIM requests that get passed from the file system to the logical volume are automatically passed to the physical volume(s). No additional configuration is necessary.

No LVM operations (lvremove, lvreduce and all others) issue TRIM requests to physical volume(s) by default. This is done to allow restoring previous volume group configuration with vgcfgrestore(8). The setting issue_discards in /etc/lvm/lvm.conf controls whether discards are sent to a logical volume's underlying physical volumes when the logical volume is no longer using the physical volumes' space.

Note: Carefully read the comment in /etc/lvm/lvm.conf before changing the issue_discards setting. It does not in any way affect TRIM requests that get passed from the file system to the disk (e.g. file deletions inside a file system) nor does it affect space management within a thin pool.
Warning: Enabling issue_discards will prevent volume group metadata restoration with vgcfgrestore. There will be no recovery options in case of a mistakenly issued LVM command.

dm-crypt

Warning: The discard option allows discard requests to be passed through the encrypted block device. This may or may not [8][9] improve 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.

Native sector size

This article or section is a candidate for merging with Advanced Format.

Notes: Or at least link to the page. There is also Solid state drive/NVMe#Sector size. (Discuss in Talk:Solid state drive#)

Most SSDs report their sector size as 512 bytes, even though they use larger sectors - typically 4 kB, 8 kB, or sometimes larger. Because they report as 512 byte devices, filesystems cannot automatically optimise for the native sector size and this must be manually specified when creating a filesystem to avoid suboptimal performance.

As an alternative to manually overriding the autodetected sector size, some SSDs can have their sector size changed during formatting, so that they report a number closer to their true sector size.

NVMe

To see whether a given NVMe device supports this, use the Identify Namespace command.

nlbaf is the number of LBA formats minus 1, so here there is only one format supported. The list of formats is at the end of the output. Here lbaf 0 means LBA format #0. It has an lbads (LBA data size) of 9, which means sectors are 29 or 512 bytes. If the device is capable of 4 kB sectors, there will be another entry here with an lbads of 12. The rp (Relative Performance) value indicates which format will provide the best performance, with 0 being the best. ms is (probably) the number of extra metadata bytes per sector, and this is not well supported under Linux so best to select a format with a value of 0 here.

To change the sector size, use nvme format and specify the preferred value with the --lbaf parameter.

SATA

For SATA devices, manufacturer specific programs must be used. Not all SATA devices support having the sector size changed.

  • Intel: Use the Intel Memory and Storage (MAS) Tool (intel-mas-cli-toolAUR) with the -set PhysicalSectorSize=4096 option.

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:

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 [10], [11]).

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:

  • The SSD's firmware
  • The motherboard's BIOS/UEFI firmware
Trim Enabler 4 2 – Write Faster To Any Ssd

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:

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:

If this (and also updating the firmware) does not resolve the problem or causes 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.

External SSD with TRIM support

This article or section needs language, wiki syntax or style improvements. See Help:Style for reference.

Trim enabler 4 2 – write faster to any ssd hard drive
Reason: Several style and formatting problems, especially too many explicit commands - see Help:Style#File editing requests. (Discuss in Talk:Solid state drive#)

Several USB-to-SATA bridge chips (like VL715, VL716 etc.) and also USB-to-PCIe bridge chips (like the JMicron JMS583 used in external NVMe enclosures like IB-1817M-C31) support TRIM-like commands that can be sent through the USB Attached SCSI driver (named 'uas' under Linux).

But the kernel may not automatically detect this capability, and therefore might not use it.Assuming your block device in question is /dev/sdX, you can find out whether that is the case by using the command

If in its output you find a line stating 'Logical block provisioning: lbpme=0' then you know that the kernel assumes the device does not support 'Logical Block Provisioning Management' because the (LBPME) bit is not set.

If this is the case, then you should next find out whether the 'Vital Product Data' (VPD) page on 'Logical Block Provisioning' of your device tells of supported mechanisms for unmapping data. You can do this using the command:

Look for lines in the output that look like this:

This example would tell you the device supports the 'UNMAP' command.

Have a look at the output of

If the kernel did not detect the capability of your device to unmap data, then this will likely return 'full'.Apart from 'full', the kernel SCSI storage driver currently knows the following values for provisioning_mode:

For the example above, you could now write 'unmap' to 'provisioning_mode' to ask the kernel to use that:

This should immediately enable you to use tools like 'blkdiscard' on /dev/sdX or 'fstrim' on filesystems mounted on /dev/sdX.

If you want to enable a 'provisioning_mode' automatically when an external device of a certain vendor/product is attached, this can be automated via the 'udev' mechanism. First find the USB Vendor and Product IDs:

Then create or append to a udev rule file (example here using idVendor 152d and idProduct 0583):

(You can also use the lsusb command to look for the relevant idVendor / idProduct.)

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.

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 Windows Intel® Solid-State Drive Toolbox software.

There is also a newer Linux command-line utility that can reflash firmware called the Intel Memory and Storage (MAS) Tool available in the AUR as intel-mas-cli-toolAUR. There is a PDF user guide available.

An example for checking the firmware status is:

Trim Enabler 4 2 – Write Faster To Any Ssd Hard Drive

-intelssd 0 can be omitted if there is only one Intel SSD in the system, or 1 passed for the second SSD, and so on.

If an update is available, it is performed by running intelmas load -intelssd 0. The PDF user guide suggests that this procedure needs to be performed twice in Linux, with a power cycle in between. The latest firmware for all devices is distributed as part of the MAS Tool itself, so does not need to be downloaded separately.

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.

Upgrade under Linux

This article or section needs language, wiki syntax or style improvements. See Help:Style for reference.

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:

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

Get the contents of the disk:

Unmount the iso:

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

Get the disk number from magician:

Assuming it was 0:

Verify that the latest firmware has been installed:

Write

Finally reboot.

Faster

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

Retrieved from 'https://wiki.archlinux.org/index.php?title=Solid_state_drive&oldid=649230'
If you have a need for speed, you need to consider the switch to SSDs.

More Linux resources

I know that many of you have been using solid-state disk (SSD) devices to replace the venerable hard drive (HDDs) with physical spinning disks for a long time now. I have been, too, actually, but only because the System76 Oryx Pro laptop I purchased a couple of years ago came with SSDs as the primary storage option. Whenever I boot my laptop – which is not frequently because I usually let it run 24x7 for various reasons – it surprises me how quickly I get to a login prompt. All of my other physical hosts boot more slowly from their spinning disk hard drives.

Don't get me wrong. I like my computers with fast processors, lots of CPUs, and large amounts of RAM. But I have this problem: people gift me their old computers, and I dismantle them for parts, including hard drives. Few people are currently discarding systems with SDDs, which I expect will not change for a while.

I use those older systems until the motherboard or something else irreplaceable dies. At that point, I take the remaining unusable components of the defunct system to the local electronics recycling center. I keep any usable parts, including hard drives. I end up with plenty of old hard drives, some of which I use to keep some of those older systems going for a while longer. The rest just sit in a container waiting to be used.

I hate to discard perfectly usable computer parts. I just know that someday I will be able to use them. I also try to keep computers and components out of the recycling process so long as they are useful. And I have found places to use most of those older bits, including those old hard drives.

Why SSD?

The primary function of both HDD and SSD devices is to store data in a non-volatile medium so that it is not lost when the power is turned off. Both drive technologies store the operating system, application programs, and your data so that they can be moved into main memory (RAM) for use. The functional advantages of SSD over HDD are twofold, and both are due to the solid-state nature of the SSD.

First, SSDs have no moving parts to wear out or break. I have had many HDDs fail over the years; I use them hard, and the mechanical components wear out over time.

The second advantage of SSDs is that they are fast. Due to their solid-state nature, SSDs can access any location in their memory at the same speed. They do not need to wait for mechanical arms to seek to the track on which the data is stored and then wait for the sector containing the data to rotate under the read/write heads to be read. These seek and rotational latencies are the mechanical factors that slow access to the data. SSDs have no such mechanical latencies. SSDs are typically 10x faster when reading data and 20x faster when writing.

There are other non-performance-related advantages for SSDs over HDDs. SDDs use less energy, are smaller and weigh less than HDDs, and are less likely to be damaged if dropped.

In many respects, SSDs are like USB thumb drives, which are also solid-state devices and essentially use the same flash memory storage technology.

The primary drawbacks to SSD devices are that they are more expensive for a given storage size than HDDs, and HDDs have a greater maximum capacity than SSDs. Currently, that capacity is about 14 TB for HDDs and 4 TB for SSDs. These gaps are narrowing. Another issue with SSDs is that their memory cells can 'leak' and degrade over time if power isn't maintained. The degradation can result in data loss after about a year of being stored without power, making them unsuitable for off-line archival storage.

There are several interesting and informative articles about SSDs at the Crucial and Intel web sites. To be clear, I like these pages for their excellent explanations and descriptions; I have no relationship of any kind with Crucial or Intel other than to purchase at retail some of their products for my personal use.

SSD types

There are two common SSD form factors and interfaces. One is a direct replacement for hard disk drives. It uses standard SATA power and data connectors and can be mounted in a 2.5' drive mounting bay. SATA SSDs are limited to the SATA bus speed, which is a maximum of 600 Mb/s.

Trim Enabler 4 2 – Write Faster To Any Ssd Upgrade

The other form factor uses an M.2 PCIe connector that is typically mounted directly on the motherboard. The ASUS TUF X299 motherboard in my primary workstation has two of these connectors. The physical form factor for M.2 SSDs is 22 mm wide with varying lengths up to about 80 mm. M.2 devices can achieve read speeds of up to 40 Gb/s due to the direct connection to the PCI bus.