Lesson 8 of 13 · 14m
What Memory Is Actually Used
`available` beats `free`, `PSS` beats `RSS`, and a leak is growth that never plateaus.
free -h reports a free column, and every week someone files "the server is out of memory" because that column is small. The page cache is not usage — it is the kernel holding recently-read file data that any application can reclaim on demand. The column that means something is available: the kernel's estimate of memory a new process could allocate without swapping, which counts most of cache as usable. "Linux ate my RAM" is a meme precisely because this misreading is universal.
The per-process version of the same lie
RSS counts shared pages fully in every process that maps them — sum RSS across a worker pool and you double-count libc, mmap'd files, and shared memory segments. VSZ is worse: virtual size counts reservations, not resident pages, and a process can carry terabytes of VSZ on a gigabyte host. The honest number is PSS in /proc/<pid>/smaps_rollup: shared pages divided among their sharers. A worker showing 400 MB RSS that shares 300 MB of it with its siblings costs you roughly 100 MB.
Where memory actually leaks
Language runtimes allocate from their own allocators, so the leak is usually in a cache, not in malloc. Unbounded maps, growing buffers, per-request structures retained by a closure — the process graph climbs linearly for days. That slope is also how you distinguish a leak from a warmup plateau: leaks do not level off.
For C/C++, heaptrack records every allocation with its stack; valgrind --tool=massif gives heap-over-time; both show which call tree holds the growth. jemalloc has built-in profiling (MALLOC_CONF=prof:true,prof_prefix:/tmp/jem) consumable by jeprof. Go's runtime/pprof heap endpoint (/debug/pprof/heap) reports alloc_space versus inuse_space — in-use is the leak signal.
The glibc arena gotcha
glibc malloc keeps per-thread arenas — by default up to eight times the core count on 64-bit — specifically to keep threads off one central lock. Under fragmentation, a 64-core box grows dozens of arenas that each hold freed-but-unreturned memory, and RSS climbs while the real heap stays flat. M_ARENA_MAX caps the arena count; jemalloc or tcmalloc replaces the allocator outright and usually returns memory better. The symptom pattern: RSS scales with thread count while heaptrack and pprof show no leak. That is arena bloat, not a leak.
Swap is not automatically failure
Swap usage alone is not an emergency — the kernel swaps cold pages it is confident are idle (vm.swappiness biases the choice), and a box with 2 GB in swap and zero swap I/O is fine. The failure mode is swap activity: vmstat's si/so columns doing sustained work while iostat shows the swap device hot. Memory pressure announces itself in /proc/pressure/memory long before the OOM killer fires — the some/full stall averages tell you threads are already waiting on reclaim. When you need PSS without parsing smaps by hand, smem -k and ps_mem print it per process.
Evidence
OOM kills are the evidence people misread most. The kernel picks a victim by oom_score, a heuristic over footprint and niceness, and it often kills the biggest victim, not the leaking cause. After a kill, journalctl -k holds the oom-killer's dump — per-task RSS at kill time and the chosen victim's name. Read it before assuming the named process was the problem.
The practice
- Read
available, notfree; per process, readPSSinsmaps_rollup, not RSS. - Leak = growth that never plateaus; confirm with the allocator's own view (heaptrack, massif, pprof) before blaming the kernel.
- On multithreaded glibc bloat, try
M_ARENA_MAXor jemalloc before hunting phantom leaks. - After an OOM kill, read the kernel dump — the named victim is not automatically the culprit.
Was this lesson helpful?
Keep reading
Related articles from the SudoSecurity blog.
Your Minecraft Server Isn't Slow, It's Misconfigured
Can't keep up! is not a hardware message. It's the server telling you a tick took longer than 50ms, and almost every cause is a default nobody changed. Here's what actually moves MSPT, with the flags that are now wrong and the setting that isn't where every guide says it is.
Your Minecraft Server Wants Java 25, Not Java 26
Every six months the same thread appears and nobody maps the JVM engineering onto what a Minecraft server actually does. This does — version by version, with the flag most guides still tell you to set that will eventually stop your server from booting.
Your Container Is Running SerialGC and Nobody Told You
You tuned G1 flags for a week. Your pod has one CPU, which means the JVM quietly picked a single-threaded collector at startup and ignored every flag you set. Here is the OpenJDK source that made that decision.
How to Debug Minecraft Server Lag with Spark Profiler (2026 Guide)
Your server dropped to 12 TPS. You copied Aikar's flags. You upgraded Java. Nothing changed. That's because JVM flags don't fix plugin bugs. Here's how to find what's actually killing your tick budget.