run-away swap memory

Since a recent upgrade, this Mac-mini running OS/X Snow Leopard runs out of disk space after running for several days. A reboot frees up some 30 GB of space. I tracked down the problem to virtual memory swap files stored under /private/var/vm. After a reboot, these files start out small then grow slowly over several days until they consume all available space and the OS begins to freeze up.


The only processes typically running on this machine are Google Chrome (Web Browser), Thunderbird (E-Mail) and Finder. If either Chrome or Thunderbird were causing the problem, then I would expect the virtual memory (swap files) to be free'ed up after the processes were shut down. But with only Finder running, the virtual memory swap space continues to grow.


Here is a list of the swap files currently on the system with only Finder, Activity Monitor and Terminal running. The machine was restarted yesterday.


ls -l /private/var/vm

total 23068672

-rw------- 1 root wheel 67108864 29 Nov 16:21 swapfile0

-rw------- 1 root wheel 67108864 29 Nov 17:20 swapfile1

-rw------- 1 root wheel 1073741824 29 Nov 17:18 swapfile10

-rw------- 1 root wheel 1073741824 29 Nov 17:18 swapfile11

-rw------- 1 root wheel 1073741824 29 Nov 17:18 swapfile12

-rw------- 1 root wheel 1073741824 29 Nov 17:18 swapfile13

-rw------- 1 root wheel 1073741824 29 Nov 17:18 swapfile14

-rw------- 1 root wheel 134217728 29 Nov 17:18 swapfile2

-rw------- 1 root wheel 268435456 29 Nov 17:20 swapfile3

-rw------- 1 root wheel 536870912 29 Nov 17:20 swapfile4

-rw------- 1 root wheel 1073741824 29 Nov 17:20 swapfile5

-rw------- 1 root wheel 1073741824 29 Nov 17:20 swapfile6

-rw------- 1 root wheel 1073741824 29 Nov 17:20 swapfile7

-rw------- 1 root wheel 1073741824 29 Nov 17:18 swapfile8

-rw------- 1 root wheel 1073741824 29 Nov 17:18 swapfile9


As you can see, there is more than 10 GB of swap space being reserved and it never gets released.


User uploaded file

Activity monitor seems to think that a lot less memory is being used, only 1.26 GB. On the same screen, the VM size at 125 GB does not make sense to me since the hard drive is only 80 GB.


Can anyone shed some light on why swap space would just grow out of control like this? It may be directly related to the most recent upgrades of OS/X since I am not aware of it happening prior to the latest upgrades.


Thanks,

Chris.

Mac mini, Mac OS X (10.6.8)

Posted on Nov 29, 2011 3:20 PM

Reply
14 replies

Nov 30, 2011 1:55 PM in response to X423424X

HP Device Monitor is a component of the HP printer drivers installed for a networked printer.


@X423424X, you may be on to something though, because when I terminated the HP process, swap space went from 11 GB down to 7 GB.


Then I terminated the next highest, the 'mds' process and swap space went from 7 GB down to 3 GB.


So it looks like there are two misbehaving processes, the HP Device Monitor and 'mds' which may be part of the spotlight search engine which in turn is part of OS/X.


I will start googling to find solutions to each of them.


One question though: when looking at the monitoring tools 'top' and Activity Monitor, while the processes appear to use more memory than is necessary, they don't show GB of memory being used - more like a few hundred MB. Why would the swap files grow to such an extreme size? Do they become fragmented by frequent allocation and release requests or something?


User uploaded file

Thank you for your help.

Jun 2, 2012 11:29 PM in response to Chris From Caledon

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.

Jul 21, 2012 6:50 AM in response to Kevin Stanchfield

Today the machine ran out of disk space. Together, the HP monitor and mds used up 45 GB of disk space by filling up swap. When I killed the HP monitor, about 8 GB were released by swap.


The mds process is part of spotlight, a search facility built in to OS/X. To shut down mds, I followed this article:

http://osxdaily.com/2011/12/10/disable-or-enable-spotlight-in-mac-os-x-lion/


and typed this in to the command line:


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


After doing this, the mds process shut down and the remaining 35 GB or so was released by swap.


Clearly these two processes are slowly consuming all available memory. For now, I'm going to leave mds disabled and see if there is a way to convince the HP monitor to not start up.


According to the article, if you need to reenable mds you can use this command line:


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


