Jack Wallen explains how you can optimize your Linux operating system for SSD.
Many TechRepublic readers have followed my difficulties with audio in Linux. For the longest time, PulseAudio was a tragedy to work with (on certain hardware -- my production recording studio machine being one of them). Things were starting to steer me toward making the leap to OS X, if only for just audio production, but then things took a turn for the slightly improved. What happened? I upgraded to Ubuntu 13.10.
The improvements for audio productions are marked, especially recording. I no longer experience random stops in the input stream, so I don't have to punch sections to fix sound loss. I still notice skipping during playback, which isn't a deal breaker as much as it is an annoyance. However, as with everything, I have a plan.
Solid state drive
That's right, I'm going to migrate my machine into modern times and use a solid state drive (SSD). Why? The drastic performance gain with these devices should, at least in theory, fix the last issue I have with Linux and audio.
But wait! Isn't Linux rumored to not be ready for prime time SSD usage? At one point, that was the case... but actually, it was more the hardware not truly being ready for prime time. Every platform had to deal with write aheads causing fast degradation of the hardware. However, there was a recent article on StorageSearch that went into great detail on why you shouldn't worry about the lifespan of an SSD. Effectively, they ran tests that concluded, even when an SSD receives writes at a continuous rate of 80M/s, the life span of said drive is 51 years. Those tests were based on 2007 SSD firmware. Things have changed quite a lot since then.
That doesn't mean that you should just throw a Linux distribution on an SSD and be done with it. In fact, there's at least one optimization that should be done before you “set it and forget it.” That optimization is TRIM, which effectively tells an operating system which blocks of data on an SSD are no longer considered in use and should be wiped internally.
You can either configure Linux to handle TRIM automatically or you can run the TRIM command manually. I highly recommend setting this up to be automated. Here's how you do it:
- Open a terminal window
- Issue the command (you'll need root access or sudo): cp /etc/fstab ~/fstab
- Open /etc/fstab for editing in your favorite editor (such as nano)
- Add the “discard” option (no quotes) to the SSD drive entry (example below)
- Save the file
UUID=00000000-0000-0000-0000-000000000000 / ext4 discard,errors=remount-ro 0 1
Note: The file system type is ext4. It's very important that your SSD be formatted to ext4, because that particular journaling system is best suited for SSDs.
Now, let's test the automatic TRIM. Follow these steps (updated on 11/13/13):
- Open a terminal window
- Change to the root directory of your SSD (if it's the only drive on the machine, it will be “/” -- no quotes)
- Issue the command (you'll need sudo or root): sudo dd if=/dev/urandom of=/home/USERNAME/tempfile count=100 bs=512k oflag=direct (where USERNAME is the actual name of your user account)
- Issue the command: sudo hdparm --fibmap tempfile
- From the output of the hdparm command, copy the number under the begin_LBA section
- Verify the device name of your SSD (sda, sdb, sdg, etc)
- Issue the command: sudo hdparm --read-sector [ADDRESS] /dev/sdX (where ADDRESS is the number you copied from the begin_LBA section and sdX is the SSD device name)
- Remove the tempfile created from the output of the sudo hdparm --fibmap tempfile command
- Issue the command: sync
- Repeat the hdparm command from above
At this point, the output of the hdparm command should be nothing but zeroes. If that's the case, automatic TRIM is working. If you do not get only zeroes, give the system an hour or so and rerun the hdparm command. Hopefully, at that point, you should only see zeroes. This method of testing isn't flawless, because sometimes the TRIM does take longer.
Congratulations, your Linux operating system should be optimized for your SSD. Of course, not everything is created equal or perfect. Everyone will find varying results with Linux and SSDs, but the performance increase you receive with these devices is so significant that the trouble you might have to go through is well worth the time involved.
Most importantly, as always, back up your data! It doesn't matter if you are using an HDD, SDD, or some newer drive based on Cylon technology -- be sure to back up your data!
Have you optimized your Linux operating system for SSD? Share your experience in the discussion thread below.