How to Check RAM Usage in Linux

See how much memory is really available, and which process is eating it.

Almost every "Linux ate my RAM" panic is a misread column. The kernel treats unused memory as wasted memory and fills it with cached file data, released the instant a program needs it. The number that reflects real headroom is "available", and once you read that one instead, most alarms disappear.

Step by step

1 The overall picture

$ free -h

total is the physical RAM, used is what processes hold, buff/cache is the kernel caching files, and available is what could be given to a new program right now. Judge pressure by available.

2 Find the biggest consumers

$ ps aux --sort=-%mem | head -n 10

The ten hungriest processes. RSS is resident memory — actual RAM in use. VSZ counts virtual mappings and overstates reality, so ignore it for this purpose.

3 Watch it live

$ htop

Sort by memory with F6 and watch a suspected leak grow over minutes. top works too if htop is not installed: press M to sort by memory.

4 Check swap activity

$ vmstat 1 5

The si and so columns are swap in and out. Occasional values are fine; sustained non-zero traffic while available is low means genuine memory pressure, and everything will feel slow.

5 Confirm an out-of-memory kill

$ journalctl -k | grep -i "out of memory"

When the kernel runs out, it kills the largest process. If something disappeared without explanation, the evidence is here.

Tips worth knowing

Frequently asked questions

Why is almost none of my RAM free?

The kernel is using it as disk cache, which makes everything faster and is reclaimed instantly when needed. This is correct behaviour, not a problem.

What is the difference between free and available?

free is memory doing absolutely nothing. available is the kernel's estimate of what could be handed to applications, including reclaimable cache. The second is the useful number.

My process was killed with no error — why?

Probably the OOM killer. Check journalctl -k for "Out of memory" and the name of the process it chose.

Should I add swap?

Some swap is worth having as a safety margin, but swap is not a substitute for RAM. If you are swapping continuously, you need more memory or a lighter workload.

The commands behind it

free

RAM and swap at a glance — and how to read "available" correctly.

ps

See what is running, find a process ID, and combine with grep to hunt down a program.

top & htop

The live dashboard: CPU, memory, load average and the processes consuming them.

journalctl

Query the system journal: by service, time window, priority — and follow live.

Concepts involved: Process

More how-to guides

Check disk space in Linux

See how much space is left, and find out what is using it.

Extract a .tar.gz archive

Unpack tar.gz, tar.bz2, tar.xz and zip archives from the command line.

Free a port that is already in use

Find which process holds a port and stop it cleanly.

Find and replace text in files

Replace text in one file or across a whole project, safely.