全部博文(116)
分类: 嵌入式
2014-02-06 09:40:58
What is ramfs?
--------------
Ramfs is a very simple filesystem that exports Linux's disk caching mechanisms (the page cache and dentry cache) as a dynamically resizable RAM-based filesystem.
ramfs是空间大小可动态变化的RAM文件系统。它非常简单,是用来实现Linux缓存机制(两类缓存:page cache和dentry cache)的文件系统。
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.
通常情况下,Linux的所有文件在内存中都有缓存。从后备存储器(即block device,通常指挂载着文件系统的块设备,如硬盘分区)读取的数据页,都保存内存周围,以防再次需要(简单地说,就是缓存在内存中);在后备存储器中的数据页执行marked as clean操作,当虚拟内存系统(Virtual Memory System)需要后备存储器中的数据页内存作为别用时,可以释放。
Similarly, data written to files is marked clean as soon as it has been written to backing store, but kept around for caching purposes until the VM reallocates the memory.
基于同样的机制,后备存储器的写入操作(内存数据写入文件,然后写回后备存储器,这些内存数据所占用的内存空间就会立即marked as clean)后,也可以释放占用的数据页内存。但这些内存数据仍保存(作为缓存使用),直至VM(虚拟机)重新分配内存,它们所占用的内存空间被释放。
A similar mechanism (the dentry cache) greatly speeds up access to directories.
对于文件目录占用的缓存(dentry: directory entry),也存在同样的机制。目录缓存作为一个类似的机制,极大的加快了对目录的访问。
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的背后并没有后备存储(我们称正被缓存的存储设备为后备存储,因为缓存背后的磁盘无疑才是所有缓存数据的归属)。也就是说,写入ramfs的文件可以正常的分配page cache和 dentry cache,但是不能写入后备存储器(也没有后备存储器可供其写入)。这意味这些page cache和 dentry cache不再标记为可用。因此,当想要回收内存时,这部分内存不能被VM释放、回收。
The amount of code required to implement ramfs is tiny, because all the work is done by the existing Linux caching infrastructure. Basically,you're mounting the disk cache as a filesystem. Because of this, ramfs is not an optional component removable via menuconfig, since there would be negligible space savings.
由于ramfs可以基于现有的Linux的文件系统结构,ramfs要做的事情都可以由现有的linux缓存机制来完成,所以,用于实现ramfs的代码量很小。 一般而言(从根本上看),后备存储器的缓存被安装(挂载)为一个文件系统 。所以,ramfs并不是一个可以通过菜单配置menuconfig来选择/卸载的可选组件,是必然进入内核的。
简单的几点重要理解: