Apple Event: May 7th at 7 am PT

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

Swapfile's out of control

Okay - I cannot account for quite a few Gig's on my HD. I ran WhatSize and came across 44.0 GB in Private/Var/VM. 4.29 GB was the sleepimage, but I have Swapfiles's 5 - 40 at 1.07 GB each (approx. 37 GB total).


In terminal, I ran:


sudo du -h -d1 /var/vm

Password: *****

37G /var/vm


My suspicion is that this is highly unusual, but I've been cautioned to avoid deleting or messing with them.


Is this indeed unusual? Are there any suggested remedies?



Your help is very much appreciated.



Thanks!

MacBook Pro (13-inch Mid 2009), Mac OS X (10.6.8)

Posted on Feb 12, 2012 11:37 PM

Reply
26 replies

Feb 13, 2012 8:55 AM in response to X423424X

X423424X wrote:


I'm not familiar with VirtualBox which is why I didn't jump all over it in my earlier posts other than suggesting its removal due to continually running daemons (at least I think they are running). But I am not sure it has a full windows system running inside it. Only enough of an environment to support windows executables which I would hope (only hope) would be less than a full windows environment. It's still though probably a memory hog.

VirtualBox itself doesn't consume many resources. (Not concerned about daemons since many apps do that...one should be concerned about kernel extensions.) But you can't do anything with just VirtualBox; like Parallels or VMWare it's like a hardware PC with a blank drive, that is, you can't do anything with it until you install a legitimate OS on it like Windows 7. Most people will install a standard version of Windows 7, which means a full home or pro version.


The big RAM and CPU footprint that happens is not technically because of VirtualBox, but because of Windows running inside it. VirtualBox just makes it possible.


Now that you can virtualize OS X, the same thing would happen if you wanted to run an OS X test environment inside your normal OS X. That would also be running two copies of a complete OS.


When you quit WIndows and VirtualBox, they do not strain the Mac any more and you free up the RAM and CPU they were using. But the swap files may hang around for a few hours or days until OS X decides to release them, which it eventually will. They shouldn't hurt performance unless you are low on disk space. Swap files only hurt performance when being actively swapped in and out of.

Feb 13, 2012 10:00 AM in response to Network 23

It won't clear the VM, but one benevolent unintended consquence of a usually time wasting Permissions repair is to clear the inactive RAM. Inactive RAM is supposed to be readily available for other apps or processes besides the ones it was originally allocated to, but in practice it doesn't seem to work like that.


Doing this may help to reduce the need to swap when memory is low.

Feb 13, 2012 10:43 AM in response to Nightshade0six

The sleep image will always be approximately as large as the amount of installed RAM on your computer. Turning off hibernate mode doesn't benefit you any other than it means that if your machine goes from sleep to power-off you'll loose your work and potentially some data on the disk (in case there are unflushed buffers / unclosed files).


With regard to the VM... Apple's virtual memory system is fairly straightforward, actually. When memory usage hits a high-water mark (90% of memory used, if I recall correctly) for some reason, then dynamic pager is asked to expand the memory. The first allocation is 64M, the next is 128M, then 256M, etc. Each time doubling. The maximum swap file size is 1G, but it still allocates by doubling the available swap each time the high-water mark is met (90% of memory is allocated).


~32G indicates that you high the 16G high water mark (about 14.5G of memory requested), triggering another 16G to be allocated. That's perfectly reasonable. You have only 2G of RAM and your are running 2 VMs that allocate very large amounts of memory themselves (the virtual RAM of the VM + the virtual RAM of the virtual Video Card + the VM software itself + the VM instance memory).


There's nothing to worry about here, the system is behaving normally. After the memory hovers around a low water mark (~30% usage), the VM swap files will slowly be deallocated (note that removing the files is MUCH slower since you have to wait for active memory segments to migrate out of the swapfiles that are to be removed).


