Linux Check Memory Usage

How do I check used and free RAM memory usage under Linux operating systems using command line and GUI tools?

Linux comes with different set of commands to check memory usage. The free command displays the total amount of free and used physical and swap memory in the system, as well as the buffers used by the kernel. The vmstat command reports information about processes, memory, paging, block IO, traps, and cpu activity. Finally, you can use the top, and/or atop/htop commands which provides a dynamic real-time view of a running system. top and friends can display system summary information as well as a list of tasks currently being managed by the Linux kernel.

/proc/meminfo

The /proc/meminfo file stores statistics about memory usage on the Linux based system. The same file is used by free and other utilities to report the amount of free and used memory (both physical and swap) on the system as well as the shared memory and buffers used by the kernel.

Example

Use the cat command or grep command to see /proc/meminfo file:
$ cat /proc/meminfo
$ less /proc/meminfo
$ more /proc/meminfo
$ egrep --color 'Mem|Cache|Swap' /proc/meminfo

Sample outputs:

MemTotal:        8120568 kB
MemFree:         2298932 kB
Cached:          1907240 kB
SwapCached:            0 kB
SwapTotal:      15859708 kB
SwapFree:       15859708 kB

free command

To display free memory size in MB (megabytes):
$ free -m
Sample outputs:

             total       used       free     shared    buffers     cached
Mem:           750        625        125          0         35        335
-/+ buffers/cache:        254        496
Swap:          956          0        956

Displays a line containing the totals memory in MB:
$ free -t -m
Output:

       total       used       free     shared    buffers     cached
Mem:           750        625        125          0         35        335
-/+ buffers/cache:        253        496
Swap:          956          0        956
Total:        1707        625       1082

So how much free ram I have?

Type the following command:
$ free -m
Sample outputs:

Understanding Free Command Output

In this above output, my server has used 2825 MB ram, and 9083 MB is available for other users and programs.

A list of free command options

  -b,-k,-m,-g show output in bytes, KB, MB, or GB
  -l show detailed low and high memory statistics
  -o use old format (no -/+buffers/cache line)
  -t display total for RAM + swap
  -s update every [delay] seconds
  -c update [count] times

vmstat command

Type the vmstat command at shell prompt:
$ vmstat
Sample outputs:

procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
r  b   swpd   free   buff  cache   si   so    bi    bo   in    cs us sy id wa
1  0      0 131620  35432 341496    0    0    42    82  737  1364 15  3 81  1

top command

Type top command at the shell prompt:
$ top
Sample outputs:

Fig.01: top command displaying used memory

To exit from top command type q key.

atop command

The program atop is an interactive monitor to view the load on a Linux system. This program can display the amount of used and free memory. It is similar to top command but comes with additional advanced options. By default, the atop command is not installed on most Linux distributions.
$ atop
Sample outputs:

Fig.02: Linux Check Amount Of Memory With atop Command

htop command

The program htop is an interactive process viewer. It is similar to top, but allows to scroll the list vertically and horizontally to see all processes and their full command lines.
By default, the htop command is not installed on most Linux distributions.
$ htop
Sample outputs:

Fig.03: Linux Check Amount Of Physical Memory With htop Command

GNOME Desktop: GUI tool to see memory usage

The “Gnome System Monitor” application enables you to display basic system information and monitor system processes, usage of system resources, and file systems. You can also use System Monitor to modify the behavior of your system. You can start System Monitor by visiting System menu > Choose Administration > System Monitor option. Or type the following command at the shell prompt:

gnome-system-monitor

Sample outputs:

Fig.04: Linux See Memory Usage With GUI System Monitor Tool

Check out related media

A note about the performance

  1. RAM – An occupation percentage of 90% is considered as critical.
  2. SWAP – An occupation percentage of 80% is considered as critical.
  3. To solve performance related problems, add more RAM and increase the swap space (or move swap space to another disk controller).

Read man pages of free, vmstat, top, atop, and htop commands for more information.

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.