Apr 202011
 

Firefox Cache

To disable the the Firefox cache on the disk (SSD) and move it to your RAM, follow these steps:

  • Go to about:config and set browser.cache.disk.enable to false
  • as well as browser.cache.memory.enable to true.

You can check what the cache is doing by going to about:cache

Set the noatime option on the root filesystem

Attention! This is an advanced topic! Do not engage in any activity if you’re not cool with the Unix command line and ready to do something to your Mac that Apple did not intend you to do! I’ve warned you.

You can run the following script on the terminal (don’t forget to make it executable beforehand using chmod +x AlwaysMountRootFSWithNoatime_MacOSX.sh) or copy it to your Terminal line by line (not recommended):

After running this script once (you need to enter your password), reboot.

Move /private/tmp, /var/run (not /var/db) to a ram disk

After running this script once (you need to enter your password), reboot.

To check if are actually using the ram disk, run the command mount in the Terminal.app where the output should contain something like

/dev/disk2 on /private/tmp (hfs, local, union, nobrowse)
/dev/disk3 on /private/var/run (hfs, local, union, nobrowse)

You can also run hdiutil info and get an output like this:

framework       : 289
driver          : 10.6v289
images          : 4
================================================
image-path      : ram://524288
shadow-path     : <none>
icon-path       : <none>
image-type      : <unknown>
system-image    : TRUE
blockcount      : 524288
blocksize       : <unknown>
writeable       : TRUE
autodiskmount   : false
removable       : TRUE
image-encrypted : <false>
mounting user   : root
mounting mode   : <unknown>
process ID      : <in-kernel>
/dev/disk2      /private/tmp
================================================
image-path      : ram://131072
shadow-path     : <none>
icon-path       : <none>
image-type      : <unknown>
system-image    : TRUE
blockcount      : 131072
blocksize       : <unknown>
writeable       : TRUE
autodiskmount   : false
removable       : TRUE
image-encrypted : <false>
mounting user   : root
mounting mode   : <unknown>
process ID      : <in-kernel>
/dev/disk3      /private/var/run

Disable Hibernation and delete the RAM image file

Every time your Mac is sent to sleep, it could store the content of your RAM in the file /var/vm/sleepimage. To prevent this and disable hibernation, do:

sudo pmset -a hibernatemode 0
sudo rm /var/vm/sleepimage

Disable waking up when LID opens

sudo pmset -a lidwake 0

Disabling Sudden Motion Sensor (If you don’t have any HDD left in your Mac)

sudo pmset -a sms 0

To check all the changes made using pmset, run:

pmset -g

Disable the swap files (virtual memory)

Paging is handled by a daemon called dynamic_pager. Turn this off with launchctl. I did not test the following, but it seems to be OK, to do it:

sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.dynamic_pager.plist
# reboot:
sudo shutdown -r now

resources

VN:F [1.9.22_1171]
Rating: 10.0/10 (2 votes cast)
SSD Optimizations on Mac OS X, 10.0 out of 10 based on 2 ratings

