Gets slower the longer it runs - bah!

Discussions related to using VirtualBox on Mac OS X hosts.
Post Reply
unix4hire
Posts: 2
Joined: 19. Aug 2016, 21:46

Gets slower the longer it runs - bah!

Post by unix4hire »

I have been running 2 Windows VM's on my macbook pro for a couple of years now and the same thing occurs regardless of version of vbox I have running.. after a week or at most 2 my entire host and both VM's start running sluggish. Copy/Pasting is slow, mouse movement slow, etc. Not TERRIBLY slow, but noticeable. The only fix I've found is to shut down at least one VM, then it goes back to normal speed immediately.

Any ideas on things I can do to fix this? For the first week all machines run fine, no problems.. so I wasn't thinking I needed to tweak anything specific. Seems like a memory leak somewhere but when I check host (mac) memory usage it doesn't appear I'm maxed out:

Phys: 16GB
Mem used: 13.6GB
Cached: 2.35GB
Swap used: 2.21GB

Thanks so much.
socratis
Site Moderator
Posts: 27329
Joined: 22. Oct 2010, 11:03
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Win(*>98), Linux*, OSX>10.5
Location: Greece

Re: Gets slower the longer it runs - bah!

Post by socratis »

Most probably your host is running low on resources, mainly RAM, and it has to do page ins and page outs to/from the hard disk. The most usual culprit is the file cache. You already see that Used+Cached=Physical. No breathing room. Of course you haven't mentioned what you've allocated to each guest, so it is a guess at this point. An educated guess, but a guess.

May I suggest a couple of applications, so that you know what's available on your system at any given time? What I do, is to have several monitor tools running at all times. Your preference may vary, but you can use either of them (I use all of them concurrently):
Do NOT send me Personal Messages (PMs) for troubleshooting, they are simply deleted.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
Perryg
Site Moderator
Posts: 34369
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX

Re: Gets slower the longer it runs - bah!

Post by Perryg »

Cached: 2.35GB
Swap used: 2.21GB
There is your problem.

Solution I use with Linux is to clear the cache and swap occasionally on systems that are limited in resources or pushed over what they have.
  • swapoff -a then swapon -a
    sync then echo 1 > /proc/sys/vm/drop_caches
Look up the Mac equivalent and make a script.
socratis
Site Moderator
Posts: 27329
Joined: 22. Oct 2010, 11:03
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Win(*>98), Linux*, OSX>10.5
Location: Greece

Re: Gets slower the longer it runs - bah!

Post by socratis »

Not a good idea I'm afraid. The OP doesn't have enough free RAM to purge the swap. You're going to start getting not enough memory errors.
Do NOT send me Personal Messages (PMs) for troubleshooting, they are simply deleted.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
Perryg
Site Moderator
Posts: 34369
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX

Re: Gets slower the longer it runs - bah!

Post by Perryg »

Not sure that is accurate either. Most of the time the swap is because of the host being used for other things or hibernation. Most of the time it comes from browsers or games but in any case the swap off and on just clears the saved memory and not an actual running application because if the application is running it would not still be in swap, or it shouldn't be. Most memory managers fail horribly and this can help.

I should note that I do make sure that the extra applications have in fact been shut down but the memory manager should be able to recover if it would cause an issue. Of course you know a lot more about a Mac than I do and your advise should carry more weight, but I can say I have been using this approach for more years than I can remember and it has never caused an issue ( on Linux anyway )

Oh and to be certain that all understand I am not saying to shut down swap, only clear it to release junk still there, swapoff then swapon.

The only other way to repair this when it happens is to reboot the host ( which clears out the swap ). I just am providing another approach which I know works ( again in Linux ) without rebooting. But it is only a suggestion.
socratis
Site Moderator
Posts: 27329
Joined: 22. Oct 2010, 11:03
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Win(*>98), Linux*, OSX>10.5
Location: Greece

Re: Gets slower the longer it runs - bah!

Post by socratis »

Swapping and memory management is a tough subject, definitely. But the basics of active, inactive, free and swap I think are pretty much common across all OSes (mostly). For example, this is what the Activity Monitor help talks about (and in parentheses my values as of ... now):
  • Physical Memory: The amount of RAM installed. (16.00 GB)
  • Memory Used: The amount of RAM being used and not immediately available. (12.27 GB)
  • Virtual Memory: The amount of disk or flash drive space being used as virtual memory. (19.83 GB)
  • Swap Used: The space on your drive being used to swap unused files to and from RAM. (763 MB)
  • App Memory: The amount of space being used by apps. (7.96 GB)
  • Wired Memory: Memory that can’t be cached to disk, so it must stay in RAM. This memory can’t be borrowed by other apps. (1.04 GB)
  • Compressed: The amount of memory in RAM that is compressed. (2.00 GB)
  • File Cache: The space being used to temporarily store files that are not currently being used. (1.27 GB)
So, even with almost 3.5 plus GB free memory, I still have 760MB in the swap file. Why? No clue.

On the other hand, clearing the swap file is not trivial on the Mac. You pretty much have to disable it (dangerous I believe) and then reboot to re-enable it. Which is useless pretty much, since rebooting clears the swap file to begin with.

There is the 'purge' command, but this only clears the Inactive memory, and even that requires sudo these days (I think since 10.7).
[color=#008000]man purge[/color] wrote:Purge can be used to approximate initial boot conditions with a cold disk buffer cache for performance analysis. It does not affect anonymous memory that has been allocated through malloc, vm_allocate, etc.
Bottom line is that the OP is short on memory, and no matter how many "aces" they have on their sleeves, they won't be enough.

Perryg wrote:the swap off and on just clears the saved memory and not an actual running application because if the application is running it would not still be in swap, or it shouldn't be
If an application is running in the background (think of your thesis in LibreOffice with a gazillion graphics and tables) and another front application requests memory with not enough free memory (like loading in the text editor all the works of Jules Vern), then the background application gets swapped to the HD while the foreground app gets memory fresh from the oven RAM. When the background want to get loaded into RAM again, some other process is going to pay the price and get swapped.
Do NOT send me Personal Messages (PMs) for troubleshooting, they are simply deleted.
Do NOT reply with the "QUOTE" button, please use the "POST REPLY", at the bottom of the form.
If you obfuscate any information requested, I will obfuscate my response. These are virtual UUIDs, not real ones.
Perryg
Site Moderator
Posts: 34369
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX

Re: Gets slower the longer it runs - bah!

Post by Perryg »

If an application is running in the background (think of your thesis in LibreOffice with a gazillion graphics and tables)
You missed the point where I said I closed these things on the host down first. :wink:

Anyway I said what I do and it works, now it is up to you and the OP to sort this out on the Mac side or not. I just don't like to reboot a server ( the host ) even if it is one that I do other things in. TTFN
unix4hire
Posts: 2
Joined: 19. Aug 2016, 21:46

Re: Gets slower the longer it runs - bah!

Post by unix4hire »

Much appreciate the thorough replies, folks. My educated guess was memory, but given used was well under phys I didn't think it would be too big of an issue. I referenced https://support.apple.com/en-us/HT201464 for explanations of cached/swap and was under the impression cached basically hurt nothing (other apps can grab from it whenever necessary), and swap was relatively low, plus I saw no red in the pressure gauge apple discusses in the link.

At any rate I will try some of the suggestions (purge, resource tools, etc) and decrease allocated guest vm memory to see if that helps. Or maybe the next mbp models will allow >16GB memory.. wouldn't that be nice (and pricey, I'm afraid!).

Thx!
Post Reply