• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
NameHero® Blog

NameHero® Blog

Web Hosting Tips & Resources From NameHero

  • Hosting
    • Web Hosting
    • WordPress Hosting
    • WooCommerce Hosting
    • Enterprise Hosting
  • VPS
    • VPS Hosting
    • Flex VPS
  • Reseller
  • Email
  • Gaming
  • Domains
  • Website Builder
  • Account
  • Blog Home
  • Categories
  • Authors

How To Check Linux Memory Usage

CJ Saathoff

Published on: June 11, 2024

Categories: Linux Command Line 0

Memory or random access memory (RAM) is a hardware component of a computer that is used to temporally store data. RAM can be compared to sticky notes and short-term memory. Like sticky notes, RAM acts as a temporary storage area where data and instructions are quickly accessible for immediate tasks, much like sticky notes. RAM is more like your short-term memory when it comes to storage as when a computer is shut down or restarted. After RAM is cleared it takes more time to recall data much like how humans need to think when recovering memories from long-term (think Pixar’s Inside Out).

  • Introduction
  • Terms To Know Beforehand
  • Checking Overall Memory Usage
    • Advanced overall usage from using proc
  • Checking Per Process Memory Usage
    • Advanced from proc per pid
  • Historical Memory Usage
    • To Install
    • To Start And Enable
    • To Check
  • Conclusion
  • Additional Links

Introduction

In this blog post, we will be going over how to check memory usage in Linux from the command line. Covering how to check total memory usage, process memory usage, and ways to even check historical memory usage. However, before we get started I recommend looking at the terms below.

Terms To Know Beforehand

Physical Memory is the usage of the physical memory (RAM).

Virtual Memory provides programs with the illusion that it has access to large amounts of memory even though the system may be limited.

Swap is storage space on your hard drive/SSD that is reserved as a backup in case memory is full.

Swappiness is the numerical value of how much memory needs to be in use to start using swap memory. Though think of it flipped 0 being do not swap until out of memory and 100 being treat swap the same as RAM.

Checking Overall Memory Usage

If you are looking to check overall system memory usage I recommend using the free command.

free -h 

total used free shared buff/cache available

Mem: 31Gi 9.1Gi 13Gi 1.6Gi 10Gi 21Gi

Swap: 8.0Gi 0B 8.0Gi

The number to be focused on is the last line of the memory line the available column.

In this example, 21G of memory is still available meaning things are just fine.

Advanced overall usage from using proc

Another way to check the overall memory usage is by checking out /proc/meminfo. I am calling this more advanced due to the amount of information you have to sort through many times the information the free command displays.

cat /proc/meminfo 

Bellow is just the first 16 lines out of the total of 57 lines

MemTotal: 32540008 kB

MemFree: 13835532 kB

MemAvailable: 23078148 kB

Buffers: 4488 kB

Cached: 10741516 kB

SwapCached: 0 kB

Active: 11198436 kB

Inactive: 4740928 kB

Active(anon): 6811408 kB

Inactive(anon): 0 kB

Active(file): 4387028 kB

Inactive(file): 4740928 kB

Unevictable: 1470544 kB

Mlocked: 5984 kB

SwapTotal: 8388604 kB

SwapFree: 8388604 kB

In this case, MemAvailable is the same number we looked at before though it’s displayed in kB rather than MB or GB.

Checking Per Process Memory Usage

Using PS we can check the process ID for usage stats

ps u -p PID

Output

USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND

user 196320 0.0 1.3 563904 54672 ? Ssl Apr17 0:00 /usr/libexec/gnome-terminal-server

For memory usage refer to the %MEM section which in this example is 1.3% of the system memory

Advanced from proc per pid

Like the previous advanced section, this is pulling information directly from proc. That said let’s use grep to filter things down as the status file contains more than just memory usage information.

cat /proc/PID/status | grep 'VmSize\|VmRSS'

output example

VmSize: 563904 kB

VmRSS: 54672 kB

VmSize – is the virtual memory being used by the process.

VmRSS – is the physical memory being used by the process.

Historical Memory Usage

If you want to look at historical Memory usage will need to have a method of logging the data ahead of time. For now, let’s focus on a simple solution to gather that data.

The sar command is one of the simplest ways to gather historical system data which includes memory usage. It gathers this data once every 10 minutes and then when you run the command displays the information in a table.

