I have 6GB on my old Macbook, with an SSD. I would like to avoid writing to the swap file as much as possible. Ever since my upgrade, I have always had at least 1 to 1.5GB memory "free". Yet, I have always had 2 to 25MB of used swap space. (Out of 128MB total) How do I get this to be 0MB swap used unless I run out of "free" memory?

On Linux, there is now a "swappiness" parameter that controls the tendency to use swap. I'd like to crank OS X's "swappiness" down very very low, but not deactivate swap entirely. I'd like to know that my machine will just run slower if it ever runs out of memory instead of having a kernel panic. I'm pretty close to where I want to be, but I'd like to get rid of these writes to a large file that (slightly) shorten the life of my SSD while doing me no benefit whatsoever.

  • It's understood you do what you want, and you're asking for an answer to this question — I won't contest this. However, I think it is important to make it clear for less technical-savvy users: the fact that your system is swapping, especially on such a little amount, is not a problem at all, not necessarily a source of sluggishness, and even the opposite. The OS can decide some memory parts won't be accessed and it's more effective to preemptively free some blocks in RAM and get extremely unlikely cache misses. OS X is very good at this (see RAM usage of hidden apps). – MattiSG Nov 18 '11 at 15:33

I'm not sure that a swap file of 2MB to 25MB is really something to worry about. It might be more useful to look at the values for Page In and Page Out to determine how often data is being written to the swap. The number of page events can be found using the System Memory tab of the Activity Monitor application.

There are a couple of other options that you could try but I think you're probably way out of warranty if you try:

I would just suggest putting up with the existing system since the wear on your SSD is probably minimal especially since SSD wear is a bit of a myth anyway or maybe it's not.

  • Thanks, but if you re-read my question, you'll find that there are actually two files 64MB each. It's not just 2 to 25MB. It's 128MB total swap and 2 to 25MB usage. What I find annoying, is that the total swap varies between 64 and 128MB. This would seem to indicate that the 2nd swap file is being deactivated then recreated. That's a lot of disk use for nothing. I already knew of the two system mods you suggested, and indicated that I didn't like the 1st one. The 2nd one, I find to be not well engineered. – StCredZero Feb 16 '11 at 23:19
  • This is your answer. Disabling the dynamic pager can really help but you truly run the risk of causing apps to go belly up when you run out of ram. If actually running out of memory isn't an issue for you then don't worry. – Dustin Nov 18 '11 at 14:31
  • The first link is dead. – kenorb Jul 21 '16 at 16:44
  • 1
    I've fixed the broken link.... although this answer is now 5 years and almost 6 macOS versions out of date. – Mike Meyers Sep 6 '16 at 4:17

For temporary solution, you can run sudo purge to force disk cache to be flushed and emptied which may reduce the swappiness a bit (if you had several large swap files in /private/var/vm, e.g. I've got 17G of them at the time of writing). If won't work, remove the files manually, they would be recreated.

You can also disable dynamic pager (swap daemon), so run in Terminal (restart is required):

sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.dynamic_pager.plist

To re-enable:

sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.dynamic_pager.plist

Unfortunately in the latest OS X you've to also disable SIP (System Integrity Protection) which is actually not recommended. See: How do I disable System Integrity Protection (SIP) AKA "rootless" on OS X 10.11, El Capitan?

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .