facebook youtube pinterest twitter reddit whatsapp instagram

Monitoring Memory Usage [Ubuntu]

Understanding how GNU/Linux manages memory is not quite that black and white, but it's really straightforward if you can get the concept.

free command is one of the useful utility for monitoring memory usage on our server, it displays the amount of free and used memory in the system.

Let's See Some Variation of The Command:

Displaying Total Memory, and Its Usage

free

Output

user@server:~$ free
              total        used        free      shared  buff/cache   available
Mem:        1008724      695164       89696      131036      223864       64788
Swap:             0           0           0

The free command in the above result is shown in kilobytes.

Displaying Total Memory, and Its Usage in MB (Megabyte)

free -m

Output

user@server:~$ free -m
              total        used        free      shared  buff/cache   available
Mem:            985         683          61         127         241          47
Swap:             0           0           0

This is much more readable, so, let's interpret the results of the above command (I would only be explaining the major ones):

  • The total shows the total installed memory on your server, in my case, it is 985mb.
  • The used show how much of that memory is currently used (by anything)
  • The free column shows how much of memory that is completely free (not used at all, cache or otherwise)
  • The available shows how much memory is free for your application to use, the thing is, this memory is actually be used in the form of a cache but would be released in the event that another application needs it.

Understanding of all the data in a table below:

Column Meaning
total The total shows the total installed memory on your server
used The used show how much of that memory is currently used (by anything)
free The free column shows how much of memory that is completely free (not used at all, cache or otherwise)
shared Memory used (mostly) by tmpfs (Shmem in /proc/meminfo
buff/cache Sum of buffers and cache
available Estimation of how much memory is available for starting new applications, without swapping.

You might wonder what the Swap does, in the event that the memory gets full, it would utilize the swap if you created one during installation.

To control at which point your server will begin utilizing Swap, which is referred to as its swappiness, you change it in the following file

/proc/sys/vm/swappiness

It's by default set to 60, you can verify by running the following command

cat /proc/sys/vm/swappiness

The higher the swappiness value, the more likely your server will utilize swap, say you set its value to 100, it will use swap as much as possible. If it is set to 0, it won't use it at all.

To set the swappiness value, you can execute the following command:

sudo sysctl vm.swappiness=25

The swap will be used when RAM becomes 85 percent full, but the above command won't set the value permanently, it would revert back to the default once you reboot the system.

To make the change permanent, you need to open the sysctl.conf file as follows:

sudo nano /etc/sysctl.conf

By default the swappiness line won't be include, so, you need to add it manually, I'll add it to the end of the file:

vm.swappiness = 25

Utilizing swappiness is one of the useful nugget when performing tuning, there might be a situation where you don't want your application to swap more. Try out different values, and see if it works for you.

Related Post(s)

  • Monitoring Multiple Log Files In RealTime With MultiTail (Ubuntu)

    Oh my... I really find scanning through the logs file time consuming, and painful. Luckily for me, I founded Multitail, which is an awesome, and powerful tool for not only browsing through several f

  • How To Find Files Using Locate in Ubuntu

    It's kind of frustrating when you are searching for a particular file, and you have no idea of how to find it, In this guide, I'll walk you through on two different ways you can find a file in your G

  • Managing MariaDB Databases (Ubuntu Server)

    In this guide, you'll learn how to manage MariaDB databases in your terminal, from connecting to the database server using the mariadb command, creating a database, removing (drop) database, and mana

  • Viewing Disk Usage in Ubuntu

    There are several ways to view disk usage in your Linux system, and that is what we would be going over in this guide... Out of the box, Linux provides us the df command, which is the standard Unix c

  • Understanding & Using Symbolic & Hard Links (Ubuntu)

    Have you ever wondered how you can create shortcuts that link to other files in Linux? Well, let me introduce you to symbolic and hard links. The two types of links in Linux are symbolic links and ha

  • Installing and Using NCDU (NCurses Disk Usage)

    ncdu is a curses-based version of the well-known 'du' command and provides a fast way to see what directories are using your disk space. What I love about this utility is that it can traverse the re