CH-J Toolsserver management over SSH
Menu
All guides and articles →

How to read RAM, cache and swap on a Linux server

What the columns of free mean, why high memory use is often fine, and which signs really point to a memory shortage.

Is low free RAM actually a problem?

You open a server dashboard and almost all RAM appears occupied. Before restarting anything, check whether applications are slow and whether Linux still has memory available for new work. A file server that has just read many files can have very little unused RAM while remaining healthy. Its cache avoids repeated storage reads.

Run these commands on the Linux server, including when your SSH client runs on Windows. The examples use the usual procps tools on Ubuntu, Debian and RHEL systems. They inspect memory without changing settings. Container images may omit the tools or show a different resource scope from the host.

free -h
grep -E '^(MemTotal|MemFree|MemAvailable|Buffers|Cached|Shmem|SReclaimable):' /proc/meminfo

Start with available, then follow its trend during the affected workload. Keep the observation time and workload alongside the numbers. A snapshot after a job has finished cannot explain what happened at its peak. There is no universal percentage that proves every server is short of RAM.

What do free, available and cache mean?

MemFree is RAM currently unused. MemAvailable estimates how much memory new applications can get without swapping, taking reclaimable memory and kernel reserves into account. It is an estimate, not a reservation or a guarantee that every allocation will succeed. The used calculation in free has changed between tool versions, so check definitions before comparing that column across machines.

  • Clean file cache can usually be reclaimed because its contents can be read from storage again. Dirty pages need writeback before they can be discarded safely.
  • Buffers and kernel slab caches serve different kernel needs. SReclaimable identifies a potentially reclaimable part of slab, not a promise that all of it can disappear immediately.
  • Shmem covers tmpfs and several forms of shared memory. These pages hold live data; they cannot simply be discarded like a clean copy of a file. Swap may provide backing where permitted.

When cache looks large but available remains low, inspect tmpfs usage before assuming that cache is harmless. In df output, Size is the filesystem limit and Used is current filesystem usage; the limit is not RAM already allocated. This check does not account for every kind of shared memory.

df -h -t tmpfs

Does occupied swap mean the server is thrashing?

Not by itself. Linux can leave infrequently accessed pages in swap after earlier pressure has passed. Bringing them all back proactively would consume RAM without helping the current workload. Check whether pages are moving now, rather than treating a nonzero swap usage figure as an incident.

swapon --show
vmstat 1 10

swapon lists active swap areas and their usage. In vmstat, si is the swap-in rate and so is the swap-out rate, normally in KiB per second with default units. The first report contains rates averaged since boot; use the following one-second reports to judge current activity. Memory amounts in the first report are still current snapshots.

Repeated swapping together with falling available memory and worsening response times supports a diagnosis of memory pressure. A brief burst alone does not prove harmful thrashing. Conversely, a server with no swap can suffer severe reclaim stalls or OOM kills while si and so remain zero. Swap activity is one signal, not a complete health check.

How do you confirm pressure and OOM events?

On kernels with Pressure Stall Information enabled, /proc/pressure/memory reports time lost while tasks wait because of memory pressure. The some line concerns at least some tasks; full concerns all non-idle tasks stalling simultaneously. avg10, avg60 and avg300 are percentages over those time windows in seconds. Compare them with normal behaviour and application latency. If the file is absent, continue with the other checks.

if [ -r /proc/pressure/memory ]; then cat /proc/pressure/memory; fi
sudo journalctl -k -b --since '1 hour ago' --no-pager | grep -iE 'out of memory|oom-kill|killed process|memory cgroup'

The journal command is for systemd hosts and searches the current boot over the last hour. Read surrounding kernel messages to establish the scope. No matching output does not prove that no kill occurred: the event may be older or outside retained logs. Service logs may explain exits that were not kernel OOM kills.

A container or service can hit its own cgroup limit while the host still has available memory. On cgroup v2, inspect memory.current, memory.max and memory.events in the affected cgroup, including ancestor limits. A memory.max value of max means no limit at that level. Compare event counters before and after the incident; a historical oom_kill count does not date the failure. Use the actual workload cgroup rather than assuming a fixed path.

Which processes and kernel allocations use the RAM?

Sort processes by resident set size to find candidates. RSS is resident memory in KiB here, not the virtual address space reserved by a process. VSZ can be large without an equivalent physical allocation. Check process identity and the owning service; the largest database process may be using exactly the cache it was configured to use.

ps -eo pid,user,rss,comm --sort=-rss | head -15
sudo slabtop -o

Shared pages appear in the RSS of every process mapping them, so adding RSS values double counts some memory. PSS apportions shared pages between processes and helps compare worker pools. If installed, smem can report PSS. For a selected PID, /proc/PID/smaps provides mapping details where permissions allow. Avoid repeatedly scanning every mapping on a busy host.

slabtop shows kernel slab allocations and normally needs elevated permissions. A large slab deserves investigation when it grows without settling, but process RSS will not explain all kernel memory. Filesystem caches such as ZFS ARC also require their own interpretation. Follow growth over comparable workloads before calling it a leak.

