OS X and SSD – tunings plus performance with and without TRIM

I finally decided to spring for a SSD for my laptop since I hammer it heavily with a lot of mostly random I/O. It was money well spent.

I went for an Intel 320 model, since it includes extra capacitors for flushing the cache in the event of power failure, and has RAID-4 onboard for protection beyond sparing (there are other, faster SSDs but I need the reliability and can’t afford large-sized SLC).

I used the trusty postmark (here’s a link to the OS X executable) to generate a highly random workload with varying file sizes, using these settings:

set buffering false
set size 500 100000
set read 4096
set write 4096
set number 10000
set transactions 20000
run

All testing was done on OS X 10.6.7.

Here’s the result with the original 7200 RPM HDD:

Time:
198 seconds total
186 seconds of transactions (107 per second)

Files:
20163 created (101 per second)
Creation alone: 10000 files (1111 per second)
Mixed with transactions: 10163 files (54 per second)
10053 read (54 per second)
9945 appended (53 per second)
20163 deleted (101 per second)
Deletion alone: 10326 files (3442 per second)
Mixed with transactions: 9837 files (52 per second)

Data:
557.87 megabytes read (2.82 megabytes per second)
1165.62 megabytes written (5.89 megabytes per second)

I then replaced the internal drive with SSD, popped the old internal drive into an external caddy, plugged it into the Mac, reinstalled OS X and simply told it to move the user and app stuff from the old drive to the new (Apple makes those things so easy – on a PC you’d probably need something like an imaging program but that wouldn’t take care of very different hardware). I spent a ton of time testing to make sure it was all OK, in disbelief it was that easy. Kudos, Apple.

Here are the results with SSD (2/3rds full FWIW):

Time:
19 seconds total
13 seconds of transactions (1538 per second)

Files:
20163 created (1061 per second)
Creation alone: 10000 files (2500 per second)
Mixed with transactions: 10163 files (781 per second)
10053 read (773 per second)
9945 appended (765 per second)
20163 deleted (1061 per second)
Deletion alone: 10326 files (5163 per second)
Mixed with transactions: 9837 files (756 per second)

Data:
557.87 megabytes read (29.36 megabytes per second)
1165.62 megabytes written (61.35 megabytes per second)

A fair bit of improvement… 🙂 The perceived difference is amazing. For some things I’ve caught it doing over 200MB/s sustained writes.

I also disabled the sudden motion sensor since there’s no point stopping I/O to a SSD if one shakes the laptop. From the command line:

sudo pmset -a sms 0 (this disables it)
sudo pmset –g (to verify it was done)

And since I don’t need hotfile adaptive clustering on a SSD, I decided to disable access time updates (noatime in UNIX parlance).

You need to put the script from here: http://dl.dropbox.com/u/5875413/Tools/com.my.noatime.plist

into /Library/LaunchDaemons

And make sure it has the right permissions:

sudo chown root:wheel com.my.noatime.plist

Then reboot, type mount from the command line, and see if the root filesystem shows noatime as one of the mount arguments.

For example mine shows

/dev/disk0s2 on / (hfs, local, journaled, noatime)

I then re-ran postmark, here are the results with noatime:

Time:
16 seconds total
11 seconds of transactions (1818 per second)

Files:
20163 created (1260 per second)
Creation alone: 10000 files (2500 per second)
Mixed with transactions: 10163 files (923 per second)
10053 read (913 per second)
9945 appended (904 per second)
20163 deleted (1260 per second)
Deletion alone: 10326 files (10326 per second)
Mixed with transactions: 9837 files (894 per second)

Data:
557.87 megabytes read (34.87 megabytes per second)
1165.62 megabytes written (72.85 megabytes per second)

Even better.

Now here comes the part that I hoped would work better than it did:

OS X doesn’t support the TRIM command for SSDs yet (unless you have a really new Mac with an Apple SSD). Fortunately, some enterprising users found out that it is possible to turn TRIM on OS X. There are various ways to do it but someone already automated the process. Be sure to do a backup first (both system backup and through the TRIM enabler application).

The process does work. However, it seems it tries to run TRIM too aggressively, messing up with the random access optimizations some drives have.

Benchmark after TRIM enabled:

Time:
39 seconds total
31 seconds of transactions (645 per second)

Files:
20163 created (517 per second)
Creation alone: 10000 files (3333 per second)
Mixed with transactions: 10163 files (327 per second)
10053 read (324 per second)
9945 appended (320 per second)
20163 deleted (517 per second)
Deletion alone: 10326 files (2065 per second)
Mixed with transactions: 9837 files (317 per second)

Data:
557.87 megabytes read (14.30 megabytes per second)
1165.62 megabytes written (29.89 megabytes per second)

This kind of performance loss is unacceptable to me, so I restored the kext file through the TRIM app, rebooted and re-ran the benchmark and all was fine again.

