After adding more memory to my Linux machine I was tempted to use the cache more agressively.
The thing is: I boot up my machine, go to bathroom, come back and log in. It takes like half a minute to log in. Then I start firefox and again it takes some time. When I log out and back in, all these things happen within seconds, because the cache is warm then. So I thought: how can I teach my machine to put all these files into the cache while I am in the bathroom.
I looked into preload and found the results somewhat disappointing. The net cause of this seems to be that it only tracks mmap()ed files and not files which are read by means of read().
I suspect this is because mmap()ed files are easier to observe. When an application mmap()s a file it stays in memory for some time, whereas open()-read()-close() could all happen within a fraction of a second (correct me if I'm wrong).
There does not seem to be a simple way to get notified when a file is read from. There is inotifiy, but it requires registering directories and IIRC correctly, is not meant for monitoring entire filesystems.
Ideally I would like to have a device in /dev (like a tty) from which I can read the filenames from which some application reads from.
(1) Is something like this available ?
(2) Are there reasons why this is difficult ?
If I had information about read file accresses I could easily warm the cache during boot.
read
, the data ends up in the cache automatically. Are you monitoring common usage patterns? Are you designing a predictive load system? The audit subsystem (search forauditctl
) might help: you can put a watch onread
.read
to get a chunk of file, the kernel does sometimes read ahead the next few chunks of the file already.