Optimize flash memory in Linux
Fine-tuned
Solid state drives make everything run faster and more smoothly, but you can squeeze out even more performance with some practical optimization steps.
Solid-State drives (SSDs) are quite different from old-fashioned hard disks, and you'll have to learn some new techniques if you want to tune up performance. This article highlights some important steps for optimizing SSDs.
Updating the Firmware
Firmware is just as important as hardware, and the flash chips in the SSD are no exception. Special software mechanisms such as wear leveling and garbage collection improve the efficiency of the drive; without these mechanisms, the durability and performance of the SSD would be impaired over its service life. The firmware is thus an important part of the product, and it is also under constant development, which means it is important to update the firmware.
Linux users are often a little envious when they see how easy it is to install new firmware in Windows by clicking around in a graphical interface. Intel and Samsung provide Linux binaries for their datacenter SSDs, but for their consumer products, users need to boot an ISO file.
Alignment
When SSDs first started to become more widespread, correct alignment [1] had not yet been implemented in the popular partitioning tools. Today, command-line utilities such as fdisk
, gdisk
, or parted
pay attention to correct alignment of the partitions, making sure, for example, that the first partition starts in sector 2048. The example in Listing 1 demonstrates how to correctly create a new partition and test it with align-check
.
Listing 1
Creating a Correctly Aligned Partition
01 $ sudo parted /dev/sdb mklabel gpt 02 $ sudo parted -a optimal -- /dev/sdb mkpart primary 0% 100% 03 $ sudo parted /dev/sdb align-check opt 1 04 1 aligned 05 06 $ sudo gdisk -l /dev/sdb 07 [...] 08 Number Start (sector) End (sector) Size Code Name 09 1 2048 390721535 186.3 GiB 8300 primary
Over-Provisioning
All SSDs have a spare area, that is, a reserved data area that is not directly visible to the operating system, which the SSD uses internally for the wear leveling and bad-block replacement, as well as read, modify, and write operations.
Especially with low-budget consumer SSDs without a trim
function, increasing the size of the spare area (aka over-provisioning) is a good way to improve durability and performance. However, enterprise SSDs already come with a higher gross capacity and tolerate more writes, that is, they show a larger value for Terabytes Written (TBW). The DC S3500 SSD shown in Figure 1 has 336GB flash chips for a nominal capacity of 300GB. The graph shows how the write performance improves for the 800GB model given a bigger spare area.
It is best to set up over-provisioning before an SSD goes into production operation. You have several configuration options: the first method is to set up a host-protected area (HPA) with hdparm
. To create an HPA, you'll need to delete all the blocks on the SSD. (You'll need to delete the blocks so the SSD controller will be able to actually use the hidden data areas for wear leveling later on.) The blocks are deleted for an SSD in an as-delivered state. However, if the device has already been used, you need to restore this state with a secure erase or manual trim (depending on the SSD). Typing the following:
hdparm -Np number_of_sectors /dev/sdb
sets up the host-protected area.
With the second method, you just leave an area on the SSD unpartitioned and create partitions for, say, only 90 percent of the disk's capacity. In this case as well, you need to perform a secure erase up front if the SSD was previously in use. The operation deletes and frees up all the flash cells.
The third method is to use the vendor's SSD tools, such as Intel's isdct
or Samsung's magician
.
Buy this article as PDF
(incl. VAT)