A Linux host can look short on memory when much of the used value is reclaimable cache rather than application pressure. Clear memory only after checking available memory, cache, and swap so a one-time reclaim does not hide a process leak or slow the next disk-heavy workload.
The kernel reclaims page cache and many slab objects automatically when applications need memory. The /proc/sys/vm/drop_caches sysctl is a manual, one-shot request to discard clean page cache, dentries, and inodes; running sync first writes dirty data so more cached objects are eligible.
Use cache dropping for testing, recovery after a known cache-heavy job, or a controlled maintenance action, not as a recurring scheduler task. If available remains low after caches are dropped, or swap-in activity continues, investigate memory pressure and process resident memory instead of repeating the same cleanup.
Related: How to check memory usage in Linux
Related: How to check swap memory usage in Linux
Steps to clear reclaimable memory in Linux:
- Check current memory and swap usage.
$ free -h total used free shared buff/cache available Mem: 11Gi 883Mi 7.9Gi 29Mi 3.1Gi 10Gi Swap: 4.0Gi 512Mi 3.5Giavailable estimates how much memory can be used by new applications without swapping. buff/cache is the cache and buffer total that may shrink after a cache drop.
- Flush dirty filesystem data before dropping caches.
$ sudo sync
drop_caches discards clean cached objects only, so syncing first gives the kernel more clean cache candidates.
- Drop clean page cache, dentries, and inodes once.
$ sudo sysctl -w vm.drop_caches=3 vm.drop_caches = 3
vm.drop_caches=3 discards reclaimable cache but does not fix a memory leak. It can make the next file reads slower while the kernel rebuilds cache from disk.
- Check memory again after the cache drop.
$ free -h total used free shared buff/cache available Mem: 11Gi 871Mi 10Gi 29Mi 942Mi 10Gi Swap: 4.0Gi 512Mi 3.5GiA lower buff/cache value and higher free value confirm that clean caches were reclaimed. If available is still low, cache was not the main constraint.
- List active swap areas before touching swap.
$ swapon --show NAME TYPE SIZE USED PRIO /var/lib/swap file 4G 512M -2
If no rows appear or USED is 0B, skip the swap refresh steps.
- Disable swap only when the used swap can fit back into available RAM.
$ sudo swapoff -a
swapoff -a moves swapped pages back into memory and can trigger out-of-memory kills when available is too low for the USED swap amount.
- Re-enable configured swap areas.
$ sudo swapon -a
swapon -a enables swap entries from /etc/fstab unless an entry is marked with noauto.
- Verify that swap is active again.
$ swapon --show NAME TYPE SIZE USED PRIO /var/lib/swap file 4G 0B -2
The USED value returning to 0B shows that the previous swap contents were cleared.
- Check memory pressure before repeating cleanup.
$ cat /proc/pressure/memory some avg10=0.00 avg60=0.00 avg300=0.00 total=124503 full avg10=0.00 avg60=0.00 avg300=0.00 total=0
Sustained non-zero some or full pressure after cache and swap cleanup points to workload sizing, cgroup limits, or memory-heavy processes.
Related: How to check memory pressure in Linux
Related: How to check process CPU and memory usage in Linux
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.