2

I have a VPS running a few websites for clients. Running free -h shows the following:

~$ free -h
             total       used       free     shared    buffers     cached
Mem:          994M       855M       138M        39M        72M       420M
-/+ buffers/cache:       362M       631M
Swap:         511M         0B       511M

So I have about 138MB of free memory. My question is, how do you know when it's necessary to increase the amount of physical memory on a server? When it starts dipping into swap on a consistent basis?

At any given time I have about 140-145MB free. Does this indicate a healthy amount of free-vs-total available memory?

  • Do you see some OOMs in dmesg? Is the SWAP empty all the time? Do you use tools that monitor the memory constantly? – 030 May 15 '15 at 18:15
  • Thanks for the reply. So sorry but I don't understand what you're asking. – Jonathan Melville May 15 '15 at 18:17
  • Out Of Memory (OOM) – 030 May 15 '15 at 18:18
  • Swap is empty 99% of the time. I don't currently use any tools to monitor the memory as I just took this over and I'm more of a web developer than a sysadmin. Hence coming here :-) – Jonathan Melville May 15 '15 at 18:22
  • Obligatory: linuxatemyram.com – Hyppy May 15 '15 at 18:27
3

The biggest thing to watch are page faults. On most Linux systems, running

ps -o min_flt,maj_flt

will give you some cumulative statistics, but real-time isn't always good enough. SAR is probably your biggest friend when it comes to checking out overall health of the system, including memory, processor, network, etc... Check out the man page for sar for sure. But to answer the page faults, run:

sar -B

Check the major faults column for anything major going on. Some major page faults are okay, but many of them racking up usually indicate you either have a process that is eating memory indiscriminately, or you need to increase the amount of physical memory in a server.

Last note, when running "free" to see the amount of memory, make sure to add back in the amount of Free memory listed under buffers/cache back to your total memory shown.

  • Which implementation of sar are you using? The one I have apparently doesn't have a -B option. – Zoredache May 15 '15 at 18:30
  • I'm running RedHat, centos and Ubuntu. Check the man page on your system "man sar" and check to see if they use a different flag for paging statistics. If nothing else, I think running sar -A will dump everything that sar is collecting. If the command is missing altogther, you may need to install the sysstat package for your distro. – Eirik Toft May 15 '15 at 19:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.