Memory: RSS vs cache, the OOM killer, swap, and pressure

Free memory is supposed to be small — the kernel spends idle RAM on page cache. Read MemAvailable, swap activity and memory pressure instead, and remember that summing RSS double-counts every shared page.

Read the briefing
About 4 min to read 12 drills

What to remember

  1. Alert on 'available', never on 'free'. Free is small by design. MemAvailable estimates what a new workload could get without swapping.
  2. Sum PSS, not RSS. RSS counts shared libraries in every process. smaps_rollup gives Pss, which divides them honestly.
  3. The OOM killer picks inside the failing cgroup. So on a container host the victim comes from the pod that hit its limit, adjusted by oom_score_adj.
  4. Memory PSI rises minutes before an OOM kill. It is the early-warning signal; free memory is not.
  5. A container can be OOM-killed with low RSS. The cgroup limit counts page cache and kernel memory too — read memory.stat.

The big picture

Linux memory questions are really about one misunderstanding: "free memory" is supposed to be small, because the kernel spends idle RAM on page cache. Once you internalize that, the rest follows: available versus free, RSS versus PSS, what the OOM killer actually chooses, what swap is for, and why PSI is the signal that warns you before any of it becomes an outage.

The mental model

RAM has three tenants: anonymous memory (heaps, stacks) that can only go to swap, file-backed page cache that can be dropped or written back, and kernel structures. Reclaim takes from the cheapest tenant first. Pressure is what you feel when reclaim cannot keep up; the OOM killer is the last resort when it fails entirely.

Diagrams

Where 64 GB of RAM actually goes
64 GB of RAM
+-- anonymous ....... heap, stack       -> swap, or OOM
+-- page cache ...... file data         -> dropped, free
+-- kernel / slab ... inodes, sockets   -> mostly pinned
+-- free ............ doing nothing     -> should be small

free -h shows:   used  |  buff/cache  |  free
                 ^^^^     ^^^^^^^^^^     ^^^^
                 real     reclaimable    idle

available = free + most of buff/cache    <- alert on THIS
The reclaim ladder, and where PSI starts moving
memory pressure rises
        |
        v
 drop clean page cache .............. cheap, invisible
        |
        v
 write back dirty pages ............. slower
        |
        v
 swap out anonymous pages ........... latency spike
        |                              PSI climbs HERE
        v
 OOM kill inside the failing cgroup .. exit code 137

In depth

free versus available, and the page cache

free -m shows a small "free" column on any healthy server, because the kernel fills spare RAM with page cache to avoid disk reads. The number that matters is available (MemAvailable), an estimate of how much a new workload could get without swapping, counting reclaimable cache and slab. Dashboards that alert on "free memory low" page you every day and teach the team to ignore memory alerts. Buffers and cache are reclaimable; dirty pages must be written back first, which is why a burst of writes can make reclaim slow. vmstat 1 shows si/so (swap in/out) and free/buff/cache; sustained so means anonymous pages are being pushed out and latency is about to get strange.

RSS, PSS, and why summing lies

VSZ is address space reserved (including never-touched mappings) and is nearly meaningless for capacity. RSS is pages actually resident, but shared pages, libraries, copy-on-write pages after fork, shared memory, are counted in every process that maps them, so summing RSS across a forking server (nginx, PostgreSQL, gunicorn) can overcount by several times. PSS divides shared pages among their sharers and is the honest number to sum; USS (private only) is what you would get back by killing the process. Read them from /proc/<pid>/smaps_rollup, or with smem. In containers, the number the limit is enforced against is the cgroup's memory.current (anon + page cache + kernel), which is why a container can be OOM-killed while its RSS looks fine: its page cache counts too.

OOM killer, swap, and PSI

When reclaim fails, the kernel picks a victim by oom_score, driven mostly by memory footprint and adjusted by oom_score_adj (-1000 disables, positive values make a process more attractive). In cgroup v2 the kill happens inside the offending cgroup first, which in Kubernetes means the container that hit its limit, not the node's biggest process. Evidence lives in dmesg/journalctl -k ("Out of memory: Killed process ...") and, for containers, in the pod's lastState.terminated.reason: OOMKilled with exit code 137.

