Site/App Performance

Understanding and Troubleshooting RAM in Linux

RAM (Random Access Memory) is computer storage that holds the data of running processes (i.e. programs). That data includes the image of the program itself, the data that the program uses to interact with the computer’s operating system, and the data that the program is actually manipulating to do whatever useful thing the program is written to do. Consequently, RAM needs to be a very fast data store that gives a running program nearly instant access to the data it needs to operate. It is also volatile — it does not survive reboot. By contrast, data on disk (whether traditional hard disk, or otherwise) is designed for long-term storage and large capacity at the expense of speed.

How much RAM is my server using?

The easiest way to see memory usage is to run the free command in SSH (use the -m tag to view the results in megabytes). Below is an example.

free -m
                   total  used  free shared buffers cached
Mem:               11796  2302  9494      0     224   1199
-/+ buffers/cache:         877 10919
Swap:               8189     0  8189

The line that most accurately describes the amount of memory being used and how much is available for future usage is -/+ buffers/cache. This line subtracts buffers and caches from the used column of memory and adds buffers and caches to the free column in order to show the user exactly what is currently being used by system processes and what is available in reserve.

Caches are memory that stores recently accessed data in case it needs to be accessed again. (Virtuozzo-based VPS technology does not use RAM buffers.) The main difference between cached RAM and used RAM is that caches can and will be released and reused when there is a more immediate and direct need for this memory.

If you use cPanel, you can also access the information in free under “Service Status.”

Why does my server use so much RAM, and how can I reduce my RAM usage?

The first step in troubleshooting high RAM usage is to narrow down which process[es] is using the majority of the RAM. Running a top command in the shell is a good place to start. Once in top, type [shift] + m to sort the list of processes by memory. Let the output refresh for the next 30-60 seconds and watch to see which processes are listed at the top. The RES column is the closest to actual RAM usage, the %MEM column is how the top is organized.

31307 named  20  0 2492m 108m 2424 S  0.0  0.7   24:49.34 named
28178 mysql  20  0 12.7g  88m 3864 S  2.6  0.5 2695:47    mysqld
19851 nobody 20  0  301m  80m 5976 S  0.0  0.5    0:13.13 httpd
19797 nobody 20  0  298m  77m 6208 S  0.0  0.5    0:13.43 httpd
20097 nobody 20  0  297m  76m 5788 S  0.0  0.5    0:07.97 httpd
30932 nobody 20  0  295m  74m 6344 S  0.0  0.5    0:02.63 httpd
30920 nobody 20  0  295m  74m 4448 S  0.0  0.5    0:01.45 httpd

Note that some processes fork (create child processes). The child processes will show up individually in top. In the above top, it looks as if named (nameserver) is using up the most memory, but in actuality it’s all of the httpd (apache) processes together that use up the majority of the memory. Running pstree will show you which processes are running, what is spawning them, and how many there are.

     │         ├─2*[imap-login]
     │         └─2*[pop3-login]
     │       └─leechprotect

Depending on which process is using up the majority of your RAM, the solution (assuming there is one) will vary. The next step will be to Google “reduce ____ memory usage” for which ever process is eating up RAM.

If you ever get stuck or are not sure how to proceed, contact the MST through the ServInt customer Portal and we can give you more information and suggestions on how to proceed.

Photo by GlacierNPS

Find out more about ServInt solutions

Starting at $25

  • Hosting Advice
  • Computer World
  • Ars Technica

  • The New York Times
  • The Seattle Times
  • Bloomberg
  • The Hill

To engage with the ServInt Sales Team use the following chat icon. Normal sales hours are Monday-Friday 9am-5pm EST but feel free to leave a message and we will follow up as soon as possible.

Sales Chat

To engage with the ServInt Support Team you must be logged into our Customer Portal for identity verification and have a ticket opened about your request or there will only be limited support offered.

Support Chat