vmtouch: portable file cache analyzer

search_compvmtouch is a useful utility to analyze and control the virtual memory used by the filesystem. It works on Unix-ish systems and BSD. It is a portable utility with minimal dependecies in the source code. In addition to understanding cache usage by files, you can also use vmtouch to preload files and speed up subsequent operations.

We came across vmtouch while troubleshooting one of our test servers which used up an unusual amount of cache after login. vmtouch helped us figure out the poorly-deployed script behind it. We could also unload a large cached file using vmtouch directly.

Features

  • Shows cached files and directories
  • Push/evict files fully or partially into/from cache
  • Lock files into memory
  • Run in daemon mode
  • Preserve virtual memory profiles during server switchover
  • Maintain hot-standby file-server
  • Track filesystem cache usage over time
  • Maintain “soft-quotas” of cache usage
  • Speed-up batch/cron jobs
  • Verbose or quiet output

Installation

To install vmtouch on Ubuntu, run:

$ git clone https://github.com/hoytech/vmtouch
$ cd vmtouch
$ make
$ sudo make install

Usage

vmtouch has some useful options:

$ vmtouch
vmtouch: no files or directories specified

vmtouch v1.0.2 - the Virtual Memory Toucher by Doug Hoyte
Portable file system cache diagnostics and control

Usage: vmtouch [OPTIONS] ... FILES OR DIRECTORIES ...

Options:
  -t touch pages into memory
  -e evict pages from memory
  -l lock pages in physical memory with mlock(2)
  -L lock pages in physical memory with mlockall(2)
  -d daemon mode
  -m max file size to touch
  -p use the specified portion instead of the entire file
  -f follow symbolic links
  -h also count hardlinked copies
  -w wait until all pages are locked (only useful together with -d)
  -v verbose
  -q quiet

You should check out the detailed explanation of each option.

Examples

Let’s check the cache usage of our /tmp, mounted in RAM:

$ vmtouch /tmp/
vmtouch: WARNING: skipping non-regular file: /tmp/ssh-GgJnCEkWMQC2/agent.1068
vmtouch: WARNING: skipping non-regular file: /tmp/.pcmanfm-socket--0-neo
vmtouch: WARNING: skipping non-regular file: /tmp/.org.chromium.Chromium.Qk5N5Z/SingletonSocket
vmtouch: WARNING: not following symbolic link /tmp/.org.chromium.Chromium.Qk5N5Z/SingletonCookie
vmtouch: WARNING: skipping non-regular file: /tmp/ssh-5fN5NHmxEP8j/agent.991
vmtouch: WARNING: skipping non-regular file: /tmp/.org.chromium.Chromium.KuSnIw/SingletonSocket
vmtouch: WARNING: not following symbolic link /tmp/.org.chromium.Chromium.KuSnIw/SingletonCookie
vmtouch: WARNING: skipping non-regular file: /tmp/fishd.socket.neo
vmtouch: WARNING: skipping non-regular file: /tmp/.menu-cached-:0-neo
vmtouch: WARNING: skipping non-regular file: /tmp/.X11-unix/X0
           Files: 17
     Directories: 7
  Resident Pages: 4780/4780  18M/18M  100%
         Elapsed: 0.001006 seconds

While converting a video with HandBrake, let’s see how much of the original file is cached:

$ vmtouch -v ../video.mp4
../video.mp4
[OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO] 86450/86450

           Files: 1
     Directories: 0
  Resident Pages: 86450/86450  337M/337M  100%
         Elapsed: 0.01291 seconds

Check how much of a file is cached in memory:

$ vmtouch -v ~/Downloads/phoronix-test-suite_6.0.1_all.deb 
/home/neo/Downloads/phoronix-test-suite_6.0.1_all.deb
[                                            ] 0/132

           Files: 1
     Directories: 0
  Resident Pages: 0/132  0/528K  0%
         Elapsed: 0.000117 seconds

Touch the file into memory:

$ vmtouch -vt ~/Downloads/phoronix-test-suite_6.0.1_all.deb 
/home/neo/Downloads/phoronix-test-suite_6.0.1_all.deb
[OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO] 132/132

           Files: 1
     Directories: 0
   Touched Pages: 132 (528K)
         Elapsed: 0.007935 seconds

Evict the file from memory:

$ vmtouch -ve ~/Downloads/phoronix-test-suite_6.0.1_all.deb 
Evicting /home/neo/Downloads/phoronix-test-suite_6.0.1_all.deb

           Files: 1
     Directories: 0
   Evicted Pages: 132 (528K)
         Elapsed: 0.000109 seconds

Daemonise and lock all files in a directory into physical memory:

$ vmtouch -dl /var/log/

Rating

Features: 4.5/5
Usability: 4.5/5

On GitHub: vmtouch

Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s