Solid State Drives - Best Practices
As most Archers know, Solid State Drives (SSDs) are not PnP devices. Special considerations such as partition alignment, choice of file system, TRIM support, etc. are needed to setup SSDs for optimal performance. This article attempts to capture referenced, key learnings to enable users to get the most out of SSDs under Arch (Linux in general).
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 the loss of performance over time.
- Buying the right size SSD is also key. It goes without saying that purchasing the right about of capacity is important. Like all file systems, target <75 % occupancy for all SSD partitions to ensure efficient use by Linux.
This section is not meant to be all-inclusive, but does capture some key reviews.
- SSD Anthology (history lesson, a bit dated)
- SSD Relapse (refresher and more up to date
- One user's recommendations
Partitioning and Alignment
Proper partition alignment is key for optimal performance and longevity. The community seems to be in agreement on the use of fdisk as the utility of choice for partitioning SSDs (although one can also find guides whose authors advocate using parted). Consensus opinion on the best settings for number of heads and cylinders is tough to find. There seem to be two different camps on this issue:
Ted Tso and others recommend using 244/56 option:
# fdisk -H 224 -S 56 /dev/sdX
While others advocate the 32/32 option:
# fdisk -H 32 -S 32 /dev/sdX
Additional Links on Alignment
Many options exist for file systems including ext2, ext3, ext4, XFS, and btrfs. Initially, ext2 was thought to be a good choice as it lacks journaling which would avoid extraneous read/write cycles. Ext4 can also be used without a journal and is thought to be superior to ext2 in a number of areas. The obvious drawback of using a non-journaling file system is data loss as a result of an ungraceful dismount (i.e. post power failure). With modern SSDs, Ted Tso advocates that journaling can be enabled with minimal extraneous read/write cycles.
--Placeholder for key data from aforementioned article--
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. It should be noted that at the time this article was written (27-June-2010), a stable version of btrfs does not exist. See this blog entry for more on btrfs.
Mount Flags in /etc/fstab
There are several key mount flags to use in one's Template:Filename entries for SSD partitions.
- noatime - Reading accesses to the file system will no longer result in 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, this can result in measurable performance gains. Note that the write time information to a file will continue to be updated anytime the file is written to with this option enabled.
- discard - The discard flag will enable the benefits of the TRIM command so long as one is using kernel version >=2.6.33.
/dev/sda1 / ext4 defaults,noatime,discard 0 1
Consider switching from the cfq scheduler to the noop or deadline scheduler. Using the noop scheduler for example simplifies requests in the order they are received, without giving any consideration to where the data physically resides on the disk. This option is thought to be advantageous SSDs since seek times are identical for all sectors on the SSD. For more on schedulers, see this Linux-mag article.
The cfq scheduler is enabled by default on Arch. Verify this by viewing the contents /sys/block/sda/queue/scheduler:
$ cat /sys/block/sda/queue/scheduler [noop] deadline cfq
The scheduler currently in use is denoted from the available schedulers by the brackets. To switch to the noop scheduler, one can add the following line in Template:Filename:
# echo noop > /sys/block/sda/queue/scheduler
Swap Space on SSDs
One can place a swap partition on an SSD. Note that 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. The following is recommended tweak for SSDs using a swap partition that will reduce the "swapiness" of the system thus avoiding writes to swap.
# echo 1 > /proc/sys/vm/swapiness