I have seen a somewhat dated tutorial that suggest serving html files with a ramdisk
like this:
mkfs -q /dev/ram1 102400
I also find another source that use something like this:
mount -t tmpfs -o size=1024 none /mnt/rds
Are these two methods equally valid? I am using Centos 6.3 with nginx. So in practice I want to serve the files in /usr/share/nginx/html
from RAM.
And in case I mounted the disk, do I have to mount again whenever there is a genuine change in the original folder?
Best Answer
From your question (last paragraph), I assume you think that the ramdrive will have the same contents as the original file system below. That's not the case. You will have an empty directory and need to fill it first. I don't think this is what you want.
Linux has a very good cache system. Every memory page which is not used for application memory will be used as cache. This means: even without a tmpfs (the method I would recommend), your file will stay in memory until there is real need to flush it from there.
Given it really happens and your memory gets too full:
So I don't see any advantage to use tmpfs as long you don't generate those files dynamically and in very short interval. Linux normally is much more efficient if you let it decide over memory usage and swapping.