Swap exists to move cold anonymous pages out so RAM can hold hot data; vm.swappiness biases reclaim between cache and anonymous pages. A little swap on a general server is healthy; heavy, continuous swapping is thrashing, and on latency-critical hosts (databases, validators) swap is often disabled deliberately so failures are fast and visible rather than slow and mysterious. Kubernetes historically required swap off for predictable accounting.

PSI (/proc/pressure/memory) is the early-warning signal: some avg10 rising means tasks are stalling on memory, full rising means nearly everything is; both climb minutes before an OOM kill, per cgroup as well as per host, which makes them far better alert sources than free memory.

Myths and facts

Myth: Low free memory means the server is running out of RAM.

Fact: Free is small by design; the page cache uses it. Look at MemAvailable, swap activity, and memory PSI.

Myth: Summing RSS gives total memory used.

Fact: Shared pages are counted per process; sum PSS from smaps_rollup instead.

Myth: The OOM killer kills the process using the most memory on the machine.

Fact: It kills the highest oom_score in the failing scope; with cgroup limits the victim is chosen inside that cgroup, adjusted by oom_score_adj.

Myth: Adding swap fixes memory pressure.

Fact: Swap trades latency for capacity; if the working set exceeds RAM, swap turns an OOM into thrashing.

Myth: Dropping caches (echo 3 > drop_caches) frees memory usefully.

Fact: It discards cache the kernel would have reclaimed anyway and hurts performance; it is a debugging tool, not a fix.

How pros do it

  • Alert on MemAvailable and memory PSI, never on 'free'.
  • Use PSS (smaps_rollup) for capacity questions and USS to know what killing a process returns.
  • Set memory limits on containers and protect critical processes with oom_score_adj deliberately.
  • Decide swap per role: on for general-purpose hosts, off (or minimal) for latency-critical services, and know why.
  • After any OOM, capture dmesg, the cgroup's memory.stat, and the workload's own metrics before restarting.

Questions people ask

free shows almost no free memory on a healthy host. Is it out of RAM?

No, and say so with the number: MemAvailable. The kernel spends idle RAM on page cache and hands it back the moment a process needs it, so 'free' is small by design and 'available' is the headroom. The caveat is dirty cache: pages waiting for writeback must be written before they can be reclaimed, so a write burst can make reclaim slow even when available looks fine.

A process was OOM-killed while the host had gigabytes free. How?

It hit its own cgroup's memory.max, which is enforced against anon plus page cache plus kernel memory charged to that group, so host memory never came into it; dmesg says 'Memory cgroup out of memory' and memory.events shows the oom_kill count. Then name the second case, a spike between monitoring samples, and say memory.peak or PSI history would show it. The caveat: a dashboard graphing RSS can look calm while memory.current sits at the limit.

Should production servers have swap?

Depends on the role, and they want the reasoning: a little swap on general-purpose hosts absorbs pressure by moving cold anonymous pages out; latency-critical hosts (databases, validators, trading systems) usually run without it so exhaustion fails fast and visibly instead of degrading into thrash. Either way, watch si/so and memory PSI, because heavy swapping shows up as latency, not as an OOM.

What would you alert on for memory?

MemAvailable and memory PSI, never 'free'. PSI some/full avg10 and avg60 are the share of time tasks stalled on memory, and they climb minutes before an OOM kill, per host and per cgroup. The caveat: a level threshold on available still misses a spike too fast to page on, which is why the PSI trend is the primary signal.

How do I find which process is growing?

Trend VmRSS and VmHWM in /proc//status, or Pss from smaps_rollup where shared pages matter, and compare with the cgroup's memory.current. Once you know which process, profile allocations inside the runtime (heap profiler, pprof, JFR); the kernel tells you who, not why.

What does swappiness actually do?

It biases reclaim between page cache and anonymous pages; 0 does not disable swap, it only makes the kernel strongly prefer dropping cache first. If the working set genuinely exceeds RAM no swappiness value saves you, which is the caveat worth saying out loud.

Further reading

Drills · 12

Answer in your head, or out loud, before you reveal. Mark each one: "Again" brings it back, "Got it" counts on your desk.

1 Pick the strongest answer