To Install

To install sar the package name should be sysstat on most Linux Distributions.

For Debian and Ubuntu systems

apt install sysstat

For RHEH, AlmaLinux, CentOS, and other systems using DNF

dnf install sysstat

To Start And Enable

To make sure it is installed and started run

sudo systemctl enable sysstat && sudo systemctl start sysstat

To Check

To Check historical memory usage use the sar command using the following command

sar -r

To preserve the columns this example is being added as a screenshot.

Screenshot of the partial output from running sar -r

Out of all the information from sar, you will want to focus on the %memused and the %commit columns.

You’re probably thinking why %commit higher? Well, don’t forget that we still have swap memory.

Be aware that swapping to disk is slower. If you run into an issue where memory is over-committed meaning above 100% you may start noticing performance degeneration. If this is occuring often this is either an indication of an issue or a sign you need more memory.

Note: About Gathering CPU Usage Data From Many Servers

If you need data from many servers the general recommended to have a centralized system that either pulls from the servers or is pushed to the centralled collection server.

Using a system like this makes collecting the data quite a bit more complicated, so think carefully before implementing it.

If you decide to go down this route my recommendation is to use promethus. This ends up being made up of a few components the Prometheus exporter, Prometheus, and the dashboard used to display the data.

Conclusion

In this blog post, we have discussed what RAM is as well as some related terms. From there we discussed how to check memory usage overall, per process, and historically. If you have questions about terms mentioned from proc or the other commands check out the links in the section below for additional documentation.

Additional Links

Done reading and looking for more things to read, why not check these out?

  • Free Man Page
  • Linux Kernel Documentation on Proc
  • Sar Man Page
CJ Saathoff

Embracing a lifelong passion for technology since childhood, CJ delved into the intricate workings of systems, captivated by the desire to understand the unknown. This innate curiosity led to his discovery of Linux, a revelation that resonated deeply. With more than 7 years of on the job experience, he’s honed his technical skills as a Geek and Senior Linux Systems Administrator.

Related Posts

Understanding What The Linux PATH Variable Is And How To Add To It

In this post, we will explore related background, how to check your path, how the path works, and how to add more file paths to your path. 

How To Install Pip And What You Need To Know

Pip is the package management solution for Python. Here's how to install it, what makes it so useful, along with the basic usage.

How To Search and Replace Using The Vim Text Editor

Check out our easy to follow guide on how to search and replace using the Vim Text Editor via the Linux Command Line.

How to Use Git to Push to a Different Remote Branch

You don't always have to commit your git changes to the same branch. Here's how to use git to push to a different remote branch.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Follow & Subscribe

Exclusive promos, content and more!


Most Popular Posts

NameHero’s Recommended WordPress Plugin and Theme Setup (2024)

WordPress Hosting vs. Web Hosting – What’s The Difference?

How To Increase The InnoDB Buffer Pool Size

How To Fix A Stuck All-in-One WP Migration Import

How To Add A Subdomain In Cloudflare

Top Categories

  • WordPress
  • WordPress Tutorials
  • Enterprise Hosting
  • WooCommerce
  • Web Hosting
  • Resellers
  • Website Security
  • Website Development
  • Website Performance
  • VPS Hosting
  • SEO Tips
  • Announcements
  • Domain Registration
NameHero

NameHero® proudly provides web hosting to over 40,000 customers with 99.9% uptime to over 750,000 websites.

  • Master Card
  • Visa
  • American Express
  • Discover
  • Paypal
Products
  • Web Hosting
  • VPS Hosting
  • Flex VPS Hosting
  • WordPress Hosting
  • WooCommerce Hosting
  • Reseller Hosting
  • Enterprise Hosting
  • Email Hosting
  • Game Hosting
  • Domains
  • Website Builder
Help & Support
  • NameHero Blog
  • NameHero Gaming Blog
  • Support
  • Help Center
  • Migrations
  • Affiliates
  • Gaming Affiliates
  • Call 1-855-984-6263
Company
  • About Us
  • Contact Sales
  • Reviews
  • Uptime
  • We're Hiring

Copyright © 2025 Name Hero, LLC. All rights reserved.
NameHero® is a registered trademark.

  • Privacy Policy
  • Terms of Use
  • Acceptable Use Policy
  • Payment Policy
  • DMCA