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?

030
  • 5,731
  • 12
  • 61
  • 107

1 Answers1

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.

Eirik Toft
  • 834
  • 8
  • 20
  • 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