free -m on a healthy database host shows free: 412 and available: 51203 out of 64 GB. A junior engineer wants to add RAM. What do you tell them?

  1. Add swap so the cache can be paged out. Page cache is dropped, never swapped; swap is for anonymous memory.
  2. They are right; 412 MB free means the OOM killer is imminent. The OOM killer cares about reclaimable memory, which 'available' estimates.
  3. Run echo 3 > /proc/sys/vm/drop_caches nightly to keep free memory high. Dropping caches throws away useful data and forces re-reads from disk; it lowers performance for no benefit.
  4. The host is fine: the kernel uses idle RAM as page cache, which is reclaimable; 'available' is the number that predicts whether new allocations will succeed. 'free' is memory doing nothing; a well-used Linux box keeps it near zero on purpose.
In short

Free memory is supposed to be small, so the number that matters is available.

Why

Page cache is the kernel spending otherwise-idle RAM on avoiding disk reads, and it is given back the moment a process needs it. Reading free correctly is table stakes in Linux rounds; the interviewer is checking whether you know what MemAvailable estimates.

The common mistake

Reading the free column as headroom, and asking for more RAM on a machine that is perfectly healthy.

Read the docs

2 Pick the strongest answer

A container exits with code 137. What does that tell you, and what does it not?

  1. It is definitively an out-of-memory kill; no further evidence is needed. OOM is the common cause but not the only one; anything that sends SIGKILL produces 137.
  2. It was killed by SIGKILL (128 + 9). Usually that is the OOM killer hitting a cgroup limit, but a failed liveness probe or a shutdown timeout also ends in SIGKILL — check dmesg or the pod's lastState to know which. 137 identifies the signal, not the reason for it. The reason lives in kernel logs or the orchestrator's own record.
  3. The application returned 137 from its own main function. Exit codes above 128 in this convention encode a fatal signal, not an application return value.
  4. The host ran out of memory. With cgroup limits the kill usually happens inside the container's own cgroup while the host has memory to spare.
In short

137 means the process was killed by SIGKILL (128 + 9), but it does not tell you who sent it.

Why

Interviewers like 137 because the shallow answer ("OOM") and the correct answer ("SIGKILL, and here is how I would tell why") sound similar for the first five words. Naming the 128 + signal convention and then saying where you would go for evidence is the difference.

The common mistake

Saying 137 always means out of memory, and stopping there. A failed liveness probe or a shutdown timeout also ends in SIGKILL.

Read the docs

3 Answer out loud

A service on a 32 GB host was OOM-killed at 3 a.m. while monitoring showed 12 GB free. Talk me through how that can happen and how you would find out which case it was.

In short

A strong answer says the kill was most likely inside a cgroup memory limit, and reads dmesg and memory.events to prove which case it was.

What a strong answer does
  • mechanism: Names the cases: cgroup memory.max exceeded (most common), a sudden spike between monitoring samples, NUMA-node exhaustion, or unreclaimable kernel memory; and how the dmesg line and cgroup counters distinguish them.
  • method: dmesg for the killer's scope and victim stats, memory.events/memory.max for the cgroup, memory.peak or PSI history for the spike, and the service's own memory trend; then decide limit vs leak.
  • communication: Cases ranked by likelihood, each with the check that confirms it, ending in the decision.
Why

The Linux round is testing whether you know that memory has scopes (cgroup versus host) and that dmesg is the primary source. Ranking cases by likelihood and pairing each with its check is what a strong answer sounds like.

The common mistake

Blaming the monitoring, or answering 'the process using the most memory gets killed'. The killer is scoped to the cgroup that hit its limit, and free host memory is irrelevant inside it.

4 Pick the strongest answer

In free -h, what is the buff/cache column actually holding?

  1. File data the kernel is keeping in RAM so it does not have to read the disk again — reclaimable the moment a process needs the memory. Page cache and buffers are opportunistic. They look like used memory and behave like free memory.
  2. Memory permanently reserved by the kernel that applications can never use. It is the opposite: cache is the first thing reclaim takes.
  3. A leak counter that grows until the host is rebooted. Cache grows to fill idle RAM by design and shrinks under pressure.
  4. Memory that has already been written to swap. Swapped pages are not resident at all; cache is resident file data.
