I had a bit of a problem earlier on with my server. Exim, the bit that handles email, decided to eat up resources, which caused the Virtuozzo operating system to kick into action and start killing off processes that were eating up too much RAM. This left my server with just Apache and MySQL running.
I generally login every day to check current running statistics for my server to make sure nothing is out of place and everything that should be running, is running. So today when most services got knocked out I was a little surprised.
I contacted the people who ultimately own the node server to see what had happened and they explained that I’d gone over my allocated memory limit for an extended time. This in turn triggers the node to start shutting down processes until I get back under the limit I’m allocated. I found this a little odd as top always reports that I’m way under my limit as the image below shows.

When I asked the support guy why I’d gone over the limit, he explained that even though top and free -m report that as memory usage, I still needed to factor in the RES column that’s outputted as part of top. This is what it shows.

If you tot up the values in the RES column above, you get a memory usage of around 530MB’s. Far greater than the value of 285MB reported by the memory line further up the image.
It turns out that Virtuozzo shares some resources between servers on the node and seems to take that off the total memory usage. It shares resources from commonly used services such as Apache and MySQL and this sharing doesn’t seem to be reflected in the memory reporting tools.
This serves as a warning to those also running under a Virtuozzo environment. The memory you think you are using may well be entirely different and you may find that you’re getting services killed off. To get round this, you’ll need to tune your services to better use the available RAM you have. The best place to start will be Apache and MySQL.
Apache has several configuration options to change, but these four are the most important: MaxRequestsPerChild, MaxClients, KeepAliveTimeout & Timeout. These control how long processes and child processes are open and thus affect memory usage.
MySQL has lots of configuration options and I’d suggest reading through these links to better understand what to tweak.