You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Over 3GB of swap files with 16GB of RAM?

Just bought a MBPr with 16gb of RAM (more for futureproofing than any actual need right now). I'm constantly checking Activity Monitor and "Free RAM" is always around 8GB or more. I notice, however, that the "Swap used" totals are quite high. I don't have any pageouts so why do I have so much swapspace being consumed? With an SSD drive in here, should I not be worried that the OS is using swapspace so much when it probalby doesn't need to?


Thanks!

MacBook Pro (Retina, Mid 2012), OS X Mountain Lion

Posted on Jul 31, 2012 6:44 PM

Reply
Question marked as Top-ranking reply

Posted on Aug 2, 2012 4:42 PM

So I loaded up all my big memory users. I upped VBox's VM usage to 2GB to help speed along the process.


I've been checking Activity Monitor regularly and the free mem has not once gone below 8GB (big green part of the pie).


Just now I woke my MacBook from sleep and it hung for about 30 seconds. I checked the /var/vm folder and there are tons of swapfiles that were seemingly just created at that instant.


Wonder what's going on. It's fair to say the last time I used my MacBook there were no swapfiles.


Free memory has always been super high.

User uploaded file

73 replies

Aug 29, 2012 12:28 AM in response to megagram

I have the same issue, 3GB swap file with 0 page outs. I have 16GB ram on the new mbpro retna display running Mt Lion.

I may change the hibernate settings as has been suggested here.

This is the only OS I've ever seen that builds a large swap file with 0 page outs and lots of free ram... My unix system tuning background says vm bug... Apple needs to fix it.

Aug 30, 2012 5:44 AM in response to MacJonny

You have provided slightly more technical detail than I did about he power management settings.


However, you are incorrect that standby mode should cause the system to write its active memory to swap. This is patently false. Upon hibernation, the mac writes out the contents of its RAM to /var/vm/sleepimage. If you place your Mac in standby mode, you will see this file created after you've woken it up. The system writes out the RAM to this file in its entirety, and restores it again once you wake the computer up. This is not the same as the swapfile(s), which are where the system stores memory that it cannot or does not want to store in main memory.


This writing to swap in addition to writing to sleepimage is exactly what our problem is, and it is definitely either a bug or an undocumented behavior that is not normal.

Aug 30, 2012 8:13 AM in response to nalundgaard

Nalundgaard, you are absolutely right!

I was mistakenly referring to swap and sleepimage as the same thing.


However, the fact remains that all my experiments show that after disabling standby and restarting,

No matter how long the mac has slept, the swap files do not take up all the space anymore.


I use istat pro to check the size of swap easily.


Can someone else please confirm. Disable standby, restart, let it sleep for at least 70 mins and then check whether the swap is huge again.


All my experiments show that it does not come back.


This has solved the huge swapfile issue for me.

Aug 31, 2012 4:41 PM in response to nalundgaard

can I just ask what the benefit of hibernate mode 0 is if you already disabled standby? this puts you at risk of losing everything if you have sudden loss of power... (not likely on a laptop but what if you are at 5% and leave the mac running? eg.)


I only disabled the standby mode without changing hibernate mode and feel it solves everything.


Regarding the swap file my theory is that it saves the contents of wired memory there in order to be able to quickly transfer them into the sleepimage upon entering standby. that way it does that faster.


If you do some experiments you will see that the size of the swapfile is about the same size as the memory you have wired before you sleep your mac as i mentioned before.

I cannot be sure but it seems like a plausible explanation.


Anyway, glad we solved this... now if I could get a MBP without IR problems i would be a happy camper.

Sep 2, 2012 10:49 AM in response to MacJonny

There is one benefit to hibernatemode 0, and that is that your system will never write /var/vm/sleepimage, which is how it stores your memory state. The file is the size of your RAM (in my case, 16GB) and can be a significant consumer of disk space of you only have a 256GB SSD in your MBPR. Also, writing out your system memory to the SSD every time your put your Mac to sleep causes significant additional write cycles on your SSD and may shorten its life. I am not sure to what degree this is a concern.


Having said that, you're right that using hibernatemode=3 (and maybe 25, I haven't tried it) and standby=0 is another method of avoiding the unregistered pageouts—with the above caveat that you'll be losing space on your hard drive in the amount of your RAM size, etc. So I owe you an apology for misunderstanding the difference between what you were doing and what I was doing. I didn't read your post thoroughly enough and I apologize for that. It's clear there are two solutions to the problem with different tradeoffs. Hibernatemode 0 frees more disk space and reduces SSD write cycles, but if your battery dies while the laptop is asleep, you lose whatever was in your RAM. Hibernatemode 3 and standy 0 causes more disk usage and more SSD writes, but if your battery dies, you will still recover your RAM from disk and be able to pick up where you left off rather than have a forced reboot. Both solutions, though, prevent the writing to the pagefile.


So, that's cool.


I also went and read the manual page for pmset in more detail after re-reading your original post more carefully. I saw this section:


hibernatemode takes a bitfield argument defining SafeSleep behavior. Passing 0 disables SafeSleep altogether, forcing the computer into a regular sleep.


