Can't allocate cached memory on OpenVZ
Hello.
I ran into a problem that forced me to upgrade my plan to a higher one. I kept getting "out of memory" errors even though free
command reported enough memory (if cache was included) to run a program. Today I remembered about this issue and did a little research. Here's what I found.
According to linuxatemyram.com, kernel should allow other programs to allocate cached memory. But on my VPS it doesn't. To prove it I ran a little program from here that allocates all available memory. Here are the results:
$ free -m
total used free shared buffers cached
Mem: 2048 1030 1017 0 0 461
-/+ buffers/cache: 568 1479
Swap: 0 0 0
$ ./bin/munch
(...)
Allocated 961 MB
$ free -m
total used free shared buffers cached
Mem: 2048 1032 1015 0 0 464
-/+ buffers/cache: 568 1479
Swap: 0 0 0
As you can see, the program can only allocate unused memory but it should also be able to allocate cached memory.
I wrote about it to my hoster's support and here's their answer:
We use standard OpenVZ kernel with standard setting and standard SolusVM
installation for VPS providing, so our VPs servers runs in the same way
as any other provider OpenVZ based VPS servers.
This includes also cache memory usage etc. We have not received any
other complain about memory usage or cache memory etc in a whole active
period of our services. This means that if there is any memory issue
(your guess that there is any) then this may be isolated and affected
only in your VPS server.
There is no memory or cache memory issues from our side related to
your VPS.
So I think there are three possible answers to this issue:
- That's a normal behavior for OpenVZ.
- Something is wrong with my VPS.
- My hoster is a douche and forces its clients to buy more expensive plans.
Which one is it? Or maybe it's something else? I honestly don't know.
Some details about my VPS:
- Debian Wheezy 32bit template, most likely official and unmodified. I also had this problem with Squeeze template.
- Kernel 2.6.32-042stab085.17.
- 2 Gb RAM (was 1 Gb, but I had to upgrade), no burst, no swap.
- No system tweaks.
I want to hear opinion of people that are more experienced with OpenVZ VPS.
Comments
Running that script on my OpenVZ VPS:
try ps_mem.py script
Tried it, it showed what I expected: there's enough memory even if I was running 1 Gb VPS.
Not sure what you asked hoster the first time, but have you tried asking them to investigate why your VM is unable to allocate cached memory. Also try sync; echo 3 > /proc/sys/vm/drop_caches (maybe won't work in openvz)
What program gave you the "out of memory" message? Maybe it was another resource limit that was hit, not the total memory.
I pretty much asked them the first three paragraphs of my initial post.
Tried that, didn't work. I also asked the hoster about that, support's reply:
My VPS is unmanaged, so basically I'm on my own, and after a reply I quoted in my first post I doubt they would even bother.
Any program that required more memory than was unused. Namely clamav and a node.js app. And they explicitly told me "out of memory", so I don't think it's anything else than actually "out of memory".
Still check /proc/user_beancounters especially the last collumn and see which resource could not be allocated.
Too bad it's too late. Like I said, I upgraded from 1 Gb RAM to 2 Gb, so no "out of memory" errors anymore. But I'll check it if I start running out of memory again.
There is a possiblity the provider doesn't have the Vswap checked in SolusVM config for that node which would result in 2.6.18 kernel beancounter settings configured for VMs.
It's an easy mistake to make when setting up a new node. If they are even remotely competent I would imagine they would have noticed it fairly quickly and/or gotten multiple complaints and figured it out so I doubt that's the problem.
Is this a new VPS and possibly a new node you were put on when you had the problem?
I've been using the same VPS for about two years. No complains besides this one.
I noticed the problem a while ago but didn't give it any attention. I thought I squeezed all potential of my VPS. Only recently it actually became an issue, when I upgraded node.js and wasn't able to run an important service anymore.
I googled a bit and checked /proc/vz/vswap file's presence. There's no such file. So my guess is they don't use VSwap.
I don't have either on VM I know uses vSwap, so..
Well, I don't understand that thing anyway.
I mentioned that there's no swap on my VPS, and googling revealed that swap is a mandatory parameter when when node uses VSwap. I dunno though if swap can be set to 0 when using VSwap.
Also I don't understand how VSwap is related to apps not being able to allocate cached memory.
The issue isn't really vSwap feature itself. New version of OpenVZ supports better memory management. I think if hosting provider is using SolusVM, they need to check the box so that it uses the newer thing (which doesn't support old kernels).
I have never interacted with OpenVZ myself so not too clear on details.
-what am I smoking? snip.-
I don't think that's how cache works. Those services should only use memory they allocated.
I asked support about VSwap, and they said my node was using VSwap. They also said the problem could be that my VPS was created quite some time ago, back when 2.6.18 kernel was in use. They changed my server's config to VSwap style, and the problem seems to be gone.
Thank you, everyone, for your replies.
Yeah I read your question wrong, that's why I edited out. Guess you saw it before that.
If it worked before and stopped working after you did something to your VM then it's your VM...duh. Occam's razor blah blah.
Never seen a node spontaneously start messing up VMs memory and beancounters.
If I remember correctly, what you're describing is the host node running out of memory, which OpenVZ advertised as 'unusable cache'.
If it works after they changed it to use new memory management system, then it doesn't make sense that it would be caused by host node running out of memory, since the problem wouldn't have been fixed if that's all they did.