3

我正在玩 Linux 内核代码,尤其是文件系统部分。我发现当内核启动时,为根目录“/”分配了一些 dentry 对象。为什么需要在 RAM 中分配多个根目录副本?而且,既然dcache(dentry缓存,本质上是一个大的hash表)似乎是在用一个hash函数H(parent_dentry_address, name_hash)来计算一个dentry抵抗的bucket。是不是意味着每个根dentry“/”都做了一个不同的dentry映射到dcache中的哈希桶?

顺便说一句,上述行为是在 Linux-3.3.0-rc4 上观察到的。

4

3 回答 3

1

从内核源代码中阅读 Documentation/initrd.txt 以了解引导过程中发生了什么:

When using initrd, the system typically boots as follows:

  1) the boot loader loads the kernel and the initial RAM disk
  2) the kernel converts initrd into a "normal" RAM disk and
     frees the memory used by initrd
  3) if the root device is not /dev/ram0, the old (deprecated)
     change_root procedure is followed. see the "Obsolete root change
     mechanism" section below.
  4) root device is mounted. if it is /dev/ram0, the initrd image is
     then mounted as root
  5) /sbin/init is executed (this can be any valid executable, including
     shell scripts; it is run with uid 0 and can do basically everything
     init can do).
  6) init mounts the "real" root file system
  7) init places the root file system at the root directory using the
     pivot_root system call
  8) init execs the /sbin/init on the new root filesystem, performing
     the usual boot sequence
  9) the initrd file system is removed

Note that changing the root directory does not involve unmounting it.
It is therefore possible to leave processes running on initrd during that
procedure. Also note that file systems mounted under initrd continue to
be accessible.

我希望这能回答内核为什么要为“/”分配一些目录的问题

于 2012-04-14T22:02:48.187 回答
1

我要闭上眼睛,不看任何代码,然后脱口而出,这可能是 mount /over的结果/,而且不止一次?

如果您将某些东西安装在 上/,则底层/不能消失,因为它可以通过 umount 暴露出来。

于 2012-03-13T08:18:34.200 回答
0

在内核中有两种类型'/',一种用于进程根目录,另一种是文件系统根目录。

文件系统注册挂载时,首先会为mount root分配一个dentry作为这个文件系统的入口,一般这个dentry使用'/'名。RAM fs如proc/devtmpfs...挂载内核,所以会有是多个同名的dentry '/'。

于 2015-12-08T16:41:36.423 回答