Logo
  • Ubuntu
  • CentOS
  • Debian
  • Fedora
  • RedHat

How to Check Memory Usage in Linux - DesignLinux

Jul 19 2020
designlinux 0 Comments

When troubleshooting system or application slowdown or misbehavior, one of the first things to check is the system memory usage.

This article explains how to check RAM usage in Linux using several different commands.

free Command #

free is the most commonly used command for checking the memory usage of a Linux system. It displays information about the total, used, and free memory.

Generally, free is invoked with the -h option that means print the output in human-readable format:

free -h
              total        used        free      shared  buff/cache   available
Mem:           3936        1087         252         130        2596        2427
Swap:             0           0           0

Here’s what each column mean:

  • total – The total amount of memory that can be used by the applications.
  • used – Used memory. It is calculated as: used = total - free - buffers - cache
  • free – Free / Unused memory.
  • shared – This column can be ignored; it is shown only for backward compatibility.
  • buff/cache – The combined memory used by the kernel buffers and page cache and slabs. This memory can be reclaimed at any time if needed by the applications.
  • available – An estimate of the memory that is available for starting new applications, without swapping.

The free command prints information for the physical memory and the system swap .

top Command #

top is a command-line utility that displays real-time information about the running processes. It also shows the system summary, including memory usage.

To invoke the command simply type top:

free -h

The output will look something like this:

The header of the output includes information about the system’s total, free, and used physical and swap memory.

The %MEM column provides information about the used share of the available physical memory for each running process.

/proc/meminfo #

The simplest way to check the RAM memory usage is to display the contents of the /proc/meminfo virtual file. This file is used by the free, top, ps , and other system information commands.

Use less or cat to view the contents of the /proc/meminfo file:

cat /proc/meminfo

The file includes a large amount of information about the systems memory and swap usage:

MemTotal:        4030592 kB
MemFree:          401804 kB
MemAvailable:    2507504 kB
...

The information from the /proc/meminfo file can be parsed and used in shell scripts.

ps_mem Script #

ps_mem is a Python script that reports per-program RAM memory usage. It work withs both Python 2 and 3 and can be installed with pip:

sudo pip3 install ps_mem

This script requires administrator privileges. To launch it, type sudo ps_mem in your terminal:

sudo ps_mem

The output will include the memory usage of each running program in ascending order:

 Private  +   Shared  =  RAM used	Program
...
 11.9 MiB +  20.2 MiB =  32.1 MiB	nginx (4)
  8.2 MiB +  42.4 MiB =  50.6 MiB	systemd-journald
 55.8 MiB + 307.2 MiB = 363.0 MiB	php-fpm7.4 (6)
233.9 MiB + 234.0 MiB = 467.9 MiB	redis-server
578.2 MiB + 578.6 MiB =   1.1 GiB	mysqld
---------------------------------
                          2.2 GiB
=================================

This script is useful when you want to find out which running program is taking most of your system memory.

Conclusion #

We have shown you several commands that you can use to check the system memory usage.

If you have any questions or remarks, please leave a comment below.

terminal

Related

Tags: terminal

How to Install Elasticsearch on Debian 10

Prev Post

How to Install TensorFlow on Ubuntu 20.04

Next Post
Archives
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • July 2022
  • June 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
Categories
  • AlmaLinux
  • Android
  • Ansible
  • Apache
  • Arch Linux
  • AWS
  • Backups
  • Bash Shell
  • Bodhi Linux
  • CentOS
  • CentOS Stream
  • Chef
  • Cloud Software
  • CMS
  • Commandline Tools
  • Control Panels
  • CouchDB
  • Data Recovery Tools
  • Databases
  • Debian
  • Deepin Linux
  • Desktops
  • Development Tools
  • Docker
  • Download Managers
  • Drupal
  • Editors
  • Elementary OS
  • Encryption Tools
  • Fedora
  • Firewalls
  • FreeBSD
  • FTP
  • GIMP
  • Git
  • Hadoop
  • HAProxy
  • Java
  • Jenkins
  • Joomla
  • Kali Linux
  • KDE
  • Kubernetes
  • KVM
  • Laravel
  • Let's Encrypt
  • LFCA
  • Linux Certifications
  • Linux Commands
  • Linux Desktop
  • Linux Distros
  • Linux IDE
  • Linux Mint
  • Linux Talks
  • Lubuntu
  • LXC
  • Mail Server
  • Manjaro
  • MariaDB
  • MongoDB
  • Monitoring Tools
  • MySQL
  • Network
  • Networking Commands
  • NFS
  • Nginx
  • Nodejs
  • NTP
  • Open Source
  • OpenSUSE
  • Oracle Linux
  • Package Managers
  • Pentoo
  • PHP
  • Podman
  • Postfix Mail Server
  • PostgreSQL
  • Python
  • Questions
  • RedHat
  • Redis Server
  • Rocky Linux
  • Security
  • Shell Scripting
  • SQLite
  • SSH
  • Storage
  • Suse
  • Terminals
  • Text Editors
  • Top Tools
  • Torrent Clients
  • Tutorial
  • Ubuntu
  • Udemy Courses
  • Uncategorized
  • VirtualBox
  • Virtualization
  • VMware
  • VPN
  • VSCode Editor
  • Web Browsers
  • Web Design
  • Web Hosting
  • Web Servers
  • Webmin
  • Windows
  • Windows Subsystem
  • WordPress
  • Zabbix
  • Zentyal
  • Zorin OS
Visits
  • 3
  • 603
  • 1,055,375

DesignLinux.com © All rights reserved

Go to mobile version