____ ___1 (bit 0) enables hibernation; causes OS X to write memory state to hibernation image at sleep time. On wake (without bit 1 set) OS X will resume from the hibernation image. Bit 0 set (without bit 1 set) causes OS X to write memory state and immediately hibernate at sleep time.


____ __1_ (bit 1), in conjunction with bit 0, causes OS X to maintain system state in memory and leave system power on until battery level drops below a near empty threshold (This enables quicker wakeup from memory while battery power is available). Upon nearly emptying the battery, OS X shuts off all system power and hibernates; on wake the system will resume from hibernation image, not from memory.


____ 1___ (bit 3) encourages the dynamic pager to page out inactive pages prior to hibernation, for a smaller memory footprint.


___1 ____ (bit 4) encourages the dynamic pager to page out more aggressively prior to hibernation, for a smaller memory footprint.



Bits 3 and 4 raised my eyebrow. It looks like for some reason the hibernation process includes having the dynamic pager (this is the part of the kernel that manages swap file creation, paging out, etc) page out the inactive pages in RAM to the disk before hibernating "for a smaller memory footprint." I am not sure why it's doing this. With an SSD it should be fine to just purge inactive memory altogether—you're going to have to hit the disk to get it back whether it's re-reading the file it was originally in OR reading from the pagefile. So, I don't get that at all. It sounds misguided to me, and certainly it sounds like the system is doing this willynilly—hibernatemode 3 (0000 0011) doesn't activate bit 3 or 4, and yet it clearly causes this behavior. It looks to me like it should only happen in hibernatemode 25 (0001 1001), which has bits 0, 3, and 4 set, so it's unfortunate that pmset doesn't appear to behave exactly as advertised.


Still, at least now I have a reasonable guess as to why this paging out was happening. For me, that basically concludes the issue. pmset is doing something normal, but it's doing it even when you don't ask it to. And now we've figured out a couple of ways to prevent the behavior with a variety of tradeoffs, I think we're in good shape despite Apple's apparently-out-of-date documentation.

Oct 17, 2012 6:07 AM in response to megagram

I have something like this happening on my iMac.


Swapfiles build up:


-rw------- 1 root wheel 67108864 Oct 17 07:14 /var/vm/swapfile0

-rw------- 1 root wheel 67108864 Oct 17 08:33 /var/vm/swapfile1

-rw------- 1 root wheel 134217728 Oct 17 08:34 /var/vm/swapfile2

-rw------- 1 root wheel 268435456 Oct 17 08:34 /var/vm/swapfile3

-rw------- 1 root wheel 536870912 Oct 17 08:33 /var/vm/swapfile4

-rw------- 1 root wheel 1073741824 Oct 17 08:44 /var/vm/swapfile5


There is lots of paging:


Mach Virtual Memory Statistics: (page size of 4096 bytes)

Pages free: 482166.

Pages active: 1021364.

Pages inactive: 899727.

Pages speculative: 54463.

Pages wired down: 686699.

"Translation faults": 11470989.

Pages copy-on-write: 479343.

Pages zero filled: 7490105.

Pages reactivated: 569332.

Pageins: 585417.

Pageouts: 60520.


And it's


1922 339 100.1 11.5 1444524 10855052 /System/Library/.../Contents/MacOS/DashboardClient


consuming 100% CPU.


If I kill it, the Dock just restarts it - only a "killall Dock" gets rid of it.


I run no Widgets, hibernate mode is 0 as it should be on an iMac and I don't know what causes this. It seems somewhat random - DashboardClient isn't normally running and then suddenly it fires up and soon after the machine is on its knees. I've been trying to figure out if it's something I do but so far I just do not know..

Jan 19, 2013 8:15 AM in response to Csound1

Tks so much. In answer to your question, I don't run a VM.


FYI my 15" rMBP is configured: 2.6 - 16 / 760 GB SSD. I stumbled upon this thread in following up an apparently well-documented issue with Aperture (even in simple viewing mode it takes up more and more RAM until the whole thing almost ground to a halt). This is my first experience with SSD, so when I got my machine just after they first came out, I did some reading around to learn what I could. I noted several reports/suggestions that regularly writing my 16 GB of RAM to the SSD might significantly shorten its life. I contacted Apple but the people I spoke with were unable to comment one way or the other. In any case, pretty much from the get-go I set Hibernation to 0, and turned standby off (not that I'm an expert, but I read carefully). I've not had any problems since. Then I noticed this thread, and hence my question.


Is there any particular application you want me to run, or any particular conditions/parameters you'd like me to set before posting?


Again, thanks.

Jun 23, 2013 9:23 AM in response to chef098

Chef,


You don't have the issue. If you go back and look at the screenshots from people suffering this issue, you'll see that they have "swap used" but no page outs. Your screenshot shows that you have both, which is very different from the issue primarily discussed in this thread. There are a number of other discussions about Mac OS X's rather aggressive paging strategy.

Over 3GB of swap files with 16GB of RAM?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.