The HP drivers are from 2010 and it is unlikely they will ever release a patch. Since Apple has moved on, it is unlikely 10.6 will ever see a patch. So the only solution may be to move up to 10.7.

Jul 21, 2012 7:31 AM in response to Chris From Caledon

Also, I've followed the instructions on this page:

http://h30434.www3.hp.com/t5/Mac-Printing-and-Scanning/HP-Device-Monitor-takes-1 30-of-CPU-and-800MB-of-RAM-while-idle/td-p/655701


to completely remove the HP software. Basically, under Applications/Hewlett Packard run the HP Uninstall utility and, after selecting your device, hold down the Ctrl, Opt and Cmd keys while clicking Uninstall. You will get a prompt asking if ALL HP software should be removed.


Reboot your machine, then add a printer. Mine was found by Apple Bonjour (it is a network printer) and drivers were downloaded automatically.


While this printer driver works for printing, it does not appear to support scanning, so that functionality is lost. On the plus side, there are no resident HP processes to consume all available memory and disk space.

Jul 21, 2012 7:45 AM in response to Chris From Caledon

You could temporarily move


/Library/Printers/hp/hpio/HPIO Trap Monitor.app


To the Trash and see what effect it has, if any. Or, just zip (compress) it in order to save it first before trashing.


From the Trash, can always use File>Put Back if needed.



I have those stock files in /Library/Printers, but the HP software for my specific printer is installed in my home folder ~/Library/Printers and my suppositon is that the one in /Library/Printers may not be used at all.


EDIT: first try killing it in Activity Monitor and then test to see if printing still works properly. If so, trash it.


Message was edited by: WZZZ

Jul 21, 2012 5:14 PM in response to Chris From Caledon

10.7 won't fix the problem; it will probably be worse. As I keep saying, this is an OSX memory management bug. Some fanboy will pop up and tell you "No, no, no, St. Steve can do no wrong, and he is watching from beyond the grave," but that doesn't change the fact that the handling of swap in recent OSXs is total, complete and utter crap.


Some such fanboy assured me and others that he had no problems at all - on his 16Gb Mac. Funny that. This problem only happens when you are running an application mix that regularly exceeds your available RAM, causing swap-outs (page-outs in ActivityMonitor). I have taken to being conservative about keeping big applications running. Whereas on a linux system, I would just keep things running until my swap-in time started to get painful, I now kill of applications that I know I wil need again fairly soon, rather than have the system grind to a halt.


As a result, HP Device Monitor, the bete noir of the fanboys, has been behaving itself impeccably. It has been running since the 8th July (today is the 22nd, and my uptime is 20 days, 21:31), has used a total of 105:24.19 (thats minutes:sec.onds) and current has 112Mb of virtual memory. So where's the problem with HP Device Monitor?

Jul 17, 2013 2:15 AM in response to numinasthmatic

I know this is a year past. But I've got to rant somewhere and this place is as good as any as Apple is not going to listen anyway.

I think what Apple did is take a perfectly good kernel and then let their least talented programmers maintain it and now it starts to show in two essential capabilities of the OS: scheduling and virtual memory management. When I started (with 10.3 I think) I worked on a 1 Gig PPC (single core) and did essentially the same thing I do now: compile stuff. And while I did that I could read mail and do research on the internet. Now I do the same on a 8 Gig DualCore and I don't dare to run more than one compiler at once because the machine will get slow ... an generate ridicolous amounts of swap-space.

Concerning the theory memory leak above:

- Currently the process with the most memory is kernel_task. Next is WebProcess. If there is a memory leak it is courtesy of Apple

- I work on Linux-machines with similar workloads and never have that kind of problems. A memory hog is a memory hog. But once it stops a good operating system is able to reclaim all the memory


Part of the problem is in my opinion the dynamically allocated swap-files. I think they are a marketing decision: "We only got a 64Gig SSD in the MB Air. If we set aside a 8Gig fixed swap-partition people are getting angry. Lets go with dynamically allocated swap. That way it will look like he can use the whole disk when he unpacks the computer". They are allocated in 1Gig-chunks. My suspicion is that they are not freed if there is SOME memory in that chunk still used.


Anyway. Sorry to bother you all. Wanted to get this of my chest SOMEWHERE and don't feel like starting a Blog "Is the Mac OS X kernel maintained by interns?". When asked "Why aren't you using a Linux-laptop" I used to say "I want a Unix but I don't want to deal with driver issues" but I'm not sure whether this argument is still valid

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

run-away swap memory

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