If your Linux system or virtual machine appears to be using a lot of memory, you may be wondering how to clear VM cache. Linux uses available RAM to cache recently accessed files and filesystem information. This cache can make a computer faster, and Linux normally releases it automatically when applications need memory. In most cases, a large cache is not a problem and does not need to be cleared.
When you do need to test memory behavior, troubleshoot a specific application, or temporarily reclaim cached memory, you can clear Linux’s page cache, dentries, and inodes with a command. This guide explains what VM cache means, how to clear it safely, what the commands actually remove, and what to check if your system is still low on memory.
What Does VM Cache Mean?
In Linux, “VM” commonly refers to the virtual memory subsystem, not necessarily to a virtual machine. VM cache is memory the kernel uses to keep useful data readily available. It includes the page cache, which stores recently read file contents, as well as dentries and inode information that helps the system find files and directories.
Cached data is usually reclaimable. If an application needs more RAM, Linux can discard suitable cache and use that memory for the application. That is why a system may report that most RAM is “used” while still having plenty of memory available for work.
A virtual machine can also have cache inside its guest operating system, while the hypervisor or host may maintain its own caches. Clearing the Linux cache inside a guest affects the guest’s kernel cache; it does not necessarily clear caches held by the host or virtualization platform.
Check Memory Before Clearing the Cache
Before running a cache-clearing command, check whether memory pressure is actually occurring. Open a terminal and run:
free -h
Focus on the “available” value, not just the amount shown as “used.” Available memory estimates how much RAM can be provided to applications without swapping heavily. You can also inspect memory and swap activity in more detail with:
cat /proc/meminfo
vmstat 1 5
If the machine is responsive and has reasonable available memory, clearing the cache is unlikely to improve performance. It may make file access slower temporarily because the system will need to read data from storage again.
How to Clear VM Cache on Linux
Linux provides the /proc/sys/vm/drop_caches interface for dropping certain clean caches. You need administrative privileges. First, run sync to ask the kernel to write pending filesystem data to storage. Then use the option that matches what you want to clear.
-
Clear page cache: Use the value
1. -
Clear dentries and inodes: Use the value
2. -
Clear page cache, dentries, and inodes: Use the value
3.
To clear all three categories, run:
sudo sh -c 'sync; echo 3 > /proc/sys/vm/drop_caches'
Alternatively, you can use tee to write the value as root:
sync
echo 3 | sudo tee /proc/sys/vm/drop_caches
The sync command is important because it requests that pending writes be committed before the kernel drops caches. The cache-clearing operation does not erase your files or remove application data. It discards eligible cached information that Linux can load again when needed.
To clear only the page cache, use:
sudo sh -c 'sync; echo 1 > /proc/sys/vm/drop_caches'
To clear only dentries and inodes, use:
sudo sh -c 'sync; echo 2 > /proc/sys/vm/drop_caches'
Afterward, check memory again with free -h. The reported cache value may fall, but Linux may begin caching data again almost immediately. That is normal: caching is part of how the operating system uses spare RAM efficiently.
What the Cache-Clearing Options Do
The page cache holds copies of file data that has been read from storage. Dropping it can be useful when you need to run a controlled benchmark that measures cold file reads. It can also help with certain troubleshooting tasks. It is not a general-purpose way to make an otherwise healthy computer faster.
Dentries are directory-entry records, and inodes hold filesystem metadata about files. Dropping these caches may be useful when testing filesystem behavior or diagnosing a specific issue. The kernel can rebuild them as directories and files are accessed again.
Using 3 requests that the kernel drop both the page cache and the dentry and inode caches. It does not mean “free all memory.” Memory used by running applications, kernel structures, and other non-reclaimable data remains in use. Linux also does not promise that every memory statistic will immediately become zero or change in exactly the way you expect.
Can You Clear VM Cache on Windows?
If by “VM cache” you mean memory cache inside a Windows virtual machine, the Linux drop_caches command does not apply. Windows manages its own standby memory and file cache, and it generally reclaims this memory automatically when applications need it.
For routine use, close unnecessary applications or restart the Windows guest if it is genuinely unresponsive. For testing, Microsoft’s Sysinternals RAMMap can show how Windows memory is being used and includes options for emptying certain memory lists. Use such tools only when you understand what you are measuring; emptying standby memory can make subsequent file access slower.
Also check the virtual machine’s assigned RAM and the host computer’s available memory. A guest operating system cannot use more physical memory than the hypervisor has made available to it, and host-level memory pressure may affect the guest even when its own cache appears normal.
Should You Clear VM Cache Regularly?
Usually, no. Linux is designed to use otherwise idle RAM for caching and to make that memory available when applications require it. Clearing caches on a schedule often creates extra disk reads, reduces performance, and can make benchmark results less representative of normal use.
A high cache figure by itself does not indicate a memory leak. Look for practical signs of memory pressure, such as frequent swapping, slow response, or processes being terminated by the out-of-memory system. Use tools such as free, vmstat, top, or htop to investigate those symptoms instead of relying on the total “used” memory number alone.
There are specific cases where clearing cache can be reasonable:
- You are testing cold-cache disk performance and want repeatable conditions.
- You are troubleshooting a filesystem or application behavior that depends on cached reads.
- You are following a diagnostic procedure that specifically calls for dropping caches.
For ordinary memory management, let the kernel handle the cache. If an application cannot get memory, identify which processes are using RAM and whether the system is swapping before deciding that cache is the cause.
Does Clearing Cache Also Clear Swap?
No. Dropping Linux filesystem caches does not clear swap or move swapped-out application pages back into RAM. Swap is a separate part of virtual memory. If you need to inspect swap usage, run:
swapon --show
free -h
Disabling and re-enabling swap is sometimes suggested as a way to clear it, but it can require enough free RAM to bring swapped pages back into memory. On a memory-constrained or production system, that can cause serious slowdowns or instability. Do not use swapoff simply to clear cache; investigate why swap is being used and ensure adequate memory first.
Make the Change Temporary and Use Caution
Writing to /proc/sys/vm/drop_caches is temporary. It does not permanently change a kernel setting, and the cache will grow again as the system reads files and directories. You generally do not need to add this command to a startup script, cron job, or scheduled task.
On a production server, clearing cache can cause a burst of storage reads as applications refill it. This may increase disk activity and response times, especially on systems with slow disks or heavy workloads. If you are administering a server, choose a quiet maintenance window for testing and monitor application performance afterward.
If the command returns “Permission denied,” make sure you are using an administrator account and that the privilege escalation applies to the write operation. For example, sudo echo 3 > /proc/sys/vm/drop_caches may fail because the shell handles the redirection before sudo runs. Use the sudo sh -c or sudo tee examples above instead.
What to Do if Memory Still Looks Full
If clearing cache does not resolve the issue, the memory may be occupied by applications, a database, a container workload, or kernel memory that is not part of the caches dropped by this interface. Identify the largest processes with top or htop, and review application-specific memory settings. On a virtual machine, also verify that the guest has enough assigned RAM and that the host is not under pressure.
For persistent memory problems, check system logs and application metrics, update software where appropriate, and look for a process whose memory use keeps growing. Restarting an application may temporarily restore memory, but finding the underlying cause is more useful than repeatedly clearing cache.
Conclusion
To clear VM cache on Linux, run sync and write 1, 2, or 3 to /proc/sys/vm/drop_caches, depending on whether you want to drop the page cache, filesystem metadata caches, or both. Use the command only when you have a specific reason, such as controlled testing or troubleshooting. Linux normally reclaims cached memory automatically, so a large cache is usually healthy and does not need to be cleared. If you are using a Windows guest or another virtualization platform, use tools appropriate to that operating system and check both guest and host memory.
Disclaimer: Articles are written by Humans, AI or Both. Verify Important information.