How do you relieve a confirmed shortage safely?

Choose the response from the evidence. First distinguish host capacity from a workload limit. Then make one controlled change so you can tell whether it helped. Use the service runbook for changes that affect running jobs.

  1. Capture available memory, swap activity, the largest processes and relevant logs before changing anything. Record which requests or jobs are affected.
  2. Reduce incoming work or defer an identified optional batch job through its scheduler. Check ownership and dependencies before stopping a workload.
  3. If worker counts, application caches or container limits explain the problem, adjust the documented setting with a rollback plan. Raising a container limit requires spare capacity on the host.
  4. If legitimate peak demand exceeds capacity, plan more RAM or distribute the workload. Extra swap can provide breathing room in suitable configurations, but cannot replace RAM for a continuously active working set.
  5. If a process keeps growing under comparable demand, preserve diagnostic evidence and investigate the application. Use a planned graceful restart only when service impact and recovery are understood.

Forcefully killing a process can lose in-flight work and trigger recovery or downtime. Verify the PID, service role and recovery procedure before terminating anything; do not kill the largest process merely because it tops the list.

How do you verify that the change worked?

Repeat the same observations during a comparable workload. This short sample is a starting point, not a substitute for watching a complete peak period. The second command supplies repeated interval measurements while free gives the before and after snapshots.

free -h
vmstat 1 10
free -h
  • Available memory should stop trending down under steady demand and leave room for expected bursts.
  • Swap traffic and memory pressure stalls should settle to an acceptable level for this workload, with application response times recovering.
  • Check for new OOM events and service failures after the change, and confirm that the deferred work can eventually complete.

Do not require occupied swap to return to zero. Recovery means useful work proceeds reliably. If reducing concurrency improves memory but creates an unacceptable queue, the incident is contained and the capacity problem still needs a lasting solution.

Which quick fixes should you avoid?

Do not schedule drop_caches to make free memory look larger. The kernel already reclaims suitable caches; forcibly dropping them can replace useful cache hits with storage reads and additional CPU work. It does not fix an application leak or make live shared memory disposable.

Do not run swapoff just to clear the swap figure on a pressured production host. Moving swapped pages back needs memory and can cause serious stalls or allocation failures. Deleting tmpfs contents can also destroy application data; identify owners and backups before any cleanup.

Changing swappiness blindly does not establish why the server is short of memory. It changes reclaim preferences, not the amount of RAM installed. Avoid combining several kernel tuning changes during diagnosis, because that obscures both the cause and any improvement.

How do you prevent the next memory incident?

Build a baseline covering ordinary traffic, backups and scheduled imports. Track available memory alongside latency, swap activity, pressure and OOM events. Alert on sustained departures from the baseline rather than one high used percentage. Include container limits in capacity reviews so healthy host totals do not hide constrained services.

Budget application caches and worker concurrency together. Several individually reasonable settings can exceed host capacity when jobs overlap. Leave headroom for the kernel, filesystem activity and operational tools. After deployments, compare memory behaviour under equivalent demand and record changed limits. A reproducible upward trend is much more useful to an application owner than a screenshot of a nearly full bar.

How does CH-J Tools show Linux memory?

System Monitor reads these values over SSH. On Linux it defines used as MemTotal − MemFree − Buffers − Cached − SReclaimable, while available is the kernel estimate. Shared memory is included in Cached and is not freely releasable. The categories in the memory bar do not overlap.

Because some versions of free use a different formula, their used values may not match the app exactly. System Monitor also shows swap with its usage history. ZFS ARC is not treated separately, so on ZFS hosts it counts as used memory.

Frequently asked questions

Why is Linux using almost all my RAM?

Linux uses spare RAM for caches. Check available memory, current pressure and application behaviour before treating high usage as a shortage. A large cache alone is not a fault.

Why is swap still used after I added RAM?

Cold pages can remain swapped out until accessed. A nonzero occupied amount does not require cleanup; examine current si and so rates and response times instead.

Can a container run out of memory when the host has free RAM?

Yes. Its cgroup limit, or an ancestor limit, can prevent further allocation. Inspect the workload limit and memory events from the host or through the container management tools.

Does a large RSS prove a memory leak?

No. Databases, runtimes and worker pools can retain memory intentionally. Investigate continued growth under comparable workload, using application diagnostics and PSS where shared pages matter.

Is the Size column for tmpfs reserved RAM?

No. It is a filesystem capacity limit, not preallocated memory. Actual contents consume memory and potentially swap; a large empty tmpfs does not consume its displayed capacity.

Detailed documentation

man: free →

man: proc_meminfo →

man: vmstat →

man: tmpfs →

man: proc_pid_smaps →

Linux kernel: Pressure Stall Information →

Linux kernel: cgroup v2 memory controller →

Linux kernel: virtual memory sysctls →

Biometric unlock and security →

All tutorials by category →