High memory usage on Linux can slow interactive workloads, increase latency, and cause applications to compete more aggressively for RAM. Reclaiming memory from file caches, idle processes, and swap keeps systems responsive, especially on shared servers and virtual machines with limited resources.
The Linux kernel aggressively uses otherwise free RAM as page cache for files and filesystem metadata, exposing the current state through tools such as free, top, and htop. Cached memory is automatically released when applications need space, but explicit cache dropping through /proc/sys/vm/drop_caches and careful management of heavy processes and swap allows tighter control in constrained environments.
Manual cache clearing and process termination require root privileges and must be used with awareness of workload patterns. Excessive cache flushing can degrade performance by forcing repeated disk reads, disabling swap on a busy host can trigger out-of-memory kills, and killing critical daemons can interrupt services. Targeted cache clearing, cautious swap refresh, and verification commands minimise disruption on production systems while recovering memory.
Related: How to check memory usage in Linux
Related: How to check memory pressure in Linux
$ free -h
total used free shared buff/cache available
Mem: 23Gi 1.2Gi 20Gi 13Mi 1.7Gi 21Gi
Swap: 1.0Gi 0B 1.0Gi
The buff/cache column shows memory that can be reclaimed if applications need more space.
$ sudo sync $ echo 1 | sudo tee /proc/sys/vm/drop_caches 1
Value 1 for vm.drop_caches clears only the page cache; using tee with sudo ensures /proc/sys/vm/drop_caches is written with root privileges.
$ sudo sync $ echo 2 | sudo tee /proc/sys/vm/drop_caches 2
Value 2 for vm.drop_caches drops cached directory entries and inodes while leaving the page cache intact.
$ sudo sync $ echo 3 | sudo tee /proc/sys/vm/drop_caches 3
Value 3 clears page cache, dentries, and inodes; only one vm.drop_caches value is needed per cache clear, and aggressive clearing can temporarily reduce performance as caches are rebuilt from disk.
$ free -h
total used free shared buff/cache available
Mem: 23Gi 1.0Gi 22Gi 13Mi 389Mi 22Gi
Swap: 1.0Gi 0B 1.0Gi
A lower buff/cache value or higher free and available values indicate that caches were successfully dropped.
$ top -b -n 1 | head -n 12
top - 08:03:55 up 1 day, 18:54, 0 user, load average: 0.20, 0.20, 0.19
Tasks: 11 total, 1 running, 10 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.9 us, 0.0 sy, 0.0 ni, 99.1 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
MiB Mem : 23745.0 total, 22640.5 free, 1038.3 used, 391.3 buff/cache
MiB Swap: 1024.0 total, 1024.0 free, 0.0 used. 22706.7 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1 root 20 0 20928 11752 8988 S 0.0 0.0 0:01.41 systemd
23 root 19 -1 42740 12620 11028 S 0.0 0.1 0:00.18 systemd-j+
171 message+ 20 0 9748 4648 3844 S 0.0 0.0 0:00.70 dbus-daem+
174 root 20 0 17788 7812 6792 S 0.0 0.0 0:00.24 systemd-l+
1426 systemd+ 20 0 90764 7200 6268 S 0.0 0.0 0:01.34 systemd-t+
$ htop
Sort by RES or MEM% to locate processes that reserve the most memory and note their PID values.
$ sudo kill [PID] $ sudo kill -9 [PID]
Use kill with the default signal first and reserve kill -9 for processes that refuse to exit, because forced termination can interrupt in-flight work and leave temporary files or locks behind.
$ sudo swapoff -a
Disabling swap on a heavily loaded system can trigger out-of-memory kills if available RAM is insufficient, so perform this action during low utilisation periods.
$ sudo swapon -a
Confirm swap state with free -h or swapon --show if detailed information about swap devices is required.
$ sudo reboot
Rebooting stops all running processes and services, so schedule this action to avoid interrupting users or critical workloads.
$ htop $ top
Interactive tools such as htop provide an ongoing view of CPU, RAM, swap, and per-process usage that is useful for capacity planning and spotting memory leaks.