Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a VPS with a hosting company. I do have some badly written perl scripts tha use MySQL. My MySQL server crashed. The hosting company says the server ran out of memory. At a time when I have no traffic on the VPS , my hosting company ran a 'free' and following is the result.

       total used free shared buffers cached
 Mem:  1024   963   60      0       0    746
 -/+ buffers/cache: 217 806
 Swap:    0     0    0

They say I have only 60 mb free. Is that the case? Do I need to upgrade memory?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

Yes, it is the case that only 60mb is free, but this is normal, as linux is designed to use as much available memory there is to maximise performance through caching.

Any memory used for caching is freed when needed by an application.

So there is a difference between memory that is "free" as in, currently unused, and memory that is "available", which may be used for something, but can be given to an application as needed.

The "available" memory is the one that is important, and it is the last number after -/+ buffers/cache:. In your case, 806MB.

With MySQL and dodgy scripts, that memory can be consumed fairly quickly.

I would suggest adding some swap space so that if you do run out, your machine doesn't start terminating processes, but can expand into disk backed storage for "additional" memory. This means it would start going slowly rather than breaking.

Create a swap file:

 # dd if=/dev/zero of=/swap.tmp bs=1M count=1024

This will create an empty file of 1024MB

 # mkswap /swap.tmp

This turns the file into something that can be used for swap space.

 #swapon /swap.tmp

This will enable the swap space - take a look at free to see the difference.

Then edit /etc/fstab and make sure swap is enabled at boot by adding this line (after root is mounted):

 /swap.tmp none swap defaults 0 0 
share|improve this answer
    
This swap stuff is bang on the money, but could have an unintended consequence with causing the system to use disk as memory and making it unuseably slow. You may want to additionally change vm_swappiness which deprioritizes the use of swap space - see askubuntu.com/questions/103915/how-do-i-configure-swappiness about this. –  davidgo Feb 21 at 6:11

No. What you should look at is the -/+ buffers/cache line. The first line includes stuff ― like cached files ― that the kernel is using but can safely get rid of if necessary. See also http://serverfault.com/a/85481.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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