Home > software > MacBook Pro SSD tuning

MacBook Pro SSD tuning

January 21st, 2011 Leave a comment Go to comments

As I only use my mac for work/programming/something stuff I chose a SSD (128GB) as storage and upgraded just yesterday from 4 to 8GB of RAM. The following is list of steps I made to maximize IO capabilities and to minimize the SSD usage to prolong its lifetime.

Hint: if something should fail, rebooting into single user mode always works (press command+s during boot). There you can simply rename the RamFS script described below to switch off all changes i describe in the following . . .

noatime

Its common knowledge in linux userland that noatime helps to reduce IO as per default on each access of a file the last-access-timestamp has to be renewed. So each read on a file creates a write – noatime (no access time) prevents the write.

Activating that for the disks is done by adding a launchdaemon-script named:

/Library/LaunchDaemons/gpl.selfmade.noatime.plist

< ?xml version="1.0" encoding="UTF-8"?>
< !DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" 
        "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>Label</key>
        <string>gpl.selfmade.noatime</string>
        <key>ProgramArguments</key>
        <array>
            <string>mount</string>
            <string>-vuwo</string>
            <string>noatime</string>
            <string>/</string>
        </array>
        <key>RunAtLoad</key>
        <true />
    </dict>
</plist>

Just to be sure:

sudo chown root:wheel /Library/LaunchDaemons/gpl.selfmade.noatime.plist

After rebooting a “mount” should show that the additional noatime-flag is now active.

RamFS

The most useful thing to me having 8GB of RAM is working on a RamFS and thus having low latency while developing/compiling (using a local GIT to not loose work on power outage is crucial here). This is what has to be done:

Create a Folder and a file both named RamFS and set access rights accordingly

cd /System/Library/StartupItems
mkdir RamFS
sudo chown -R root:wheel RamFS
sudo chmod -R u+rwX,g+rX,o+rX RamFS
cd RamFS
touch RamFS
sudo chmod u+x,g+x,o+x RamFS

This is my actual version of the RamFS script:

#!/bin/sh
# Create a RAM disk with same perms as mountpoint
 
RAMDisk() {
    mntpt=$1
    rdsize=$(($2*1024*1024/512))
    echo "Creating RamFS for $mntpt of size $rdsize 512byte blocks"
    # Create the RAM disk.
    #dev=`hdik -drivekey system-image=yes -nomount ram://$rdsize`
    dev=`hdid -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 4096
#    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"

We also need a plist-file called “StartupParameters.plist” in that very folder:

< ?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>

If you want to use less than 2GB for the ramdisk please switch the dev line to hdik which is the much more lightweight way of mount the ramfs – i want to have a 3-4GB ramdisk which is something hdik cant do do i reverted back to the old hdid.

The flag nobrowse of mount makes sure i dont see the mountpoint in finder and on the desktop while union merges files already in the folder when the ramdisk is created (for deamons that created pidfiles etc earlier in the boot process)

I have a folder called Software in my home were i keep all my (software)projects. The tmp-folder there actually links to the ramdisk at /private/tmp via a softlink. I use that tmp for buildfiles, caching and so on.

If you use macports (as i do) it might also be a good idea to replace
/opt/local/var/macports/build
and
/opt/local/var/macports/distfiles
with softlinks to /private/tmp. Keep in mind that your ramdisk must be sufficient to hold the tar.gz, the unpacked sources as well as all the buildfiles for this to work. As an example, the gcc4.4.5 uses around 2.9GB . . .

I also think about moving ~/Library/Caches to the ramdisk, maybe creating an own ramdisk for that purpose.

If you have more ideas let me know in the comments . . .

Categories: software Tags: , ,
  1. bert
    January 22nd, 2011 at 14:47 | #1

    For linux, that would be:

    $ echo "tmpfs /tmp tmpfs defaults,noatime,mode=1777 0 0" | sudo tee -a /etc/fstab

    The default is to take at most 50% of your physical RAM. You can add a size=(%|bytes) parameter after the mode= to change this.

    Setting up any symlinks is left as an exercise to the reader.

  2. Frank
    April 21st, 2012 at 15:18 | #2

    Nice work, man !

  3. Diogo
    May 26th, 2015 at 11:54 | #3

    Hey ,

    Is this still usefull for Yosemite ? (i believe so , if it is to save life of my ssd :D) in case yes could anyone help me because i have all permissions ok files in the /System/Library/Startupitems but after reboot i go check diskutil list and i don’t see any ram disk being created.
    I belive the StartupItems are not working in Yosemite … :S or maybe something is missing on the StartupParameters.plist to make it work on Yosemite.

  4. Diogo
    May 26th, 2015 at 12:01 | #4

    Ok i belive i found some answers here, ” https://developer.apple.com/library/mac/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/StartupItems.html” why StartupItems does’t work anymore :

    “Deprecation Note: Startup items are a deprecated technology. Launching of daemons through this process may be removed or eliminated in a future release of OS X.
    Unless your software requires compatibility with OS X v10.3 or earlier, use the launchd facility instead. For more information, see Creating Launch Daemons and Agents.”

  1. November 18th, 2011 at 00:22 | #1