我正在玩Linux内核代码,特别是文件系统的一部分。 我发现当内核引导时,一些dentry对象被分配给根目录“/”。 为什么需要在RAM中分配多个根目录的副本? 而且,由于看起来dcache(dentrycaching本质上是一个大的散列表)正在使用散列函数H(parent_dentry_address,name_hash)来计算一个dentry抵制的桶。这是否意味着每个根dentry“/”不同的dentry映射到dcache中的散列桶?
顺便说一句,上面的行为是在Linux-3.3.0-rc4上观察到的。
我要闭上眼睛,不看任何代码,只是脱口而出,这可能是安装/
结束/
不止一次的结果?
如果你在/
安装某个东西,那么这个东西就不能随便移开,因为它可以被卸载。
从内核源文件中阅读Documentation / initrd.txt,看看bootstrapping上发生了什么:
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.
我希望这回答了为什么内核为“/”分配几个“
内核中有两个类型“/”,一个用于进程根目录,另一个是文件系统根目录。
当文件系统注册和挂载时,它将首先为mount root分配一个dentry作为这个文件系统的入口,通常这个dentry使用'/'name.RAM fs,像proc / devtmpfs …挂载内核,所以会有成为几个同名的“/”。