How to Configure File System Caching in Linux | Baeldung on Linux
Fleeting- External reference: https://www.baeldung.com/linux/file-system-caching
How to Configure File System Caching in Linux | Baeldung on Linux
file system cache holds data recently read from secondary storage. This makes it possible for subsequent requests to obtain data from the cache instead of reading it from slower memory
store frequently accessed data in memory for faster access
kernel uses the page cache to store recently-read data from files and file system metadata.
when a program reads data from a file, the kernel performs several tasks:
checks the page cache to see if the data is already in memory if the data is in memory, the kernel simply returns the data from the cache otherwise, it reads the data from the drive and stores a copy of it in the cache for future use
he vmstat command provides detailed information about virtual memory. In particular, it shows the amount of memory in use for caching: $ vmstat
cache column shows the amount of memory used for file system caching in kilobytes
use the free command to check the amount of file system cache memory in the system. It shows the memory usage in kilobytes under the buff/cache column
value of the buff/cache column is the sum of the values of the buffer memory and swap cache rows for vmstat.
value of vm.vfs_cache_pressure, which controls the tendency of the kernel to reclaim the memory used for caching directory and inode objects:
Swappiness controls how aggressively the kernel swaps memory pages. Lowering the value of swappiness means the kernel will be less likely to swap out less frequently used memory pages. Thus, the kernel will be more likely to keep these pages cached in RAM for faster access.
dirty pages are memory pages that aren’t written to secondary memory yet.
vm.dirty_background_ratio parameter is the amount of system memory in percentage that can be filled with dirty pages before they’re written to the drive
For instance, if we set the value of the vm.dirty_background_ratio parameter of a 64GB RAM system to 10, it entails that 6.4GB of data (dirty pages) can stay in RAM before they’re written to the storage.
Alternatively, we can set the vm.dirty_background_bytes variable in place of vm.dirty_background_ratio. The *_bytes version takes the amount of memory in bytes. For example, we can set the amount of memory for dirty background caching to 512MB
the *_ratio variant will become 0 if we set the * _bytes variant, and vice versa
vm.dirty_ratio is the absolute maximum amount of system memory in percentage that can be filled with dirty pages before they’re written to the drive. At this level, all new I/O activities halt until dirty pages are written to storage.
vm.dirty_expire_centisecs manages how long data can be in the cache before it’s written to drive. Let’s set the variable so that data can stay for 40 seconds in the cache:
40 seconds before it’s written to the drive. Notably, 1s equals 100 centisecs.
vm.dirty_writeback_centisecs is the variable for how often the write background process checks to see if there’s data to write to secondary storage.