My recommendations:

  1. Always test before and after the tweaks – my results may only apply to Intel drives. Please post your results with other drives
  2. Always do backups before serious tweaks
  3. If TRIM seems to slow down random I/O on your Mac SSD, don’t keep it running, maybe enable it once a month, go to disk utility, and ask it to erase the free space. This will ensure the drive stays in good shape without adversely affecting normal random I/O.

D

11 Replies to “OS X and SSD – tunings plus performance with and without TRIM”

  1. I bought the same drive for use in my MacBook Pro. My results are very similar to yours. I’m running with the TRIM hack, but may very well do what you are doing, and TRIM only occasionally.

    One thing I found that is interesting: Carbon Copy Cloner left the ownership of the root (/) directory on the SSD as owned by “bill” instead of root. This added a good 10-15 seconds to my boot times. It seems that some Mac OS X updates can change the ownership as well. By chowning it back to root, I cut the boot times down significantly. These are probably issues that one never notices with regular drives.

  2. Vertex2 LE results in older i7 Macbook Pro prior to tweaks:
    Time:
    15 seconds total
    10 seconds of transactions (2000 per second)

    Files:
    20163 created (1344 per second)
    Creation alone: 10000 files (2000 per second)
    Mixed with transactions: 10163 files (1016 per second)
    10053 read (1005 per second)
    9945 appended (994 per second)
    20163 deleted (1344 per second)
    Deletion alone: 10326 files (10326 per second)
    Mixed with transactions: 9837 files (983 per second)

    Data:
    557.87 megabytes read (37.19 megabytes per second)
    1165.62 megabytes written (77.71 megabytes per second)

    After tweaks:
    Time:
    14 seconds total
    9 seconds of transactions (2222 per second)

    Files:
    20163 created (1440 per second)
    Creation alone: 10000 files (2500 per second)
    Mixed with transactions: 10163 files (1129 per second)
    10053 read (1117 per second)
    9945 appended (1105 per second)
    20163 deleted (1440 per second)
    Deletion alone: 10326 files (10326 per second)
    Mixed with transactions: 9837 files (1093 per second)

    Data:
    557.87 megabytes read (39.85 megabytes per second)
    1165.62 megabytes written (83.26 megabytes per second)

    1. I’m also interested in the same tests, but in done in Lion. I suspect they’re the same.. but would be good to have some hard figures.

  3. FWIW (maybe a dead article?) – but thanks for the notes!

    mid-2012 MBP (hi-res non-glare); 2.6GHz; 16G RAM;
    Lion 10.7.4 (11E261) – fresh install on SDD rather than cloning, just for baseline. I did align vol1 to 512kb boundary.

    Crucial M4 512 in drive bay – registers as sata3/6G speed and no problems in ~30 hrs operation with several different stress tests and , firmware update this weekend). Apple 750G HDD still in place (will be removed next week for second M4). Yeah, I was quite literally cutting open the package when I started seeing reports about M4’s not working in the drive bays, but I decided to test it anyway.

    M4-CT512M4SSD2:

    Capacity: 512.11 GB (512,110,190,592 bytes)
    Model: M4-CT512M4SSD2
    Revision: 309
    Serial Number: xxx
    Native Command Queuing: Yes
    Queue Depth: 32
    Removable Media: No
    Detachable Drive: No
    BSD Name: disk0
    Medium Type: Solid State
    TRIM Support: (varied with run – see below)
    Partition Map Type: GPT (GUID Partition Table)
    S.M.A.R.T. status: Verified
    Volumes:
    disk0s1:
    Capacity: 209.7 MB (209,715,200 bytes)
    BSD Name: disk0s1
    Content: EFI
    vol1:
    Capacity: 511.25 GB (511,248,355,328 bytes)
    Available: 465.61 GB (465,611,137,024 bytes)
    Writable: Yes
    File System: Journaled HFS+
    BSD Name: disk0s2
    Mount Point: /
    Content: Apple_HFS
    Recovery HD:
    Capacity: 650 MB (650,002,432 bytes)
    BSD Name: disk0s3
    Content: Apple_Boot

    Constants:
    – noatime on all FS
    – RAM disk for /private/tmp and /private/var/run
    – HD mounted
    – Intentionally tested with moderate app load (same) – Firefox w/ 30 open tabs, parallels running Ubuntu, disk monitor and some other things, but nothing doing notable disk activity during the test. Three runs with TRIM, three without, these are the medians:

    — Testing w/ TRIM enabled

    pm>show
    Current configuration is:
    The base number of files is 10000
    Transactions: 20000
    Files range between 500 bytes and 97.66 kilobytes in size
    Working directory: /Users/kab
    Block sizes are: read=4.00 kilobytes, write=4.00 kilobytes
    Biases are: read/append=5, create/delete=5
    Not using Unix buffered file I/O
    Random number generator seed is 42
    Report format is verbose.
    pm>run
    Creating files…Done
    Performing transactions……….Done
    Deleting files…Done
    Time:
    21 seconds total
    18 seconds of transactions (1111 per second)

    Files:
    20163 created (960 per second)
    Creation alone: 10000 files (5000 per second)
    Mixed with transactions: 10163 files (564 per second)
    10053 read (558 per second)
    9945 appended (552 per second)
    20163 deleted (960 per second)
    Deletion alone: 10326 files (10326 per second)
    Mixed with transactions: 9837 files (546 per second)

    Data:
    557.87 megabytes read (26.57 megabytes per second)
    1165.62 megabytes written (55.51 megabytes per second)
    pm>pm

    — Testing w/ TRIM disabled

    pm>show
    Current configuration is:
    The base number of files is 10000
    Transactions: 20000
    Files range between 500 bytes and 97.66 kilobytes in size
    Working directory: /Users/kab
    Block sizes are: read=4.00 kilobytes, write=4.00 kilobytes
    Biases are: read/append=5, create/delete=5
    Not using Unix buffered file I/O
    Random number generator seed is 42
    Report format is verbose.
    pm>run
    Creating files…Done
    Performing transactions……….Done
    Deleting files…Done
    Time:
    9 seconds total
    7 seconds of transactions (2857 per second)

    Files:
    20163 created (2240 per second)
    Creation alone: 10000 files (5000 per second)
    Mixed with transactions: 10163 files (1451 per second)
    10053 read (1436 per second)
    9945 appended (1420 per second)
    20163 deleted (2240 per second)
    Deletion alone: 10326 files (10326 per second)
    Mixed with transactions: 9837 files (1405 per second)

    Data:
    557.87 megabytes read (61.99 megabytes per second)
    1165.62 megabytes written (129.51 megabytes per second)
    pm>

    — Original 7200rpm HDD was around 160 s, for baseline, but I didn’t save the results.

    enjoy!

  4. Hi

    Early 2009 17″ MBP with 480GB OWC electra 3G
    Time:
    11 seconds total
    7 seconds of transactions (2857 per second)

    Files:
    20163 created (1833 per second)
    Creation alone: 10000 files (5000 per second)
    Mixed with transactions: 10163 files (1451 per second)
    10053 read (1436 per second)
    9945 appended (1420 per second)
    20163 deleted (1833 per second)
    Deletion alone: 10326 files (5163 per second)
    Mixed with transactions: 9837 files (1405 per second)

    Data:
    557.87 megabytes read (50.72 megabytes per second)
    1165.62 megabytes written (105.97 megabytes per second)

    with the above tweaks:
    Time:
    10 seconds total
    8 seconds of transactions (2500 per second)

    Files:
    20163 created (2016 per second)
    Creation alone: 10000 files (5000 per second)
    Mixed with transactions: 10163 files (1270 per second)
    10053 read (1256 per second)
    9945 appended (1243 per second)
    20163 deleted (2016 per second)
    Deletion alone: 10326 files (10326 per second)
    Mixed with transactions: 9837 files (1229 per second)

    Data:
    557.87 megabytes read (55.79 megabytes per second)
    1165.62 megabytes written (116.56 megabytes per second)
    pm>

    with the above tweaks + TRIM enabled :

    Time:
    36 seconds total
    31 seconds of transactions (645 per second)

    Files:
    20092 created (558 per second)
    Creation alone: 10000 files (5000 per second)
    Mixed with transactions: 10092 files (325 per second)
    9935 read (320 per second)
    10064 appended (324 per second)
    20092 deleted (558 per second)
    Deletion alone: 10184 files (3394 per second)
    Mixed with transactions: 9908 files (319 per second)

    Data:
    548.25 megabytes read (15.23 megabytes per second)
    1158.00 megabytes written (32.17 megabytes per second)

    BTW To get permission to work on the noatime plist I had to use sudo chown with -R, is that still OK?
    Also you might want to show people where to drop the postmark executable and the correct usage for it.

    Cheers

  5. Macbook Pro i5 , Corsair Force 3PostMark v1.5 : 3/27/01
    pm>set buffering false
    pm>set size 500 100000
    pm>set read 4096
    pm>set write 4096
    pm>set number 10000
    pm>set transactions 20000
    pm>run
    Creating files…Done
    Performing transactions……….Done
    Deleting files…Done
    Time:
    13 seconds total
    9 seconds of transactions (2222 per second)

    Files:
    20163 created (1551 per second)
    Creation alone: 10000 files (5000 per second)
    Mixed with transactions: 10163 files (1129 per second)
    10053 read (1117 per second)
    9945 appended (1105 per second)
    20163 deleted (1551 per second)
    Deletion alone: 10326 files (5163 per second)
    Mixed with transactions: 9837 files (1093 per second)

    Data:
    557.87 megabytes read (42.91 megabytes per second)
    1165.62 megabytes written (89.66 megabytes per second)

Leave a comment for posterity...