pas*_*636 12 mmap offset page-size
在mmap()手册页中:
它的原型是:
void *mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset);
Run Code Online (Sandbox Code Playgroud)
和描述:
The mmap() function asks to map 'length' bytes starting at offset 'offset'
from the file (or other object) specified by the file descriptor fd into
memory, preferably at address 'start'.
Run Code Online (Sandbox Code Playgroud)
最后,对于最后一个论点:
'offset' should be a multiple of the page size as returned by getpagesize(2).
Run Code Online (Sandbox Code Playgroud)
根据我的实践,offset必须是页面大小的倍数,例如,我的Linux上有4096,否则,mmap()会返回Invalid argument,offset是文件偏移量,为什么它必须是虚拟内存系统页面大小的倍数?
谢谢,
简单的答案:快速做到.更复杂的答案:每当您访问映射内存中某个位置的内存时,操作系统必须确保此位置填充了文件的内容.但操作系统只能检测您是否访问内存页面 - 而不是单个位置.它的作用是,它在文件和内存页面中的偏移之间创建一个简单的关系 - 无论何时访问内存页面,都会加载该文件的那一部分.要快速进行这些计算,它会限制您从某些偏移开始.
| 归档时间: |
|
| 查看次数: |
8834 次 |
| 最近记录: |