memory - 运行时,唯一存储在 tmpfs 中的可执行代码是否会复制到 RAM 的另一部分?

标签 memory linux-kernel tmpfs

磁盘上的可执行文件需要首先将其代码和数据部分加载到 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/

相关文章:

c - 测试内核模块

docker - 使用 ramdisk 更快地构建 Dockerfile

java - 在运行时将数据保存在服务器中的首选方法是什么

memory - 在幕后,Rust 中的向量是通过引用还是值返回的?

linux - 内核模块 : extern only if a specific parameter is set

linux - 了解 tmpfs 大小

memory - 将 tmpfs 或 ramfs 绑定(bind)到特定的内存节点

c - 传递方法参数时防止数组越界

Java对象未访问变量的内存分配

linux-kernel - sysfs 属性可以在 Linux 设备驱动程序中采用非数值吗?