jay's some development note
jay's some development note
Ramfs is a very simple FileSystem that exports Linux's disk cacheing mechanisms (the page cache and dentry cache) as a dynamically resizable ram-based filesystem.
ramfs 是一个基于linux缓存机制（page cache and dentry cache）的简易文件系统，基于ram，大小可动态调整。
Normally all files are cached in memory by Linux. Pages of data read from backing store (usually the ?block_device the filesystem is mounted on) are kept around in case it's needed again, but marked as clean (freeable) in case the Virtual Memory system needs the memory for something else. Similarly, data written to files is marked clean as soon as it has been written to backing store, but kept around for cacheing purposes until the VM reallocates the memory. A similar mechanism (the dentry cache) greatly speeds up access to directories.
通常地，所有文件通过linux缓存到ram，按页（通常作为块设备在挂载后）从非易失的存储（backing store）读取到ram直到不再需要它。此时，该ram缓存区域被虚拟存储系统（Virtual Memory system ）重新标记为可使用（clean/freeable)。同样地，一旦被回写到非易失存储（backing store）的ram也标记为可使用，直到虚拟存储系统下一次按需分配空间。A similar mechanism (the dentry cache) greatly speeds up access to directories.
With ramfs, there is no backing store. Files written into ramfs allocate dentries and page cache as usual, but there's nowhere to write them to. This means the pages are never marked clean, so they can't be freed by the VM when it's looking to recycle memory.
The older "ram disk" mechanism created a synthetic block device out of an area of ram and used it as backing store for a filesystem. This block device was of a fixed size, so the filesystem mounted on it was a fixed size. Using a ram disk also required unnecessarily copying memory from the fake block device into the page cache (and copying changes back out), as well as creating and destroying dentries. Plus it needed a filesystem driver (such as ext2) to format and interpret this data. This wastes memory, creates unnecessary work for the CPU, wastes memory bus bandwidth, and pollutes the CPU caches. (There are tricks to avoid this copying by playing with the page tables, but they're unpleasantly complicated and turn out to be about as expensive as the copying anyway.)
早期的ram disk机制是在非ram区域创建一个综合块设备，被作为文件系统的备份存储器。因其大小固定，所以文件系统也被作为固定大小挂载。使用ram disk 需要额外的从或者到页缓存的拷贝，作为创建和销毁条目的结果。因此，其需要文件系统驱动解释数据。此过程浪费存储空间，给cpu带来额外负担，浪费存储总线带宽，败坏cpu缓存(There are tricks to avoid this copying by playing with the page tables, but they're unpleasantly complicated and turn out to be about as expensive as the copying anyway.)。
More to the point, all the work ramfs is doing has to happen anyway, since all file access goes through the page and dentry caches. The ram disk is simply unnecessary, ramfs is internally much simpler.
One downside of ramfs is you can keep writing data into it until you fill up all memory, and the VM can't free it because the VM thinks that files +should get written to backing store (rather than swap space), but ramfs hasn't got any backing store. Because of this, only root (or a trusted user) should be allowed write access to a ramfs mount.
A ramfs derivative called tmpfs was created to add size limits, and the ability to write the data to swap space. Normal users can be allowed write access to tmpfs mounts. See documentation/filesystems/tmpfs.txt for more information.