SSD Optimization for Mac OS

SSD Optimization for Mac OS

Here are a few tricks to squeeze the absolute best performance out of your SSD on a Mac OS.

 

Do not run benchmarks on your new SSD

 

New SSD owners, right after they buy a new SSD, want to enjoy the speed and are eager to find out how much faster their new solid state drive is than the old hard drive. So in order to see the difference some people run extensive benchmarks to see the amazing performance numbers. Benchmarks usually write a lot of data to the disk (to test the write speed), and can wear out the drive. So it is the best way to ruin your SSD even before you start using it. It is recommended that benchmarks are not run on your SSD.

 

Use Trim Enabler

 

 

 

 

 

 

 

 

 

 

 

 

 

TRIM support is essential for keeping the SSD healthy. Unfortunately Mac OS supports TRIM only for Apple-supplied SSDs. If you bought a 3rd party one like I did, you have to tweak the system in order to turn on the TRIM support. Or you can download Trim Enabler, which is a simple, free utility that does this for you.  Trim Enabler is a free tool, that allows TRIM support to be added to all SSDs running Mac OS X 10.7.2 and 10.6.8. The newest version of the utility works by patching a kernel extension, and also includes some SMART data to check the health of the SSD drive.

Turn off local Time Machine snapshots  [laptops only]

Time Machine in Mac OS X Lion initiates a sometimes useful, but sometimes unnecessary feature called: local backups. These local backups are also called snapshots and are created when your primary Mac is a laptop and the Time Machine backup is an external drive.  OS X Lion does local snapshots at times when your Time Machine disk is not available.  OS X Lion compensates for the potentially unavailable external disk by keeping an additional backup locally on the Mac’s primary hard drive. This has its obvious advantages, since you can restore to past Time Machine backups right away from anywhere, but if you’re trying to conserve disk space such as when you have a limited space on a SSD, this can be a real pain.

Note: Time Machine local backups are only stored if you have Time Machine enabled in general.

 

You can confirm if the local TM backups are on by opening Time Machine Preferences:

 

 

 

 

 

 

 

 

 

 

 

There is no GUI switch to turn these local backups off, but it can easily be done on the command line. Just start Terminal.app and execute the following command:

Disable Time Machine Local Backup Storage via Terminal

 

Here’s how to turn off local backups:

  • Launch Terminal from /Applications/Utilities
  • Enter the following command:

sudo tmutil disablelocal

  • Enter the admin password when requested to disable local backups

Re-Enable Local Time Machine Backups via Terminal

 

The steps are the same as above, except with the following command entered into the Terminal instead:

sudo tmutil enablelocal

 

This feature gets turned on automatically whenever you turn the Time Machine off and on – so do not forget to turn the local backups back off again whenever you do that.

Remember, if you disable this feature you will not have local backups anymore, so if something goes wrong you will be out of luck. It’s important to have regular backups of your data, and so if you’re going to disable local backups be sure to still use Time Machine, perhaps even initiating a manual backup before you disconnect the drive, in order to preserve a recent copy of your data.

Turn off hibernation [laptops only]

 

Another default Mac OS feature on laptops is hibernation.  This feature saves all the memory to the hard disk when entering sleep mode. This ensures your laptop does not lose your data if it runs out of battery while it is “sleeping”.

 

Solid state drives are based on NAND Flash technology which has a limited writes life. Currently 25nm chips support 3000-5000 cycles then they become read only.  With this limitation it is very important to avoid unneeded writes on the drive.

 

Here is how you can turn the hibernation feature off – it will not only make your SSD’s life longer, but also significantly speed up the time it takes for your laptop to enter the sleep mode:

  1. open terminal app and type:

sudo pmset -a hibernatemode 0

 

Enter an admin password and this will prevent GBs of writes every time you close the lid of your notebook or put your computer to sleep.

  1. Once you turn off hibernation, you can also remove the sleep image file and that will free up several GBs of disk space (depending on how much RAM you have).  Removing unused hibernation files will free up as much space as your RAM:

sudo rm /var/vm/sleepimage

Set noatime flag

 

Mac OS (like other unix-based systems) by default records last access time for every file.  So that every time you read a file, a write is made on the filesystem to record this action.  There is no point in doing it and there are no side effects if you disable that by mounting the root filesystem with noatime flag set, this speeds up the performance of your SSD.  Noatime is used to reduce the number of write actions on the disk.