In short

buff/cache is file data the kernel is holding in RAM, and it hands it back the moment a program needs the memory.

Why

This is the single most common misreading of free. A healthy long-running server shows a large buff/cache and a small free, because RAM sitting idle is RAM being wasted. Reading this correctly is what lets you ignore the "low memory" panic and go look at MemAvailable and PSI instead.

The common mistake

Calling cache 'used memory', or suggesting a nightly drop_caches job to keep the free number looking good.

Read the docs

5 Read the output

A dashboard is alerting because free memory is under 400 MB. What do these two outputs together tell you?

$ cat /proc/pressure/memory
some avg10=0.00 avg60=0.00 avg300=0.00 total=1843
full avg10=0.00 avg60=0.00 avg300=0.00 total=402

$ free -h
               total        used        free      shared  buff/cache   available
Mem:            31Gi        11Gi       398Mi       120Mi        19Gi        19Gi
  1. The 120 MB of shared memory is the cause of the low free figure. 120 MB is noise against 31 GB; the cache accounts for the difference.
  2. Memory pressure is hidden because PSI only counts swap activity. PSI measures stall time on memory reclaim whether or not swap is configured.
  3. The host is about to OOM; free memory is nearly exhausted. 19 GB of that cache is reclaimable, which is exactly what MemAvailable is reporting.
  4. The host is healthy: 19 GB is available, and memory PSI is flat, so nothing is stalling on memory. The alert threshold is wrong. PSI at zero means no task has waited on memory reclaim. Available, not free, is the headroom number.
In short

The host is healthy: 19 GB is available and memory PSI is zero, so the free-memory alert is wrong.

Why

Alerting on free memory is the classic false-positive generator: it fires daily on healthy hosts and teaches the team to mute memory alerts, so the real one gets ignored too. Replace it with MemAvailable plus memory PSI and the alert only fires when something is genuinely stalling.

Read the docs

6 Scenario: what do you do next?

A Python service in Kubernetes restarts every few hours. kubectl get pods shows RESTARTS climbing and the last state is OOMKilled. The container has limits.memory: 512Mi. The team's dashboard shows container memory sitting at about 300 MB.

Step 1. Where do you look first?

  1. Blame the node and cordon it. A cgroup OOM is about this container's limit, not the node's health.
  2. Restart the deployment to clear the memory. The pod is already restarting on its own every few hours; doing it manually adds no information.
  3. Raise the limit to 1Gi and see if the restarts stop. It may well stop them, but you have learned nothing and the same leak will hit the new ceiling later. Measure before you resize.
  4. The cgroup's own accounting — memory.current and memory.stat inside the container — because the limit is enforced against anon + page cache + kernel memory, not against the RSS the dashboard is graphing. The gap between 300 MB on the dashboard and a 512 MB kill is almost always accounting: the dashboard is showing one component of what the limit counts.

Step 2. memory.stat shows anon at 180 MB but file at 300 MB, and the service writes large temporary files. What is happening?

  1. Page cache from its own file writes is counted against the cgroup limit, so the container reaches 512 MB even though its heap is small. Either give the limit room for the cache, or stop the service buffering that much file data. This is the classic cgroup surprise: file-backed cache the process caused counts toward its limit.
  2. The kernel is failing to reclaim cache and needs a newer version. Reclaim under a cgroup limit is normal; the kill happens when reclaim cannot keep up with the write rate, not because reclaim is broken.
  3. The Python heap is leaking; add a memory profiler. Anon is 180 MB and stable — that is the heap, and it is not the thing hitting the limit.

Step 3. What do you change so this does not recur?

  1. Remove the memory limit entirely. That converts a contained container restart into a node-wide OOM affecting unrelated workloads.
  2. Add a cron job to restart the pod nightly. A scheduled restart hides the signal and guarantees nobody looks again.
  3. Set the limit from measured memory.current under real load with headroom, alert on memory PSI for the cgroup rather than on RSS, and graph the same number the limit is enforced against. Fix the measurement first, then the limit; alerting on the number that actually kills you is the durable part.
In short

Read memory.current and memory.stat in the cgroup: the page cache from the service's own file writes counts toward the 512 MB limit, so size the limit from that number and alert on PSI.

