Serving html from linux ramdisk

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:

  • if you use tmpfs, your tmpfs contens will move to your swap memory, which means, it is also saved on disk and not faster anymore than using a real file system.
  • if you don't use tmpfs, your cached version will be flushed from memory, which consumes almost no time. when it is accessed next time, it will be read from disk and comes back into the cache.

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.


Why bother? Linux is just going to cache them in RAM anyway, the first time they get read from disk. And if they're read frequently enough they'll always be cached.


The tmpfs method has less overhead. In the /dev/ram1 example, you have an entire filesystem with inodes, directories, etc stored in a block device. With tmpfs it is essentially only the disk cache.

Yes, if you create a ramdisk and copy files into it, you need to copy those files again whenever there is a change.