How To

How to Check Memory Usage in Linux: free, top, and /proc/meminfo

When a Linux system is slow or behaving unexpectedly, memory is one of the first things to check. This guide covers four methods to check RAM usage in Linux, from a quick summary to per-program breakdowns.

How to Check Memory Usage in Linux with free

The free command gives a fast memory summary. The most useful flags:

bashfree -h    # human-readable (KiB, MiB, GiB)free -m    # megabytesfree -g    # gigabytesfree -s 5  # refresh every 5 seconds

Output includes two rows: Mem: for physical memory and Swap: for swap space.

The three columns that matter:

  • buff/cache — memory used by the kernel for disk buffers and page cache. This is reclaimed immediately when an application needs it. Linux fills unused RAM here intentionally to speed up file access. A high buff/cache value is normal behavior, not a sign of a memory problem.
  • free — completely unused memory. This number alone does not tell you how much memory is actually available.
  • available — an estimate of how much memory a new application can use without triggering swap. This is the column to watch.

The used value is calculated as total - free - buffers - cache. The shared column is a legacy field kept for backward compatibility — ignore it.

Note on free -g: it rounds DOWN to whole gigabytes. If less than 1 GiB is free, the column shows 0. Use free -m or free -h for accurate output.

Real-Time Monitoring with top and /proc/meminfo

The top command displays running processes in real time. The header shows total, used, and free physical and swap memory. The %MEM column shows each process’s share of available RAM:

bashtop

For raw memory data without a live display, read /proc/meminfo directly:

bashcat /proc/meminfo

This file does not exist on disk. The kernel exposes it at runtime, and it is the data source behind freetopps, and other system tools. MemFree shows completely unused memory; MemAvailable shows the realistic usable estimate — the same concept as the available column in free output. The file can be parsed directly in shell scripts.

Per-Program RAM Breakdown with ps_mem

ps_mem is a Python script that groups memory usage by program name – useful for identifying the heaviest RAM consumer:

bashsudo ps_mem

Each line shows Private + Shared = RAM used with the program name. Private is memory used only by that process. Shared is memory shared with other processes (libraries, shared buffers). Programs are listed in ascending order with a total at the bottom.

On Ubuntu 23.04 and later, install with pipx to avoid conflicts with the system Python environment:

bashpipx install ps_mem

On older systems:

bashsudo pip3 install ps_mem

For a quick check, run free -h and look at the available column. For per-process investigation, ps_mem shows which program is using the most RAM. Leave a comment below if you run into any issues.

Cyber Defence

Recent Posts

type Command in Linux: Show How the Shell Resolves a Name

The type command in Linux shows how the current shell would interpret a name typed on the…

48 minutes ago

ip Command in Linux: Configure Interfaces, Routes, and ARP

The ip command is the standard network configuration tool on modern Linux systems. It is part of…

58 minutes ago

chown Command in Linux: Change File and Directory Ownership

Every file and directory in Linux has an owner (a user) and a group. Together…

1 hour ago

How to Remove Files and Directories in Linux: rm, shred, rmdir

The command line does not have a Trash folder. When you delete a file from…

1 day ago

How to Create a systemd Service File in Linux: Step-by-Step Guide

Systemd is the init system on most modern Linux distributions. A service file (also called…

1 day ago

How to Create Users in Linux with useradd: A Complete Guide

Linux is a multi-user system. Each person or service that needs access should have its…

1 day ago