vmtouch
Force files into system memory (page cache)
TLDR
Print the cache status of a file
Load a file into cache
Evict a file from cache
Lock a file in cache to prevent eviction from memory
Lock a file and daemonize the program
SYNOPSIS
vmtouch [options] file1 [file2 ...]
PARAMETERS
-v
Verbose operation; reports on files as they are encountered.
-t
Touch files instead of just reporting; forcing them into memory.
-e
Evict files from memory instead of reporting on them.
-l
Operate on the files listed in a lockfile, exclusive with files on command line.
-d
Specify recursion depth for directory traversal, default: 0 (no recursion).
-f
Follow symbolic links when recursing into directories.
-m
Limit memory usage to the specified number of bytes when touching files.
-p
Print percentages instead of raw byte counts.
-i
Run interactively, reporting usage every
-w
Report warnings for files that cannot be mapped.
-V
Show version information.
-h
Show help message.
DESCRIPTION
vmtouch is a tool for learning about, diagnosing, and inducing file system cache behavior. It provides a portable interface for gaining insight into the files that reside in physical memory (RAM) and potentially influencing which files are resident. This is crucial for performance tuning, especially in scenarios where disk I/O is a bottleneck. vmtouch operates by reading files and mapping them into memory, allowing you to 'touch' files, effectively loading them into the page cache. This can improve application startup times, reduce latency for frequently accessed data, and optimize overall system responsiveness. It can also provide valuable diagnostics on current cache usage.
It displays the portion of the specified files or directories that currently reside in memory, the total size of the specified files, and provides options to force files into memory or remove them.
vmtouch leverages `mincore(2)` system call to check what part of the file is in ram. It uses `mmap(2)`/`read(2)` to touch the files.
Note that excessive touching without understanding cache behaviour can be detrimental to performance as it may cause thrashing. The tool is most helpful in understanding performance constraints and optimizing accordingly.
CAVEATS
Touching very large files can consume significant memory, potentially leading to system slowdown or OOM (Out of Memory) errors. Use the '-m' option carefully. vmtouch may not be effective on systems with very aggressive memory management policies that immediately swap out touched files.
EXAMPLES
vmtouch file.txt: Reports the amount of file.txt currently in memory.
vmtouch -t file.txt: Loads file.txt into memory.
vmtouch -ve directory/: Verbose operation, showing each file that is encountered during recursion through directory/.