Monitoring memory usage on Linux keeps applications responsive and reduces the chance of sudden out-of-memory conditions that can terminate important services. Understanding how much RAM and swap space are in use makes it easier to troubleshoot slow systems, size workloads correctly, and spot memory leaks before they become critical.

The kernel exposes memory statistics through the /proc/meminfo interface and makes them available to tools such as free, top, htop, and vmstat. These utilities summarize total and available memory, show how much is used for page cache and buffers, and reveal whether the system is relying on swap space. Most of them are available by default on common Linux distributions.

Graphical utilities like GNOME System Monitor or KDE System Monitor provide similar information in a desktop-friendly way, but terminal-based tools remain the standard choice on servers and remote systems where no GUI is present. Reading memory statistics is safe, but some commands benefit from sudo access to see all processes, and high memory pressure visible in these outputs should be treated as a sign to optimize workloads or upgrade resources.

Steps to monitor memory activity in Linux:

  1. Open a terminal on the Linux system with an account that can run administrative commands when needed.
  2. Display overall memory usage using the free command.
    $ free
                   total        used        free      shared  buff/cache   available
    Mem:         3995176      300740     3159160        4440      687964     3694436
    Swap:        2097148           0     2097148

    This output summarizes physical RAM and swap, including memory used for page cache and buffers.

  3. View memory usage in a human-readable format.
    $ free -h
                   total        used        free      shared  buff/cache   available
    Mem:           3.8Gi       293Mi       3.0Gi       4.3Mi       671Mi       3.5Gi
    Swap:          2.0Gi          0B       2.0Gi

    The -h option prints sizes in GiB and MiB, which is easier to interpret than raw kilobytes.

  4. Monitor real-time memory usage using the top command.
    $ top
    top - 14:47:31 up  6:43,  2 users,  load average: 0.00, 0.00, 0.00
    Tasks: 113 total,   1 running, 111 sleeping,   0 stopped,   1 zombie
    %Cpu(s):  0.0 us,  4.5 sy,  0.0 ni, 95.5 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st 
    MiB Mem :   3901.5 total,   3084.4 free,    294.0 used,    672.2 buff/cache     
    MiB Swap:   2048.0 total,   2048.0 free,      0.0 used.   3607.6 avail Mem 

    Press q to exit top; the MiB Mem line shows total, free, used, and cached memory in real time.

  5. Run htop for an interactive, colorized view of per-process memory usage.
    $ htop

    htop presents CPU and memory meters at the top and allows sorting by columns such as RES and VIRT using function keys.

  6. Check detailed memory statistics from the kernel using the /proc file system.
    $ cat /proc/meminfo
    MemTotal:        3995176 kB
    MemFree:         3158404 kB
    MemAvailable:    3694148 kB
    Buffers:           27892 kB
    Cached:           633520 kB
    SwapCached:            0 kB
    Active:           273384 kB
    Inactive:         417736 kB
    Active(anon):      41592 kB
    Inactive(anon):        0 kB
    Active(file):     231792 kB
    Inactive(file):   417736 kB
    ##### snipped #####

    Fields such as MemTotal, MemAvailable, Buffers, and Cached explain how physical memory is divided between applications and cache.

  7. View memory and paging activity using the vmstat command.
    $ vmstat -s
          3995176 K total memory
           301028 K used memory
           273584 K active memory
           417736 K inactive memory
          3158404 K free memory
            27892 K buffer memory
           660472 K swap cache
          2097148 K total swap
    ##### snipped #####

    vmstat adds information about swap and paging, which helps detect thrashing and sustained swap activity.

  8. Sort running processes by memory usage using the ps command.
    $ ps aux --sort=-%mem | head
    USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
    root         362  0.0  0.6 290464 26240 ?        SLsl 08:04   0:06 /sbin/multipathd -d -s
    root         899  0.0  0.5 110516 22144 ?        Ssl  08:04   0:00 /usr/bin/python3 /usr/share/unattended-upgrades/unattended-upgrade-shutdown --wait-for-signal
    root         311  0.0  0.4  66684 16896 ?        S<s  08:04   0:00 /usr/lib/systemd/systemd-journald
    root           1  0.0  0.3  22556 12664 ?        Ss   08:04   0:02 /sbin/init
    ##### snipped #####

    Sorting by %MEM surfaces the heaviest consumers of RAM so that tuning can focus on the most demanding processes.

  9. Compare MemTotal from /proc/meminfo with totals reported by free or top to confirm that memory statistics are consistent.
    $ grep MemTotal /proc/meminfo
    MemTotal:        3995176 kB

    A small difference between tools is normal due to rounding and units, but large discrepancies can indicate measurement misunderstandings such as including or excluding cache.