Find What's Eating Your RAM on Linux
A practical method for reading free, top, and ps correctly so you attribute Linux memory to a real cause instead of guessing.
Key takeaways
- Judge Linux memory by the available column in free -h, not free, because page cache is reclaimable.
- Then sort processes with ps aux --sort=-%mem and confirm the suspect with PSS and Private_Dirty from /proc/PID/smaps_rollup.
- In containers, read memory.current and memory.stat from the cgroup instead of free.
On this page
To find what is using memory on Linux, run free -h and read the available column, not free. If available is low, run ps aux --sort=-%mem | head for candidates, confirm the top one with Pss and Private_Dirty in /proc/<pid>/smaps_rollup, and check slabtop when processes don't add up. In containers, read the cgroup files.
Verified against
Linux kernel 7.3 documentation (cgroup v2 and /proc), man-pages 6.19 (proc_pid_smaps, vmstat) and the procps-ng free(1) page, against docs.kernel.org and man7.org. Checked October 2026.
Someone pages you: "the box is out of memory." You run free -h, see free sitting at 200 MB, and panic. Usually nothing is wrong. Sometimes you need to know exactly which process or subsystem is holding the pages. This is how to tell the two apart without guessing.
Start with free -h and read the right column
free -h
total used free shared buff/cache available
Mem: 31Gi 8.2Gi 412Mi 1.1Gi 22Gi 21Gi
Swap: 8.0Gi 128Mi 7.9Gi
The trap is the free column: 412 MiB looks like starvation. It is not. Linux deliberately fills idle RAM with page cache, shown under buff/cache, and most of it is reclaimable the instant a process needs it.
The column that matters is available. The free(1) man page defines it as an "estimation of how much memory is available for starting new applications, without swapping", and the kernel computes it (MemAvailable in /proc/meminfo) from free memory, reclaimable slab and the file LRU lists. Here 21 GiB is available, so the box is healthy despite free looking tiny.
If available is a small fraction of total and swap is climbing, you have a real problem worth chasing.
Per-process the honest way
Sort processes by memory and look at the top of the list:
ps aux --sort=-%mem | head -6
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
postgres 2417 1.2 18.4 9420112 5900312 ? Ss Jul18 42:11 postgres: writer
java 3810 6.0 12.1 8123400 3880220 ? Sl Jul19 88:02 java -Xmx4g -jar app.jar
redis 1902 0.4 3.2 1120044 1030880 ? Ssl Jul17 9:44 redis-server
prom 2201 2.1 2.8 2455010 905122 ? Ssl Jul18 30:15 prometheus
Two columns describe each process:
VSZ (virtual size): everything the process has mapped, including untouched mapped files, shared libraries, and reserved-but-unused heap. Ignore it for "who is using RAM."
RSS (resident set size): the pages actually in physical RAM right now. Closer to the truth, but it has one big flaw: RSS counts shared pages in full for every process that maps them. Twenty PHP workers sharing 200 MB of the interpreter each report that 200 MB in their RSS. Sum the column and you will "find" more memory used than the machine has.
PSS: stop double-counting
Proportional set size (PSS) splits shared pages fairly: the kernel docs define it as each page divided by the number of processes sharing it. If a 200 MB library is shared by 20 workers, each is charged 10 MB, so per-process PSS values sum to something close to physical usage. smaps_rollup gives the per-process totals without summing every mapping in smaps:
grep -E '^(Rss|Pss|Shared|Private)' /proc/3810/smaps_rollup
Rss: 3880220 kB
Pss: 3120044 kB
Shared_Clean: 540210 kB
Shared_Dirty: 210880 kB
Private_Clean: 98110 kB
Private_Dirty: 3030120 kB
Here RSS is 3.7 GiB but PSS is 3.0 GiB; the difference is shared libraries counted against everyone. Private_Dirty (3.0 GiB) is the interesting number: pages this process alone owns and dirtied. Kill the process and that is what you get back. For a fleet-wide view, smem -tk -c "name pss rss" (from the smem package) reads smaps for every process and gives you a PSS-sorted table without the arithmetic.
What top's columns actually mean
In top (press M to sort by memory) the relevant fields are RES, SHR, and %MEM:
- RES is the same resident set as
psRSS, shared pages included. - SHR is the portion of RES that is shareable (libraries, mapped files, shared memory segments).
RES - SHRroughly approximates the private footprint, which is a decent quick proxy for PSS when you do not want to read smaps.
RES 4 GiB with SHR 3.5 GiB is mostly shared pages and not your leak; RES 4 GiB with SHR 40 MB is private memory and deserves attention.
Containers live in cgroups, not free
Inside a container, free reports the host's totals, which is useless. The container's real limit and usage live in its cgroup. On cgroup v2:
cat /sys/fs/cgroup/memory.current
4187553792
cat /sys/fs/cgroup/memory.max
4294967296
grep -E '^(anon|file|slab|sock)' /sys/fs/cgroup/memory.stat
anon 3980210176
file 178954240
slab 24117248
sock 2097152
memory.current (about 3.9 GiB) against memory.max (4 GiB) says the container is one bad allocation from the OOM killer. In memory.stat, anon is heap and stacks and file is page cache charged to the cgroup; OOM kills with high anon mean a leak or an undersized limit. If yours is dying at the limit, see the Linux OOM killer for how that decision gets made.
When the culprit is the kernel
Sometimes ps and top add up to far less than used, and no cgroup explains it. The kernel itself is holding memory in slab caches (dentries, inodes, network buffers). slabtop shows it:
sudo slabtop --once --sort=c | head -8
Active / Total Size (% used) : 3120.44M / 3350.10M (93.1%)
OBJS ACTIVE USE OBJ SIZE SLABS NAME
8912340 8900112 99% 0.19K 424397 dentry
1204880 1201002 99% 1.05K 80325 ext4_inode_cache
980220 975003 99% 0.10K 25130 buffer_head
Millions of dentry objects usually means something is stat-ing or opening enormous directory trees (a backup job, a misbehaving find, a container churning files). Check Slab, SReclaimable, and SUnreclaim in /proc/meminfo for the split that matters: SReclaimable comes back under pressure, SUnreclaim does not, and a growing SUnreclaim points at a kernel or driver leak rather than a workload.
Swap thrashing: the smoking gun
A machine can have "used" swap and be perfectly fine. What hurts is active swapping: pages moving in and out constantly because the working set no longer fits.
vmstat 2 4
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
3 2 6820112 210044 40122 880210 4820 6110 5200 6300 8100 12200 14 9 20 57 0
2 3 6910220 198100 39980 861200 5100 6402 4900 6800 8400 12900 12 8 18 62 0
Watch si and so (memory swapped in from and out to disk per second). Sustained non-zero values in both, combined with high wa (I/O wait, 57-62% here), is thrashing: the CPU sits idle because everything is blocked on disk paging memory back and forth. A one-time so spike during a backup is normal; continuous churn is not. For an earlier warning than swap counters, memory pressure stall information (PSI) shows the time tasks spend waiting on memory.
A method that actually attributes memory
free -h: isavailablegenuinely low, or doesfreejust look scary? If available is healthy, stop, nothing is wrong.- If available is low, check swap with
vmstat 2. Sustainedsi/soplus highwaconfirms real pressure. ps aux --sort=-%mem | headto find candidates. Treat RSS as a hint, not a verdict.- Confirm the top suspect with
/proc/<pid>/smaps_rollup(PSS and Private_Dirty) orsmem. Private_Dirty is the memory you reclaim by killing it. - If processes do not add up to
used, checkslabtopand/proc/meminfofor kernel/slab growth. - In containers, ignore
freeentirely and readmemory.current/memory.max/memory.stat.
Questions people ask
Why does Linux show so little free memory?
Linux fills otherwise idle RAM with page cache, so the free column in free -h looks small on any machine that has been up for a while. That cache sits under buff/cache and is mostly reclaimable the moment a process asks for memory. The available column already accounts for it and is the number to watch. Low free with high available is a healthy machine.
What is the difference between RSS and PSS?
RSS counts every page a process has resident in RAM, including shared libraries, in full for every process that maps them, so summing RSS overstates usage. PSS divides each shared page by the number of processes sharing it, so the PSS values of all processes add up to roughly real physical use. Read both from /proc/<pid>/smaps_rollup, or get a sorted table from smem.
How do I check memory usage inside a Docker container?
Don't trust free inside a container; it reports the host. Read the cgroup v2 files instead: memory.current is the container's usage, memory.max its hard limit, and memory.stat splits usage into anon (heap and stacks), file (page cache), slab and sock. High anon near memory.max means a real leak or an undersized limit.
The call we'd make
Trust available over free, and trust PSS over RSS. Most "out of memory" pages are page cache doing its job, and the fix is to close the ticket. When it is real, the honest number is Private_Dirty (or per-cgroup anon), because that is the memory that actually disappears when you kill the offender. Everything else is either shared, reclaimable, or a rounding error. For the broader playbook, see the Linux troubleshooting guide.
Sources
Cite this article
Kiril Urbonas (2026). Find What's Eating Your RAM on Linux. DevOpsNess. Updated 2026-10-31. https://www.devopsness.com/blog/find-what-is-using-memory
[Find What's Eating Your RAM on Linux](https://www.devopsness.com/blog/find-what-is-using-memory) (Kiril Urbonas, DevOpsNess, updated 2026-10-31)
More from Linux
Explore more articles in this category
Linux "Permission Denied": Diagnose It Fast
A likelihood-ordered checklist for tracing "Permission denied" on Linux through mode bits, ownership, ACLs, SELinux, and mount options.
Linux Container Internals: Understanding How Containers Work
A container is a process with extra kernel features applied. Walking through namespaces, cgroups, and the actual mechanics — the level of detail that makes "container weirdness" debuggable.
Systemd Drop-In Overrides for Vendor Services: The Supportable Linux Ops Pattern
A practical systemd drop-in guide built from a real operations problem: vendor unit files kept changing, but the team still needed consistent restart, environment, and logging behavior.
You might have missed
Evergreen posts worth revisiting.