Also note that if the machine is shut-off improperly (e.g., if you turn it off without shutting down, or if you sleep it with hibernation disabled and the power runs down), those swap files may remain until they a referenced again and normally deallocated.


You can always boot into single-user mode and do:


rm /var/vm/swap* && reboot


... but keep in mind that you don't have all that much RAM, particularly enought to support two virtual machines. The system is going to be doing a lot with virtual memory and it's going to create new swap files just as fast as you've created them.

Feb 13, 2012 9:22 PM in response to J D McIninch

J D McIninch wrote:


You can always boot into single-user mode and do:

rm /var/vm/swap* && reboot

... but keep in mind that you don't have all that much RAM, particularly enought to support two virtual machines. The system is going to be doing a lot with virtual memory and it's going to create new swap files just as fast as you've created them.

That's an important point. While there are ways of manually killing swap files (which are dangerous techniques if done while the OS is actually loaded), that won't stop swap files from continuing to pile up, as long as the root cause for them exists: insufficient RAM.

Jun 2, 2012 11:32 PM in response to Nightshade0six

This is a repost from another related thread. The problem gets reported in many places, but no-one ever joins the dots to illustrate that it is fundamental memory management bug in the OS.


......


This is an on-going and serious OS X bug. It is NOT confined to Lion, although that may have made it worse for some people. I experienced ths problem with Snow Leopard as well.


The problem is not with any particular apps, although it may start there. You can shut everything down on the system, and the swap will still not be freed. That's an OS X problem, because the processes that generated any memory leak have gone away, but OS X doesn't want to know.


The other symptom you will see is that the system will slow down dramatically, because activitymonitord is chewing up increasing percentages of CPU. I have seen activitymonitord running at over 40% of a CPU. That's impressive, and that was on Snow Leopard.


Apple needs to fix this, but they don't seem to be interested.

Jun 4, 2012 1:14 AM in response to numinasthmatic

It doesn't happen all the time though. And in Snow Leopard and Lion, OS X seems to dump swap files much sooner than in older OS X versions. Just yesterday I watched Firefox hang, and its RAM use went up past 1.5GB, causing my number of swap files to go from 3 to 5. When I resolved the hang, Firefox started letting go of RAM and I watched OS X swap files go from 5 to 4 and then 3 in a matter of minutes. I see this when using Photoshop too, it can accumulate swap files and then drop them soon after quitting Photoshop. In older versions of OS X, the Mac wouldn't drop swap files for hours or days.

Mar 8, 2013 6:30 PM in response to Network 23

I have the same problem. I never used to have this issue i'm sure. When I reboot I get about 11-12GB of free space back - the longer i leave my computer without rebooting the more space gets stolen.


I see you mention Virtual Box. I have crossover (which may be similar) and an application called bluestracks which runs android on my mac. Could these be causing issues or is it normal for this to happen? I've never noticed it before even when I didn't have much free disc space.

Mar 9, 2013 11:12 AM in response to Made In Machines

Made In Machines wrote:


I see you mention Virtual Box. I have crossover (which may be similar) and an application called bluestracks which runs android on my mac. Could these be causing issues or is it normal for this to happen? I've never noticed it before even when I didn't have much free disc space.

Crossover is not exactly the same. VirtualBox is a way to run Windows on a Mac, while Crossover can run some (not all) Windows apps without Windows being installed at all. But to do that, it probably uses a bit of RAM to provide Windows functions that the apps will expect to be able to use.


I don't know bluestracks but if it is an Android emulator it probably does need a bit of RAM to set itself up inside the host OS X. But I wouldn't normally expect it to need as much RAM as Windows since Android runs on devices with limited RAM.


Also, to respond to jdran - normally you don't want to delete those files because they represent data the system has cached and expects to be able to find. In some cases an application may crash if it looks for data it knows got temporarily stored in virtual memory, but you took away behind its back. It goes to get the data, the data is not there...boom. Also, 4GB RAM is not a lot of RAM. It is minimal if you do any graphics or multimedia work.

Swapfile's out of control

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