Is it necessary to clear the memory cache (drop caches); when is it done?
Short answer
It is not necessary in normal operation. The system uses free memory as a cache to speed up disk access, and this space is given back automatically when applications request it; the value that actually needs to be checked is the available column in the sys-cmd memory status output, and a low free value is not a problem. The cache is cleared when it is to be reset before a measurement or test, or when it is to be seen that the buff/cache space can really be given back: sys-cmd memory drop-page-cache clears only the page cache, and sys-cmd memory drop-all-caches additionally clears the file and directory information caches. Both commands ask for confirmation, cause a temporary slowdown and are not a permanent solution; the cache fills up again in a short time.
How Does It Work?
The memory of the device is shared between applications and the cache:
- Files that are read are kept in the cache: when log, graph and configuration files are read, their contents stay in memory; when the same file is read again, the disk is not accessed. This space appears in the
buff/cachecolumn in thememory statusoutput. - The cache shrinks when needed: when an application requests memory, the space in the cache is given to it. Therefore the
availablecolumn is close to the sum offreeand the cache that can be given back. - The clearing commands delete the cache immediately: first the pending disk writes are completed, then the cache is cleared and the space moves from the
buff/cachecolumn to thefreecolumn. Application data is not touched. - The cache fills up again: after clearing, files are read from the disk again for a while; during this time disk access slows down, and the cache grows again with use.
Comparison
| memory drop-page-cache | memory drop-all-caches | memory free-swap | |
|---|---|---|---|
| What it clears | Page cache | Page cache, dentry and inode caches | The swap content is moved to memory, and swap is turned on again |
| Performance impact | Temporary slowdown | Noticeable slowdown; felt more in services that write logs and open many files | It can take minutes while swap is emptied; the device may slow down |
| When | Resetting the cache before a measurement or test | When the file and directory information caches are also to be reset; in a maintenance window | If swap is full even though available is high |
| Risk | Low | Noticeable performance impact under traffic | If available is not noticeably greater than the swap used value, memory can run out |
| Confirmation title | You are about to drop the page cache | You are about to drop all caches | You are about to clear swap space |
Clearing the Cache in TR7
The commands are found under sys-cmd memory in WEB-CLI and run only for a user whose User Type is Admin. They are not affected by the selected v-device and route table, and always run on the device where the command is run; in a cluster, they are run separately for each device. Every run is written to the user logs.
The recommended order is to first see the status, clear if needed, and read the result again:
sys-cmd memory status
sys-cmd memory drop-page-cache
sys-cmd memory status- When the clearing commands are run, the confirmation screen opens; the operation is applied when
evetis written in the Turkish interface andyesin the English interface. If anything else is written, theInvalid confirmation. Operation cancelled.message appears; Esc closes the confirmation screen. - When the job is done,
Page cache dropped successfully.orAll caches dropped successfully (page cache, dentries and inodes).is written. This message is written without looking at the result of the operation; if there is a red line above it, the operation may not have completed, and the status is verified withmemory status. - Before sys-cmd memory free-swap is used for swap, the
availablevalue of theMemline is compared with theusedvalue of theSwapline.
Common Misconceptions
- "If the
freevalue is low, memory has run out." Free memory is used as a cache; memory pressure is shown by theavailablecolumn. Ifavailableis high, there is no need to clear the cache. - "Clearing the cache regularly speeds up the device." On the contrary, after clearing, files are read from the disk again and the device slows down for a while; the cache fills up again in a short time.
- "drop-all-caches is always preferred because it is more comprehensive." Its performance impact is more noticeable;
drop-page-cacheis enough for a reset before a measurement, anddrop-all-cachesis not run during peak hours. - "If swap is full, clearing the cache is enough." Clearing the cache does not change the swap content; for swap, there is
memory free-swap. If swap fills up frequently, the memory of the device is not enough for the workload; this situation is solved not with commands but with resource planning.
How it is done in the documentation