Related Posts:

  30 Responses to “SSD Optimizations on Mac OS X”

  1. Thank you for the good hints. Also good to move the /private/var/folders/ to Ramdisk.

    Cheers

    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
  2. […] SSD Optimizations on Mac OS X » Philipp Klaus’s Computing Blog. […]

  3. Great RAM disk script!

    I’ve got /private/tmp mounting but /private/var/run still doesn’t mount.. any ideas? I’m running OS X Lion

    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
    • Sorry, I can’t help as I didn’t switch to Lion so far. Maybe you can get hints to the solution in one of the two blog posts on nullvision.com. If you have a solution to the problem, I would like to hear about it. Thanks, Philipp

      VN:F [1.9.22_1171]
      Rating: 0 (from 0 votes)
    • Had the same problem with mounting /private/var/run on Lion. I tried to figure out the reason of this strange behavior: I logged ‘mount’ and ‘hdiutil info’ output after each RAMDisk() function execution and 64M /private/var/run ramdisk was successfully created, but every time it disappeared after login. I tried to increase the disk size up to 128M and it worked! But I have no idea why.

      VA:F [1.9.22_1171]
      Rating: 0 (from 0 votes)
    • I inserted a “sleep 1″ after each RAMDisk call and it works fine for me now. The script seems to be running too fast for its own good ;-)

      StartService () { ConsoleMessage “Starting RamFS disks…” RAMDisk /private/tmp 256 sleep 1 RAMDisk /var/run 64 sleep 1 #RAMDisk /var/db 1024 #mkdir -m 1777 /var/db/mds

      }

      VA:F [1.9.22_1171]
      Rating: 0 (from 0 votes)
      • Zak’s insertion of ‘sleep 1′ after each RAMDisk call fixed the mounting of /var/run as a ramdisk on my Mac as well. I’m currently running Mavericks 10.9.3..

        Cool beans :).

        VA:F [1.9.22_1171]
        Rating: 0 (from 0 votes)
        • Here’s an update. Strangely, the ‘sleep 1′ after each RAMDisk call only seemed to work the one time. After some investigation, the only change that seems to be needed is to insert a ‘sleep 1′ after the hdik -drivekey.. line.

          My theory is that after the hdik command is executed, there’s a small time window during which things are not entirely in sync. The ‘sleep 1′ gives the system enough time to get in sync with itself..

          In any case, I’ve just restarted my computer 3-4 times in a row and the /var/run has been properly mounted as a ramdisk each time.. so it’s looking good at this point..

          Create the RAM disk.

          dev=`hdik -drivekey system-image=yes -nomount ram://$rdsize`
          # this sleep seems to be needed in order for /var/run to be mounted consistently/succesfully.
          sleep 1
          # Successfull creation...
          
          VA:F [1.9.22_1171]
          Rating: 0 (from 0 votes)
        • Basically, someone else (on this page) suggested inserting a ‘sleep 4′ before creating any of the ramdisks. This seemed to work pretty well for me and less complicated than inserting a bunch of ‘sleep 1′ in various places.

          See my comment (search for ‘sleep 5′ on this page) to see where to insert the ‘sleep 5′ statement.

          So far, it’s been solid with my ssd drive, in terms of creating the ramdisks reliably..

          VA:F [1.9.22_1171]
          Rating: 0 (from 0 votes)
  4. I added /private/var/folders by editing the RamFS shellscript in /system/library/startupitems – placing the line RAMDisk /var/folders 256 under the other RAMDisk lines in Startservice()

    For good measure I added # diskutil unmount /private/var/folders to Stopservice() even though its hashed out!

    VA:F [1.9.22_1171]
    Rating: +1 (from 1 vote)
    • Hi Sam, thanks for your feedback. /private/var/folders should be put into the ram filesystem too, I agree. If I find the time in the next hours/days, I will update the setup script in the post. Philipp

      VN:F [1.9.22_1171]
      Rating: 0 (from 0 votes)
  5. […] SSD 以后的优化从 jjgod 的文章出发,找到了这一篇,现在把 ~/Library/Caches 放在 ramdisk 上(我有 8G 内存,用 1G 做了 […]

  6. It appears the Mac App Store (at least in Lion) uses /private/var/folders to store application installers temporarily. I got insufficient space errors with /private/var/folders on the RAM disk. Instead, I made a symbolic link for this folder to my hard disk.

    In addition to /private/tmp and /var/run, I added /var/audit, /var/log, /var/tmp, and /Library/Logs.

    Also, with each boot, sometimes not all RAM disks are created. Sometimes I get all of them; sometimes I don’t. Like Mike indicated above, I was also seeing /private/var/run not mount, but sometimes it does mount. The same goes for the others. Maybe it is a timing issue?

    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
  7. Hi there,

    I wanted to say thanks for the article! I’ve been putting some of these tips into action. However, I have a few concerns over the use of RAM disks to replace folders.

    Now, obviously RAM disks are volatile so any time you restart the contents are cleared. As a result, anyone that restarts their machine regularly may find that the use of RAM disks is a bad idea. While they should be fine to use for /private/tmp and /var/run, I think that /var/folders and /var/db should be left persistent, as this will avoid the need to re-cache their contents, which could easily give slower startup times.

    Fortunately, it’s fairly easy to modify the RAM disk script by creating a separate start-up item for these folders. In this case, instead of using hdik to create a RAM disk, use it to create a regular disk image on another drive (if it doesn’t already exist). You can then follow the other steps as provided, in which case you will be mounting a persistent disk image in union with /var/folders and /var/db, which will allow their contents to persist without being written to your SSD. For laptop users or others with only an SSD, then the other option is to use the RAM disk, but use rsync to copy the contents somewhere on shut-down/restart/sleep (I think you need a tool that monitors for these conditions), this way when you re-create the RAM disk you can rsync from this location, allowing the contents to persist, but only writing to your SSD once per session.

    Anyway, as mentioned, it isn’t clear what /var/folders is actually used for, which makes sizing a disk image a bit of a tricky proposition. For this reason I’d recommend against using a RAM disk for it, as you could need an inordinate amount of RAM to actually use it. The best option with regards to /var/folders is petition Apple to get rid of it, as I can’t fathom for the life of me why they aren’t using /Library/Caches or ~/Library/Caches as appropriate, or just using more common locations like /private/tmp.

    VA:F [1.9.22_1171]
    Rating: +1 (from 1 vote)
  8. Hi,

    I am looking for ways to minimize/reduce write access to SSD and found this great article. I have a macbook with 2 disks: OSX system volume on SSD and data on magnetic. I applied most hints here, however it seems the SSD disk still has regular write access, caused mostly by files under /private/var/{db,log,folder}. I wonder it is possible to move the whole /private/var to another partition on the magnetic disk? I would appreciate any relevant information.

    thanks, Tony

    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
  9. What size will be perfect for my MBA 2.1 with 2gig ram and 128GB Apple SSD. And by the way in system profiler Trim is off for my SSD, and TrimEnabler does not fix it.

    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
  10. […] This tweak was taken from blogs.nullvision.com, which seems to not be available anymore, but I found a mirror of the old content here: http://www.icyte.com/saved/blogs.nullvision.com/441781 And the same trick (inspired by the same blog) is here: http://blog.philippklaus.de/2011/04/ssd-optimizations-on-mac-os-x/ […]

  11. I have tried with large ramdisk size, say “RAMDisk /private/tmp 2048″, but it won\t work any more. Is there any size limit for a RAMDisk??

    I am using Mountain Lion on MBA with 8G mem.

    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
  12. How do you disable mounting of /private/tmp to RAM-disk? I’ve found that using it gives error when trying to install git from HomeBrew.

    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
  13. […] This tweak was taken from blogs.nullvision.com, which seems to not be available anymore, but I found a mirror of the old content here: http://www.icyte.com/saved/blogs.nullvision.com/441781 And the same trick (inspired by the same blog) is here: http://blog.philippklaus.de/2011/04/ssd-optimizations-on-mac-os-x/ […]

  14. Can you please update the script for mountain lion? I believe hdik needs to be replaced with hdutils etc. Thanks!

    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
  15. Hi,

    Thanks for the script. Considering the ramfs mounts, considering a fix another guest suggested: adding a sleep, I added a “sleep 4″ before running any of (and not each) the RamFS calls and it works for me.

    I printed “mount” during the scripts and the disks+mounts are actually created but for some reason they dissapear by the time the boot finishes. running the whole thing “later” seems to help. Probably there’s a smarter solution than “sleep “. I also tried 1 and 2 and it was not OK.

    VA:F [1.9.22_1171]
    Rating: +1 (from 1 vote)
    • adding the ‘sleep 4′ (actually, I changed it to ‘sleep 5′ to hopefully make it more robust) seems to work fairly well for me.

      StartService () { /usr/bin/logger “creating ramdisks..” sleep 5 RAMDisk /private/tmp 512

      VA:F [1.9.22_1171]
      Rating: 0 (from 0 votes)
  16. 256M for /private/tmp is too small for installing MS Office updates past 14.2.1. I don’t know the minimum size necessary. I increased it to 512M and was able to install.

    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
  17. Hi, Philip. I’m having trouble finding other sources to reference the arguments in defining the RAM parameters in the earlier fields, such as…

    RAMDisk() {
        mntpt=$1
        rdsize=$(($2*1024*1024/512))

    In my case, I have 16GB of RAM in my laptop and would like to create two 2GB RAM disks upon startup. Would I change the rdsize=$(($2*8192*8192/2048)) ?

    Then for the lower argument, I have two questions:

    StartService () {
        ConsoleMessage "Starting RamFS disks..."
        RAMDisk /private/tmp 256
        RAMDisk /var/run 64
        #RAMDisk /var/db 1024
        #mkdir -m 1777 /var/db/mds

    Would mine need to look like:

    StartService () {
        ConsoleMessage "Starting RamFS disks..."
        RAMDisk /private/tmp 2048
        RAMDisk /var/run 64
        #RAMDisk /var/db 8192
        #mkdir -m 1777 /var/db/mds

    Can you help explain if my logic would be correct or incorrect as I’ve configured it thus far? And does the 64 account for 64k data sets being written to the RAM from the disk? What if I had a RAID with 32k sets written across them? Would I change this to 32 or allow the redundancy to resolve against 64?

    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
    • Wow my copy and paste did not translate whatsoever!!! considering I have 16GB of RAM, would I need to set the rdsize for 2×8192 before declaring the allocation fields (parameters)? rdsize=$(8192x8192x2/2048) …

      VA:F [1.9.22_1171]
      Rating: 0 (from 0 votes)
  18. First, I tried the noatime tweak here: http://blog.alutam.com/2012/04/01/optimizing-macos-x-lion-for-ssd/ Testing if it worked witht he code mount | grep ” / ” returned /dev/disk0s2 on / (hfs, local, journaled) instead of /dev/disk0s2 on / (hfs, local, journaled, noatime)

    Then, used your noatime tweak, the testing code returned the same message

    Any advice?

    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
  19. I wold like to put name to the untitled folder, I also add RAMDisk /Volumes/Data/Users/xxx/Library/Caches 1024.

    Thanks

    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)
  20. Thanks for this tutorial, I followed all the steps, but not being accustomed to shell script, I discovered a new App “RAMDisk Manager” we can easily move “T” and another folder to RAM Disk. http://www.macupdate.com/app/mac/51310/ramdisk-manager

    VA:F [1.9.22_1171]
    Rating: 0 (from 0 votes)

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>