Tell the linux kernel to put a file in the disk cache?

Is there any command to for a file to be read in and loaded into the linux disk cache? This is on an up-to-date debian system.

I know in the general case, it's better to let the linux kernel figure this out. But I have an edge case. I have a laptop that has an NFS director mounted, and i want to play a long video file, but I don't want to have a network problem interrupt the playnig. I know that (largeish) file will be read in it's entirety later on. I know that nothing else (really) will be running while playing this video. There is enough free memory to store this file.

(I know I could just copy the file into a new tmpfs filesystem, but I'm curious if there's an even shorter way to do it)


A small program that mmap()ed the file with the MAP_LOCKED flag set would do the trick. You'll need to run this program as root, or a user with an RLIMIT_MEMLOCK value greater than the size of the file you want to map.

As SaveTheRbtz has mentioned, vmtouch has this capability built-in. The manpage suggests that vmtouch -l /some/file will do the trick.


If you really control the local environment that strictly, a simple cat $file >/dev/null should be sufficient. It's quite non-deterministic, when cache eviction removes that file - but if you have plenty of RAM and noone consuming it, it should be kept.

If there is a sticky and deterministic way to keep a file in cache - dunno...