What is the purpose of a ramdisk when fadvise exists?

Philip asked:

My understanding is that fadvise will tell the system that the indicated files should be stored in the file system cache (RAM).

What is the purpose of mounting a directory in a ramdisk when you can just fadvise --willneed the directory?

My answer:

Let us read the manual page for the underlying library call:

Programs can use posix_fadvise() to announce an intention to access file data in a specific pattern in the future, thus allowing the kernel to perform appropriate optimizations.

The advice applies to a (not necessarily existent) region starting at offset and extending for len bytes (or until the end of the file if len is 0) within the file referred to by fd. The advice is not binding; it merely constitutes an expectation on behalf of the application.

(Emphasis added.)

Everything on a RAM disk is guaranteed to be in RAM, by design (though tmpfs can be swapped out). But fadvise is merely advisory; the kernel is not required to preload the data into RAM, nor to always keep it in RAM.

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.