When a Linux operating system and user processes in the operating system run, the page cache (also known as file cache) is utilized. The page cache usage increases over the runtime, which leads to high system resource consumption. This may cause performance jitter for performance-sensitive business or even cause out of memory (OOM) errors to occur in specific tasks. In business scenarios in which you must release a large amount of memory, you can call the /proc/sys/vm/drop_caches interface to release the page cache.
Procedure
Memory reclamation by calling the drop_caches interface deletes page cache and the required dentries and inodes from the system, which may cause performance degradation during disk I /O operations. Exercise caution when you reclaim memory based on your business requirements.
The following operations release only unused objects. Dirty page objects in the memory are not released until the objects are written to a disk. To release dirty page objects from the memory, run the sync command to write the dirty page objects from the memory to a disk and then call the drop_caches interface to clear the page cache. This way, you can release more memory.
Release the page cache.
Call the
drop_cachesinterface to release the page cache.sudo sh -c 'echo 1 > /proc/sys/vm/drop_caches'Run the
sysctlcommand to release the page cache.sudo sysctl -w vm.drop_caches=1
Release
dentriesandinodes.Call the
drop_cachesinterface to releasedentriesandinodes.sudo sh -c 'echo 2 > /proc/sys/vm/drop_caches'Run the
sysctlcommand to releasedentriesandinodes.sudo sysctl -w vm.drop_caches=2
Release the page cache,
dentries, andinodes.Call the
drop_cachesinterface to release the page cache,dentries, andinodes.sudo sh -c 'echo 3 > /proc/sys/vm/drop_caches'Run the
sysctlcommand to release the page cache,dentries, andinodes.sudo sysctl -w vm.drop_caches=3