The Solid State Drive (SSD) has transformed storage technology by providing outstanding speed, accuracy, and lower power consumption. SSDs have many advantages, but to truly enjoy the full benefits and advantages of them, we should ensure that our Linux system configuration is fully optimized. To ensure that the optimization techniques work on our system, it’s important to verify that the system is using an SSD.
In this tutorial, we’ll learn how to optimize SSD configuration in Linux, tested on the Ubuntu 20.04 distribution, for better and more efficient performance.
2. Changing the Filesystem
Additionally, some filesystems are designed with specific features that take advantage of the SSD. One example of such a filesystem is the F2FS filesystem, which provides features such as cleaning overhead, flash awareness, and others that help improve the performance and durability of the SSD.
It’s also important to back up the system data before making any major changes because this process can remove previously stored data.
Let’s create and mount a new F2FS filesystem in Ubuntu:
$ sudo mkfs.f2fs /dev/sda
Info: Superblock written successfully
Info: Copying primary superblock to secondary superblock and backup superblock...
Info: Successfully created filesystem on /dev/sda.
$ sudo mkdir /mount/ssd
$ sudo mount /dev/sda /mnt/ssd
First, we create an F2FS filesystem on the specified device /dev/sda. Next, we create a directory named /mnt/ssd. Finally, we mount the F2FS filesystem onto the created directory /mnt/ssd to make it accessible.
3. TRIM Support
TRIM support plays an essential role in maintaining the peak speed and endurance of an SSD. It ensures that SSD can efficiently handle its storage capacity.
Without TRIM, the SSD performance could decrease gradually when data is written and erased, thereafter creating empty data blocks that affect performance. TRIM resolves this problem by allowing the SSD to flag data blocks as no longer in use and ready for removal:
$ sudo fstrim -av /mount/point: 3.4 GiB (3656416256 bytes) trimmed
/user/sda: 26.9 GiB (28878043136 bytes) trimmed
Here, we use the fstrim command to trigger a TRIM operation on the SSD, informing it to clean up and optimize its storage space. The -av flags produce detailed output that shows the operation’s progress in all mounted filesystems. The output also shows the amount of data that has been trimmed and identified for effective removal.
Additionally, it’s advisable to trigger the TRIM operations weekly for basic users and daily for heavy users. We can automate the TRIM operations by creating trim.service and trim.timer units in the /etc/systemd/system/ directory to handle continuous TRIM operations:
$ sudo nano /etc/systemd/system/trim.service
Description=SSD TRIM Service
$ sudo nano /etc/systemd/system/trim.timer
Description=Run trim weekly
$ sudo systemctl enable trim.timer
$ sudo systemctl start trim.timer
Here, we create a trim.service file and add the description, type, and ExecStart options. In the second code block, we also create a trim.timer file and add description, oncalendar, accuracysec, and other options. Thereafter, we enable and start the trim.timer unit. The value of oncalendar in the .timer unit is set to weekly in this instance. We can also set the value to daily depending on the system usage.
4. Adjust Swappiness
Swappiness is a Linux parameter that controls the system’s readiness to swap data from RAM to the swap space on the storage device. This occurs when physical RAM is full, thereby freeing up memory for other processes.
The default value for swappiness on most Linux systems is 60, but for efficient SSD performance, the value should be set to a number less than 60:
$ sudo nano /etc/sysctl.conf
$ sudo sysctl -p
Reducing the swappiness value to a lower value (between 0 and 60) tends to reduce write operations to the SSD as the system will use the memory meant for swap more conservatively, while a higher swappiness value (60 to 100) aggressively uses swap space, potentially reducing the SSD lifespan.
5. Minimize Access Time Updates
The last time a file was accessed in a system is recorded by the atime (access time) parameter. By default, Linux updates the value of this parameter every time a file is read. This may result in needless write operations on an SSD, thereby reducing the lifespan and performance of the SSD.
The filesystem has a mount option called noatime that we can use to minimize these access time updates. With the noatime option, the system is instructed to retain the original atime timestamp from the time the file was last written or edited instead of updating it when a file is read:
$ sudo nano /etc/fstab
/dev/sda /mnt/ssd ext4 defaults 0 2
/dev/sda /mnt/ssd ext4 defaults,noatime 0 2
Here, we use the nano command to open the /etc/fstab file, which provides details about the devices and partitions that mount at startup. Then, we edit the file by adding a noatime option. The /etc/fstab file is hereafter edited and the noatime option is added. To ensure the new mount choices take effect, consider rebooting the system.
By limiting the access time updates, we can prolong the lifespan and enhance the performance of the SSD.
6. Optimize I/O Scheduler
I/O schedulers in Linux are responsible for managing read and write data operations that go in and out of the SSD. The default scheduler on most Linux distributions is the Completely Fair Queuing (CFQ) scheduler, which isn’t suitable for SSD.
The most suitable schedulers for the SSD are the deadline and noop schedulers. However, various I/O schedulers such as none, bfq, and mq-deadline show minimal capacity differences for fast multi-queue SSD or NVME devices. In these cases, it could be preferable to use none as the I/O scheduler to minimize CPU overhead. This option maximizes system performance by reducing pointless processing, thereby utilizing the SSD’s built-in speed. Optimizing these schedulers involves modifying bootloader configurations:
$ sudo nano /etc/default/grub
GRUB_CMDLINE_LINUX="quiet splash scsi_mod.use_blk_mq=1"
$ sudo update-grub
Here, we use nano to open the GRUB configuration file usually located at /etc/default/grub. Then, we can look for any line containing the GRUB_CMDLINE_LINUX parameter and add the scsi_mod.use_blk_mq=1 parameter. This parameter enables the Block Multi-Queue blk-mq for the SCSI subsystem, which indirectly influences the I/O scheduler to default to none for the SSD.
This method uses the blk-mq to implicitly set the I/O scheduler to none. After this, we save and exit the file. We then use the update-grub command to apply the changes. The system I/O scheduler is now configured in the GRUB bootloader to be none.
By doing this, we can be confident that the ideal scheduler is utilizing the processing power and capabilities of the SSD immediately when the system powers on.
7. Monitor SSD Health
To ensure full optimization of the SSD, it’s essential to regularly check and monitor the SSD’s health. Monitoring the health of an SSD tends to boost longevity — for example, by detecting potential issues early.
$ sudo smartctl -a /PATH_TO_SSD
Device Model: SSD 860 EVO 1TB
Serial Number: S4G7NB0KA12345E
LU WWN Device Id: 5 002538 88012345E
Firmware Version: RVT04B6Q
User Capacity: 1,000,204,886,016 bytes [1.00 TB]
Sector Size: 512 bytes logical/physical<i
Rotation Rate: Solid State Device
Form Factor: 2.5 inches
Device is: In smartctl database [for details use: -P show]
ATA Version is: ACS-4 (minor revision not indicated)
SATA Version is: SATA 3.2, 6.0 Gb/s (current: 6.0 Gb/s)
Local Time is: Wed Oct 26 13:45:12 2023 CEST
SMART support is: Available - device has SMART capability.
SMART support is: Enabled
SMART overall-health self-assessment test result: PASSED...
Here, we use the smartctl command to analyze the SSD health. The section that requires attention is the SMART overall-health self-assessment test result, which in this case indicates PASSED. An SSD with a PASSED status is in good condition and is operating as intended. If this command had reported a status of FAILED, it would indicate potential SSD health difficulties.
Furthermore, the output of smartctl provides detailed information about the SSD’s health and performance. The output also includes device information, SMART attributes, and a self-test log. It’s important to check these attributes regularly to identify signs of wear, potential issues, or critical conditions.
In this article, we discussed how to fully optimize the SSD and harness its power. We discussed some steps that need to be taken to ensure the efficient performance of the SSD.
Changing the filesystem type to options such as Btrfs or F2FS, enabling TRIM support, adjusting swappiness to a lower value, minimizing access time updates with the noatime option, optimizing I/O schedulers, and regularly monitoring SSD health with tools such as smartctl are all important steps to ensure efficient performance of the SSD.
The success of these modifications can be measured using applications like CrystalDiskMark, hdparm, FIO, and others. These applications measure the performance and efficiency of the SSD. Furthermore, comparing IOPS (Input/Output Operations Per Second) and read/write speeds before and after optimizations will provide a clear picture of the gains we’ve achieved.