Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Register

Managing VPS memory usage

IevazIevaz Moderator
edited May 5 in Server management

After installing the operating system on the server, some of RAM will be used by default (the RAM usage depends on the installed operating system). Since there are many system processes that have to run so that VPS could work and be accessible, you need to keep in mind that system processes will use some memory after installing OS.

It is essential to check RAM usage for a few reasons. First of all, it can provide information on whether it’s necessary to upgrade your VPS plan to a bigger plan that RAM usage limit would increase. If you notice that more utilization regularly nearing full capacity, it might say that your system needs an upgrade.

Also, it can help you track down issues that might be related to RAM usage. For example, high RAM usage or a spike in memory usage can indicate the issue with processes running on the server.

Thus in this tutorial, I will explain how to check memory usage via SSH.

free command

free -m command displays the current memory usage on your VPS and the output should look something like this:

The -m option tells the command to provide the result of memory usage in megabytes. The option -g tells the command to display the usage in gigabytes.

  • Total: the amount of physical RAM and swap available in the system;
  • Used: shows how much RAM is currently used by the system and its processes;
  • Free: display the amount of RAM that is not occupied at the moment;
  • Shared, buff/cache: shows the amount of RAM used by the kernel for particular purposes, such as shared between different processes or allocated to cache.

So when you check RAM usage, you should pay attention to 'buff/cache' column. Linux OS uses unused memory for disk caching. This is a normal process because that's how Linux works. It often seems that the server is using all the RAM, but it's not true, so the real used RAM is displayed in 'used' column.

More information about this process can be found here.

ps command

Another useful tool is ps, which will show you all of your running processes with RAM usage as a percent of total RAM. Without any option and argument, the ps command shows only the process running under the logged in user account from the current terminal:

The "ps aux" command is the most frequently used command. ps aux command options:

a:- This option prints the running processes from all users.

u:- This option shows user or owner column in the output.

x:- This option prints the processes those have not been executed from the terminal.

ps aux will provide all the running processes in the system regardless from where they have been executed.

So ps aux is useful if you only want to see a particular process(es). For example, if you want to see only running Apache processes, you should use this command:

ps aux | grep apache

For PHP processes, you can use this command

ps aux | grep php

If your used memory usage reaches almost the limit, you should check which processes are using mostly RAM because it might lead to problems. For instance, if on your VPS is hosted a website, it might stop working due to memory saturation during peak hours. Later, it might start working normally once the traffic decreases to more manageable levels.
So it's important to configure VPS correctly and have enough resources to prevent such problems.

top and htop commands

top command displays virtual memory usages by each process. It displays how much memory % a process is consuming separately for each running process. Also, top command provides a listing of the most CPU utilization tasks and also can sort the tasks by memory usage, CPU usage, and runtime.
You can use single top command to display memory usage only:

top -o %MEM

Command htop is very similar in functionality to the top command,. However, htop is a bit more graphical and shows information a little more friendlier than top.

Also, both of these commands have a real-time visualization.

More about these commands you can find here.

Using the various commands from this article, you will be able to review your server’s RAM usage because understanding memory usage is important for overall system-performance measurement.

Sign In or Register to comment.

Learn how to install a web and database server, email, FTP client or other applications. Discover and share information on server security or optimization recommendations.
Feel free to join our constantly expanding community, participate in discussions, strengthen your knowledge on Linux and Windows server management!
© 2013 - 2021 Time4VPS. All rights reserved.

Get In Touch