Why Is Most of My Memory Being Used?

We often get calls and tickets from VPS and dedicated customers wondering why, when their server is largely idle, much of their RAM appears to be in use.

When RAM is not needed for other functions, your server will load frequently-accessed files into memory in order to read them more quickly. When a file is loaded into RAM, the server can access the information orders of magnitude faster than from disk. A current SATA disk can read files at 100 MB/second, if the files are in sequential units. However, RAM can be read at GB/second, or even tens of GB/second rates.

If the RAM becomes needed for another function, these files are quickly flushed out of memory, and the RAM becomes available for other tasks.

The most reliable method to view your memory use is run from the command line – “top.” Top is a very handy program, which will show you real-time sytem information.

Log into your server as root using SSH, and type the word “top” (without quotes) at the prompt. You’ll see something like the following:

top - 00:24:58 up 27 days,  4:49, 10 users,  load average: 0.15, 0.23, 0.25
Tasks: 152 total,   1 running, 151 sleeping,   0 stopped,   0 zombie
Cpu(s):  6.5%us,  0.6%sy,  0.0%ni, 92.9%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   2074588k total,  1555948k used,   518640k free,   150452k buffers
Swap:  3220992k total,   411716k used,  2809276k free,   366392k cached

The second line from the bottom shows your total memory usage – it displays how much RAM you have (2 GB in this case,) how much is used (1.5 GB) and now much is free (.5 GB.)

The bottom line shows your swap usage. “Swap” memory is extremely inefficient; the system is using hard disk space as virtual memory, essentially using the disk as “fake RAM.” If you see your server has low free memory, and is using a lot of swap space, this is cause for some concern – we should certainly investigate what is taking up so much memory, and if a RAM upgrade is required.

If you see available RAM, but swap is still taking up space, as in this example, this is less of a concern. Once a file is written to swap, it tends to stay there until the space is needed for another function.

If one particular service is using up the majority of the available RAM on the server restarting the service can often times help lessen the overall load on the server.  Restarting a service is a quick process that should only take a few seconds.  Instructions on restarting a service via the command line can be found here:
Restarting Services from the Command Line


Liquid Web’s Heroic Support is always available to assist customers with this or any other issue. If you need our assistance please contact us:
Toll Free 1.800.580.4985
International 517.322.0434

Be Sociable, Share!
Here's 75 % off, Launch a New VPS Today. Find out why 30,000 customers have chosen our Best-in-Class Performance & 24x7 Heroic Support