First open an XML editor to create a plist, and add the following XML code:

 

Create com.whatever.noatime.plist in /Library/LaunchDaemons

 

 

 

 

 

 

 

 

 

 

 

And execute the following command in Terminal:

sudo chown root:wheel /Library/LaunchDaemons/ com.whatever.noatime.plist

Then restart the computer.

 

You can verify that it worked by executing the following in Terminal:

mount | grep ” / ”

 

You should get the following output (i.e. see noatime in the list in parentheses):

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

Move user home directories to HDD [SSD+HDD only]

 

This tweak is only useful if you have both SSD as well as HDD in your Mac.  This configuration modification was explained in detail on a previous article however this is a command line implementation of this step.  All the content of /Users folder should be on the HDD and there should be a symbolic link from the SSD to it, this is so that home folder location in the user settings do not need to be changed, some applications do not like that and may not work correctly.  To do this, execute the following commands in Terminal:

sudo ditto /Users /Volumes/your_hdd_name/Users

sudo mv /Users /Users.bak

sudo ln -s /Volumes/your_hdd_name/Users /Users

 

To be safe, you should also go to System Preferences, click on Users & Groups, click the lock icon to unlock advanced editing (a password prompt will appear). Once unlocked, you should be able to right-click on each user account and choose Advanced Options from the pop-up menu. Once in the Advanced Options dialog, change the Home directory of the user from “/Users/user-name” to the new location (e.g. “/Volumes/HDD/Users/user-name”).

Now, check if your home folders are showing up correctly in Finder. If so, restart your computer.

Finally, delete the back-up of your Users folder on the SSD by typing the following into the Terminal:

sudo rm -rf /Users.bak

Use RAM disk or HDD for temporary files

 

If you have enough RAM in your computer, you can dedicate typically around 256 to 512 MB of RAM to a RAM disk. RAM disk is a virtual disk that only resides in memory, so it is suitable for storing data that needs to live only until you shut down your computer. Temporary files are ideal for this. You can create a RAM disk during the boot time and redirect all the temporary files there.

 

 

 

 

 

 

 

 

 

 

 

If you want to quickly make a RAM disk for use on your Mac, you could create one manually through the command line, or you can make it even easier by downloading TmpDisk for Mac OS X. The open source application uses a menu bar item to quickly make RAM disks of any size, from anywhere.  The only restraint is that you need to have the physical memory to be able to accommodate the disks creation.

  • Download TmpDisk now (direct dmg link)
  • Put this app into your /Applications/ folder and launch it to see the little disk icon in your menu bar, click on that and choose “New TmpDisk”, specify a size, and a RAM disk is created instantly on the Mac desktop, ready for use.

 

RAM disks are temporary so you won’t want to place anything intended to be permanent there, but for cache files, photo and video editing, and anything else that you want absolute maximum speeds from, RAM disks are the best. Just remember to copy your files out of the temporary disk before you reboot or eject the drive so you do not lose anything.

 

To manually create a RAM disk in Terminal, follow these steps:

 

Create a file named “MoveTempFoldersToRamDisk.sh” in your home directory and put the following content in:

 

#!/bin/bash

cd /System/Library/StartupItems

sudo mkdir RamFS

sudo chown -R root:wheel RamFS

sudo chmod -R u+rwX,g+rX,o+rX RamFS

cat << “EOF” | sudo tee RamFS/RamFS > /dev/null

#!/bin/sh

# Create a RAM disk with same perms as mountpoint

RAMDisk() {

mntpt=$1

rdsize=$(($2*1024*1024/512))

echo “Creating RamFS for $mntpt”

# Create the RAM disk.

dev=`hdik -drivekey system-image=yes -nomount ram://$rdsize`

# Successfull creation…

if [ $? -eq 0 ] ; then

# Create HFS on the RAM volume.

newfs_hfs $dev

# Store permissions from old mount point.

eval `/usr/bin/stat -s $mntpt`

# Mount the RAM disk to the target mount point.

mount -t hfs -o union -o nobrowse $dev $mntpt

# Restore permissions like they were on old volume.

chown $st_uid:$st_gid $mntpt

chmod $st_mode $mntpt

fi

}

