SSD performance woes

I noticed that copying a 7 GB file from my Drobo 5D to my internal SSD took forever to complete – as in, over a minute. (Life is hard!) My Drobo can read significantly faster than that, and my SSD can write faster than that, so what's the deal?

I pop open Activity Monitor, turn to the Disk Activity tab, and open Terminal:

$ cd /Volumes/Drobo
$ dd if=input_file of=/dev/null bs=$(( 1024 * 1024 ))

Yep, easily 250 MB/s off the Drobo.

$ cd
$ dd if=/dev/zero of=zero bs=$(( 1024 * 1024 )) count=8

Yep, easily 200 MB/s to the SSD… wait, why did it drop to zero after the first GB? What are all these spikes?!

*poke about system diagnostics*

Ah, TRIM is disabled. Probably a while ago, too. (I guess Apple still doesn't trust third-party SSDs to implement it properly?) Whatever. I now have two problems: I need to OSX to send ATA TRIM commands going forwards, and I need to TRIM all the current empty space in order to restore my SSD's write performance.

I open up Trim Enabler and slide the switch. Done. I go to the Settings tab, check "Warn if trim patch is disabled", so maybe I'll notice if this breaks again. Reboot, and System Information now says TRIM is enabled.

Now, how do I re-TRIM all the current free space? I could write a file of zeroes and delete it, but that's… dumb.

*poke about the web*

Ah, great! fsck can do this. Though… since I need to use my now-modified kernel extensions, I'll have to fsck my Macintosh HD volume while running from it. This can be done from single user mode, but asking a running system to modify itself in this manner is mildly unnerving. I'd feel better if I were booted from the recovery partition, but that would not include the modifications necessary to enable TRIM on non-Apple SSDs.

Before going further, I asked Disk Utility to "Verify Drive" from the desktop to make sure everything was fine.

Guess what? Everything wasn't fine. Apparently somewhere along the line my volume bitmap got screwed up; space was marked as used even though the filesystem no longer referenced it. That doesn't affect any of my data, but it does indicate that the volume somehow got in an inconsistent state, which means it's possible there are other undetected problems. Now the situation demands even more caution.

Time Machine! Back up everything!

Time Machine dutifully backed up everything, both to my NAS as usual and to an external hard drive that I infrequently attach.

I powered down, then powered up again while holding ⌘S. Once booted:

# fsck
...
** Checking Journaled HFS Plus volume.
** Checking extents overflow file.
** Checking catalog file.
** Checking multi-linked files.
** Checking catalog hierarchy.
** Checking extended attributes file.
** Checking multi-linked directories.
** Checking volume bitmap.
   Volume bitmap needs minor repair for orphaned blocks
** Checking volume information.
   Invalid volume free block count
   (It should be 82404658 instead of 81741301)
** Repairing volume.
** Rechecking volume.
** Checking Journaled HFS Plus volume.
** Checking extents overflow file.
** Checking catalog file.
** Checking multi-linked files.
** Checking catalog hierarchy.
** Checking extended attributes file.
** Checking multi-linked directories.
** Checking volume bitmap.
** Checking volume information.
** Trimming unused blocks.
** The volume Macintosh HD appears to be OK.

Hooray! It says the volume is fixed, and it issued TRIM commands for all the unused space. We should be in business.

# reboot

Now I see a globe instead of the Apple logo. Are you… are you trying to netboot? What? Why?

Did I do a bad?

Power down. Power up. Apple logo, flicker, Apple logo, login screen. (Whew.)

And finally: I tried copying that 7 GB file again. It completed in about 30 seconds, averaging 220 MB/s.