Debian – My server is running out of memory, despite having all swap free

debianmemoryswap

I am using Debian 6 (Squeeze). The server has 4gb of memory in it, and 8gb of swap. I'm starting to get memory alloc errors at high application load times, but from top command:

Mem:   4055944k total,  3915436k used,   140508k free,    10444k buffers
Swap:  7999480k total,        0k used,  7999480k free,  3604496k cached

The system isn't even trying to use the swap?

Why would this be happening? I would like to upgrade the primary memory, but this isn't possible just right now.

Thanks.

As requested, the error/exception is:

terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc ยท

which as far as I know, is only ever raised when memory has run out.

Also, here is the output from 'free -m':

             total       used       free     shared    buffers     cached
Mem:          3960       3334        625          0         19       2847
-/+ buffers/cache:        467       3493
Swap:         7811          0       7811

The system is not under heavy load right now though.

Best Answer

That is the output from top.. Look at the following output

free -m

Then look at the free column for the +/- buffers line. That is your true free memory that apps can use. Linux will use all memory for filesystem caching to take load off the disks and make accessing files very quick. The kernel will release the memory used for caching as needed when applications request it.

I'm sure you have plenty of free memory left.