Why

This scenario separates people who have read about cgroups from people who have debugged them. The senior move is to notice the discrepancy between the dashboard and the kill, and to go straight to the accounting rather than reaching for the limit slider.

Read the docs

7 Pick the strongest answer

A teammate sums the RSS column of ps for 40 nginx workers, gets 12 GB, and says the 8 GB host must be swapping. It is not. How is that possible?

  1. ps reports virtual size; use RSS from top instead. The column was RSS; VSZ would be even larger and equally misleading.
  2. ps is reading stale values from /proc. /proc is live; the numbers are correct for what RSS means.
  3. The kernel is compressing memory with zswap, so 12 GB fits in 8. Not swapping means no zswap activity; the discrepancy is accounting, not compression.
  4. RSS counts shared pages (libraries, shared memory) in every process that maps them; PSS divides shared pages among sharers, so the true footprint is far lower. smem or /proc//smaps_rollup gives PSS; summing RSS across a process family always overcounts.
In short

RSS counts shared pages in every process that maps them, so summing RSS overcounts; sum PSS instead.

Why

RSS, PSS and USS answer different questions: RSS is pages resident in this process's address space, PSS shares out the shared pages, USS counts only private pages. Capacity planning and container memory limits should use PSS or cgroup memory.current, never a sum of RSS. This is a favourite Production Engineering probe because it separates people who read numbers from people who understand them.

Read the docs

8 Read the output

Walk me through it: the host had 41 GB available at the moment of the kill. Why was java killed?

$ dmesg -T | tail -4
[Tue Sep  2 03:12:40 2026] Memory cgroup out of memory: Killed process 41822 (java) total-vm:9182212kB, anon-rss:3912440kB, file-rss:0kB, shmem-rss:0kB, UID:1000 pgtables:8420kB oom_score_adj:0
[Tue Sep  2 03:12:40 2026] oom_reaper: reaped process 41822 (java), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB

$ free -g
               total        used        free      shared  buff/cache   available
Mem:              64          21           9           0          33          41
  1. oom_score_adj 0 means it was the default victim. 0 is neutral; the victim is chosen by score within the cgroup, and here it was the only large process.
  2. A memory leak elsewhere on the host consumed the free memory at that instant. A host-wide OOM message says 'Out of memory: Killed process', not 'Memory cgroup out of memory'.
  3. The JVM's heap setting exceeded physical RAM. total-vm 9 GB is address space; the kill decision was about the cgroup's 4 GB of resident anonymous memory.
  4. It exceeded its cgroup's memory.max (about 4 GB here), so the OOM killer ran inside the cgroup; host-wide memory was irrelevant. 'Memory cgroup out of memory' names the scope. Container and systemd memory limits are cgroup limits.
In short

java hit its own cgroup's memory.max, so the OOM killer ran inside that cgroup; free host memory did not matter.

Why

The first words of the dmesg line say which OOM killer ran. Cgroup OOMs are the common case in containerized environments and they happen with plenty of host memory free, which is exactly what confuses people. The fix is the limit or the leak, and for a JVM it means aligning heap plus off-heap to the cgroup limit.

Read the docs

9 Scenario: what do you do next?

A bare-metal Solana RPC host (512 GB RAM) has p99 RPC latency climbing over an hour. CPU is 35%, no OOM kills in dmesg, disk I/O looks normal. vmstat 1 shows si/so in the tens of thousands of KB/s. The accounts database is memory-mapped.

Step 1. What is your read of the situation and what do you check to confirm?

  1. Increase swappiness so the kernel swaps more aggressively. The problem is that it is swapping at all.
  2. Add more RPC threads to handle the latency. More threads touch more memory; the constraint is memory, not concurrency.
  3. Restart the RPC process to clear its caches. It drops the mmap'd working set and forces a cold start; latency gets worse before it gets better and the cause returns.
  4. The host is swapping anonymous memory: the working set exceeds RAM minus what mmap'd files need. Confirm with /proc/pressure/memory, free -g, and smem//proc/<pid>/status for the validator process's RSS and swap. Swap-in/out with no OOM is the signature of memory pressure being absorbed by swap; PSI quantifies the stall.

