博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ramfs, rootfs & initramfs
阅读量:2439 次
发布时间:2019-05-10

本文共 4445 字,大约阅读时间需要 14 分钟。

From:

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.

 

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 caching purposes until the VM reallocates the memory.  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 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 and ramdisk:

 

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 fixed size, so the filesystem mounted on it was of 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.

Compared to ramfs, this wastes memory (and memory bus bandwidth), creates unnecessary work for the CPU, 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.) 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. Another reason ramdisks are semi-obsolete is that the introduction of loopback devices offered a more flexible and convenient way to create synthetic block devices, now from files instead of from chunks of memory. See losetup (8) for details.

 

ramfs and tmpfs:

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.

What is rootfs?

Rootfs is a special instance of ramfs (or tmpfs, if that's enabled), which is always present in 2.6 systems.  You can't unmount rootfs for approximately the same reason you can't kill the init process; rather than having special code to check for and handle an empty list, it's smaller and simpler for the kernel to just make sure certain lists can't become empty. Most systems just mount another filesystem over rootfs and ignore it.  The amount of space an empty instance of ramfs takes up is tiny.

What is initramfs?

All 2.6 Linux kernels contain a gzipped "cpio" format archive, which is extracted into rootfs when the kernel boots up.  After extracting, the kernel checks to see if rootfs contains a file "init", and if so it executes it as PID 1.  If found, this init process is responsible for bringing the system the rest of the way up, including locating and mounting the real root device (if any).  If rootfs does not contain an init program after the embedded cpio archive is extracted into it, the kernel will fall through to the older code to locate and mount a root partition, then exec some variant of /sbin/init out of that.

.....

Populating initramfs: External initramfs images: Contents of initramfs: Why cpio rather than tar? Future directions:

转载地址:http://vhbqb.baihongyu.com/

你可能感兴趣的文章
centos安装nginx_如何在CentOS 8上安装Nginx
查看>>
graphql 嵌套查询_了解GraphQL中的查询
查看>>
如何在Ruby中使用数组方法
查看>>
如何在Ubuntu 20.04上安装R
查看>>
如何在CentOS 8上安装MySQL
查看>>
Apollo Boost简介
查看>>
strapi_使用Strapi构建自定义API
查看>>
graphql解析器_GraphQL中的架构和解析器
查看>>
debian创建交换分区_如何在Debian 8上添加交换空间
查看>>
debian创建交换分区_如何在Debian 9上添加交换空间
查看>>
debian安装nginx_如何在Debian 10上安装Nginx
查看>>
金蝶kis可用库存查询_如何建立可用库存
查看>>
vue密码正则验证表单验证_如何在Vue中使用表单验证
查看>>
particles.js_使用Particles.js创建很棒的背景效果
查看>>
golang flag 包_如何在Go中使用Flag包
查看>>
泛型 typescript_TypeScript中的泛型
查看>>
布尔逻辑_了解Go中的布尔逻辑
查看>>
gatsby_Gatsby更快的WordPress网站
查看>>
react 自定义控件使用_使用React使用自定义API
查看>>
react上下文_了解React的新上下文API
查看>>