Disable linux read and write file cache on partition

Solution 1:

there is a solution which perfectly fits your use case: http://code.google.com/p/pagecache-mangagement/

After checking out the source code:

svn checkout http://pagecache-mangagement.googlecode.com/svn/trunk/ pagecache-mangagement-read-only

issue

make
sudo cp *.so /usr/local/lib/
sudo cp *.sh /usr/local/bin/

then, you can start whatever application you want with

pagecache-mangagement.sh <App>

and the App won't fill up your caches!

Solution 2:

The nocache tool is designed for a similar goal: preventing specific commands from spoiling the current buffer cache. Just prepend ./nocache to your command:

./nocache cp -a ~/ /mnt/backup/home-$(hostname)

Note that the similar tool pagecache-mangagement - A tool to permit the management of the pagecache usage of arbitrary applications, as noted by rmetzger, is still in the same state as it was in 2008. Of course that can be either good or bad, or a mix :) I don't have a direct comparison, but I've asked the nocache folks for one

Solution 3:

This cannot be done cleanly. If you require this for certain applications then they should be modified to pass O_DIRECT to their open(2) calls.

Solution 4:

man raw. You can bind a raw device that bypasses the cache with that. It has some restrictions. I've only used it with CD/DVD devices, so I don't know how well it will work for you.