当我使用mmap()将文件映射到内存时,它不是直接加载到内存中(缓存缓冲区RAM),而是只加载访问特定映射内存区域时所需的部分。
系统如何通过C: *ptr = val;或asm: MOV捕捉到内存映射文件的内存并从文件中生成加载数据,使用什么机制(IRQ或类似于分页内存的机制),以及如何调用它?
发布于 2013-11-09 15:54:33
简单的回答是传呼。
内核跟踪每个进程的不同虚拟内存区域(又名映射)。有文件支持映射和匿名映射(交换支持映射)。在Linux上,您可以使用cat /proc/<pid>/maps查看它们。
对按需页生存期内的不同阶段进行一些概述:
- It corresponds to a non-present file-backed mapping: load it from disk.
- It corresponds to a non-present non-file-backed (anonymous) mapping: swap it in.
- It's a write to a non-writable page, and corresponds to a writable mapping: it's a COW (copy-on-write) fault, duplicate (unshare) the page, mark the page in the page-table/TLB as writable.
msync(),或者只是定期执行。https://stackoverflow.com/questions/19875575
复制相似问题