Step 2. PSI shows full avg60=18%; the RPC process has 40 GB in swap. A large index for getProgramAccounts was enabled yesterday. What is the mitigation?

  1. Disable swap entirely with swapoff -a. With the working set larger than RAM, removing swap converts latency into an OOM kill.
  2. Shed the memory-hungry feature: disable the new index (or move heavy getProgramAccounts traffic to a dedicated node) and let the working set fit; consider vm.swappiness low and memory.low protection for the RPC process afterwards. Reverse the change that grew the working set past RAM; that is mitigation aimed at the proven cause.
  3. Drop the page cache. The cache is holding the mmap'd accounts data the node reads constantly; dropping it multiplies disk reads.
  4. Raise the process's oom_score_adj so it is never killed. Nothing is being killed; this protects against a problem you do not have.

Step 3. Systemic fix?

  1. Capacity rule tying enabled indexes to RAM (working set + headroom), PSI-based alerting on memory stall time, and separating heavy-query RPC nodes from latency-critical ones. Mechanisms: a rule that prevents the change, an alert that catches it early, and topology that limits blast radius.
  2. Ban swap on all hosts. A policy about the symptom; and swap as a shock absorber is defensible when monitored.
  3. Buy 1 TB of RAM for every node. Expensive and it does not stop the next index from outgrowing it.
In short

The host is swapping because the new index pushed the working set past RAM; confirm with memory PSI, disable the index, then tie enabled indexes to a RAM budget.

Why

Swapping is the kernel's way of not killing you, at the price of latency; PSI tells you how much time the system is losing to it. On chain infrastructure the memory working set is a first-class capacity dimension because indexes and account databases are memory-mapped. The interview shape: read the signature, confirm with the right counters, reverse the change, then encode the capacity rule.

Read the docs

10 Quick recall

A dashboard says a host has 400 MB free. Which single /proc/meminfo field do you quote back to say whether it is actually short of memory?

In short

MemAvailable is the field that estimates how much memory a new workload could get.

Accepted

MemAvailable · mem available · available

Why

MemAvailable is the kernel's own estimate, and it already accounts for reclaimable page cache and slab. It is the field every memory alert should be built on, and the one number to quote when somebody says a host is "out of RAM".

Read the docs

11 Quick recall

You want the one kernel signal that rises minutes before an OOM kill: the share of time tasks are stalled waiting on memory. Where do you read it?

In short

/proc/pressure/memory reports memory pressure stall information.

Accepted

/proc/pressure/memory · proc/pressure/memory · pressure/memory

Why

/proc/pressure/{cpu,memory,io} (PSI) report 'some' and 'full' stall percentages over 10s/60s/300s windows; rising memory 'full' predicts OOM kills.

12 Find what's broken

After this tuning file was applied to a fleet of 64 GB application hosts with 8 GB swap, services began failing to start with Cannot allocate memory while free showed plenty available, and hosts felt sluggish. Which two lines?

# /etc/sysctl.d/90-tuning.conf
vm.swappiness = 100
vm.overcommit_memory = 2
vm.overcommit_ratio = 50
vm.max_map_count = 262144
net.core.somaxconn = 4096
fs.file-max = 2097152
In short

Lines 3 and 4 turn on strict overcommit with a commit limit of only 40 GB, so allocations fail while memory sits free.

What's broken
  • Line 3: overcommit_memory=2 disables heuristic overcommit: allocations are refused once committed address space exceeds swap + ratio% of RAM.
  • Line 4: With strict overcommit, ratio 50 makes CommitLimit = swap + 50% of RAM = 40 GB on a 64 GB host, so half the RAM can never be promised.
Why

Strict overcommit is a legitimate choice for some databases, and a foot-gun when copied into a generic tuning file: many programs reserve far more address space than they touch, so allocations fail while memory sits idle. swappiness=100 (line 2) is aggressive but not the cause of allocation failures; max_map_count and somaxconn are harmless here. Interviewers like this because it tests whether you know what 'Cannot allocate memory' with free RAM means.

Read the docs

Next lesson Processes and signals: states, zombies, PID 1, and PID exhaustion
Drill · Memory
0:00

Loading…