# Test for arguments.

if [ -z $1 ]; then

    echo “Usage: $0 [start|stop|restart] ”

exit 1

fi

# Source the common setup functions for startup scripts

test -r /etc/rc.common || exit 1

. /etc/rc.common

StartService () {

ConsoleMessage “Starting RamFS disks…”

RAMDisk /private/tmp 256

RAMDisk /var/run 64

#RAMDisk /var/db 1024

#mkdir -m 1777 /var/db/mds

}

StopService () {

ConsoleMessage “Stopping RamFS disks, nothing will be done here…”

# diskutil unmount /private/tmp /private/var/run

# diskutil unmount /private/var/run

}

RestartService () {

ConsoleMessage “Restarting RamFS disks, nothing will be done here…”

}

RunService “$1″

EOF

sudo chmod u+x,g+x,o+x RamFS/RamFS

cat << EOF | sudo tee RamFS/StartupParameters.plist > /dev/null

<?xml version=”1.0″ encoding=”UTF-8″?>

<!DOCTYPE plist SYSTEM “file://localhost/System/Library/DTDs/PropertyList.dtd”>

<plist version=”0.9″>

<dict>

<key>Description</key>

<string>RamFS Disks Manager</string>

<key>OrderPreference</key>

<string>Early</string>

<key>Provides</key>

<array>

<string>RamFS</string>

</array>

<key>Uses</key>

<array>

<string>Disks</string>

</array>

</dict>

</plist>

EOF

 

After running this script it will prompt you to enter and password, then you will need to reboot your computer.

Now, run the following in the Terminal:

chmod 755 ~/MoveTempFoldersToRamDisk.sh

~/MoveTempFoldersToRamDisk.sh

 

This creates two RAM disks on startup – one 256MB large for /private/tmp (command “RAMDisk /private/tmp 256″ in the middle of the above script) and another one 64MB large for /var/run. You can now delete ~/MoveTempFoldersToRamDisk.sh from your computer.
Remember to restart your computer in order for the changes to take effect.

 

If you decide to undo this tweak in the future, you can do it simply by deleting /System/Library/StartupItems/RamFS directory from your Mac by executing the following command in the Terminal:

sudo rm -rf /System/Library/StartupItems/RamFS

 

A restart is needed for this to take effect.

There are some small drawbacks to applying this tweak:

  • After applying, the computer takes a few seconds (2-3 on my machine) to shut down
  • It lowers the size of RAM usable for applications

 

If you are bothered by the above and have HDD in your Mac as well, you can consider moving the temporary files to HDD instead of the RAM disk. The steps are similar to moving the user home directories.

To move /private/tmp, execute the following in the Terminal:

sudo ditto /private/tmp /Volumes/your_hdd_name/private/tmp

sudo rm -rf /private/tmp

sudo ln -s /Volumes/your_hdd_name/private/tmp /private/tmp

 

If you have a SATA 2 interface and a Nvidia chipset on your Mac, check to make sure you have 3 Gbps Negotiated Link Speed.
Go to Serial-ATA section in System Information app to take a look of your disk(s).
This will ensure optimal performance of SSD.

Turn off sudden motion sensor [no HDD only]

 

The Sudden Motion Sensor is designed to protect your Macs hard drive in case your computer experiences being dropped or an unusually strong vibration. This feature parks the hard drive head when movement is detected. This prevents the hard drive head from scraping across the disk surface and scratching or damaging the drive or drive head.  If a SSD is the only drive in your Mac, there is no point in using the Sudden Motion Sensor. You can switch it off by executing the following in the Terminal:

sudo pmset -a sms 0

Turn off hard drive sleep [no HDD only]

 

Some websites mention SSD may freeze when the hard drive sleep feature is on, so it is recommended to turn it off. However, this is not necessary if you also have a secondary mechanical hard drive in your Mac. To turn the hard drive sleep off, open System Preferences and go to Energy Saver, then uncheck ‘Put the hard disk(s) to sleep when possible’ for both the Battery and Power Adapter tabs.  This will prevent disk freezes and beach balls.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

These fine tuning measures will allow your SSD in your Apple computer to run at an optimal performance level.

 

Speak Your Mind