Home LinuxClear Cache Memory in Linux Without Rebooting

Clear Cache Memory in Linux Without Rebooting

by Noyal S
Clear Cache

Linux automatically uses available RAM for disk caching to improve performance. However, during troubleshooting, benchmarking, or memory-related issues, you may need to manually clear cache in Linux without rebooting.

This guide explains how to safely clear:

  • Page cache
  • Dentries
  • Inodes

Using the vm.drop_caches kernel parameter via the sysctl command.

Understanding Linux Cache Memory

Linux uses three primary types of cache:

Cache TypeDescription
Page CacheStores file data to speed up disk reads
DentriesDirectory entry cache
InodesMetadata about files

This caching improves performance. Clearing it unnecessarily can temporarily reduce system efficiency.

When Should You Clear Cache in Linux?

Clearing cache is useful when:

  • Troubleshooting memory issues
  • Testing application performance
  • Benchmarking disk performance
  • Freeing memory in development environments
  • Resoling abnormal RAM usage spikes

Note: On production systems, clearing cache may temporarily degrade performance.

How to Clear Cache in Linux Without Rebooting

Step 1: Sync Cached Data to Disk

Before clearing cache, flush pending writes:

sync

This ensures all modified data is written to disk.

Step 2: Clear Cache Using sysctl

Run the following command as root:

sync && sudo sysctl -w vm.drop_caches=3

What This Does:

  • vm.drop_caches=1 → Clears Page Cache
  • vm.drop_caches=2 → Clears Dentries & Inodes
  • vm.drop_caches=3 → Clears All (Page Cache + Dentries + Inodes)

Step 3: Reset drop_caches Parameter

sudo sysctl -w vm.drop_caches=0

This stops further cache clearing.

Alternative Method (Using /proc Interface)

You can also clear cache directly:

sync && echo 3 | sudo tee /proc/sys/vm/drop_caches

This achieves the same result as sysctl.

Verify Memory Usage Before and After

Check memory usage:

free -h

Or:

cat /proc/meminfo

Look for changes in:

  • Cached
  • Buffers
  • Available memory

Important Considerations

  • Linux automatically manages memory efficiently.
  • Clearing cache does NOT permanently free RAM.
  • Cache will rebuild as applications access disk.
  • Avoid scheduling frequent cache clearing on production systems.
  • Always use sync before dropping caches.

Best Practice for Production Servers

Instead of manually clearing cache:

  • Investigate high memory usage using top or htop
  • Check for memory leaks
  • Optimize application memory limits
  • Review swap usage
  • Monitor I/O activity with iotop

Cache clearing should be a troubleshooting step; not a routine maintenance task.

Summary

You can clear cache in Linux without rebooting using:

sync && sudo sysctl -w vm.drop_caches=3

This clears page cache, dentries, and inodes instantly. However, use it cautiously, especially on production servers.

It’s important to use this method with caution and follow the instructions carefully, if you have any doubts, contact SupportPRO Server Admin for help.

Facing issues?

Our technical support
engineers can solve it.

Contact Us today!
guy server checkup

You may also like

Leave a Comment