Investigate Linux memory pressure before adding swap. Swap can provide breathing room for less-active pages, but sustained swapping can make an application extremely slow. It does not create the same performance or capacity as additional RAM.
IN THIS ARTICLE
Gather the details you will need
Confirm whether this is a physical host, VM or container and what memory controls apply. Record workload peaks, current swap, available disk and any provider restrictions. Avoid creating a swap file on a full or unsupported filesystem.
01 Diagnose memory pressure before adding Linux swap
- Inspect
free -h,swapon --showand a shortvmstatsample. Focus on available memory, swap-in/out activity and workload latency rather than interpreting cached memory as wasted RAM. - Check kernel OOM events and cgroup/container limits. A service can hit its own memory ceiling while the overall host still has free memory.
- Identify large or growing processes and correlate them with expected work. Fix a leak, runaway concurrency or oversized cache where evidence supports it.
- If additional swap is appropriate, choose the distribution-supported file or partition procedure for the actual filesystem. Swap files on copy-on-write filesystems have specific restrictions; do not use a generic sparse-file recipe.
- Enable the reviewed swap area, verify its visibility and add a tested persistent entry if intended. Tune policy only with measured workload evidence and keep storage latency under observation.
02 Example: distinguish low free memory from sustained pressure
Run this short read-only sample on the Linux server during the reported slowdown. It displays current RAM, configured swap and several observations of memory activity. No swap file is created and no process is terminated.
free -h
swapon --show
vmstat 1 5
Read the result: Read available memory alongside free memory because the kernel can reclaim some cache. Persistent swap-in and swap-out activity in later vmstat samples may indicate pressure; a nonzero amount of used swap alone does not show active thrashing. Check application latency at the same time.
Compare the workload with any container or service limit before buying more RAM or adding swap. Swap is not a substitute for correcting an unbounded job or memory leak, and its storage performance matters. Keep the sample and incident time so you can compare behaviour after the chosen change.
Does nonzero swap usage mean the server is currently overloaded?
Not by itself. Older inactive pages can remain in swap after pressure subsides. Current swap traffic, available memory and application latency provide a better picture.
Confirm the expected result
Confirm the server avoids uncontrolled memory exhaustion and application response remains acceptable during a representative peak. Check that swap use stabilizes rather than growing continuously and that the storage backend retains enough capacity.
If the problem continues
If the system continues heavy swap-in/out, reduce workload pressure or add suitable RAM instead of increasing swap indefinitely. Do not drop caches repeatedly as a memory-management strategy. Removing active swap can itself require enough free memory, so plan that change rather than running swapoff on a pressured server.