用户工具

站点工具


jaysnote:ramfs

ramfs

What is ramfs?

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.

然后对于ramfs,这里没有备份的存储器。通常地,文件一旦被ramfs写入ram,不需要再重新写入,该位置区域不再会被标记为可使用状态。其不会被VM在需要可循环使用空间的时候回收。

实现ramfs的代码量需要非常小,因其所有工作都要基于linux缓存机制完成。基本上的,你是使用磁盘缓存作为一个文件系统。因此,也就不提供额外选项支持移除此功能,因磁盘空间微乎其微。

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.)

ramfs and ramdisk

早期的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.

ramfs有一个缺点,它连续写入ram直到耗完整个空间,但是此时VM并不能释放此空间因为VM认为文件需要写入备份存储器(而不是交换空间),但是ramfs没有任何备份存储器,因此建议只有root(或者其他可信任的用户)才接近ramfs挂载点。

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.

ramfs and tmpfs

ramfs衍生出tmpfs技术,其限制空间大小,可以用以数据交互。正常用户可以接近此tmpfs挂载点。更多信息访问如下链接。

jaysnote/ramfs.txt · 最后更改: 2021/06/22 23:14 (外部编辑)