磁盘上的可执行文件需要首先将其代码和数据部分加载到 RAM 中,然后才能执行。当可执行文件存储在 tmpfs 中时,它已经在 RAM 中,那么内核是否通过将 tmpfs 页面映射到进程地址空间来绕过将可执行文件加载到 RAM 中的步骤?答案是否适用于可执行文件和加载的库?
最佳答案
您的问题似乎已在 post on the Linux Kernel Mailing List 中得到解答2007年
(由于 tmps 是一种存储在文件系统缓存代码中的方案,没有后备存储,因此我认为提到的缓冲区缓存应该是“原始”)
菲利普·苏西问道:
The question is, when you execute a binary on tmpfs, does its code segment get mapped directly where it's at in the buffer cache, or does it get copied to another page for the executing process? At least, assuming this is possible due to the vma and file offsets of the segment being aligned.
休·狄更斯回复了
Its pages are mapped directly into the executing process, without copying.
您可能想阅读完整的线程 - 需要注意的是,这取决于具有 MMU 的系统,然后讨论转向 tmpfs 的非持久性。
我认为 Linux 的写时复制行为意味着您写入的任何数据页都会在第一次写入时为您的进程创建一个唯一的副本。
关于memory - 运行时,唯一存储在 tmpfs 中的可执行代码是否会复制到 RAM 的另一部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25270110/