C**********n 发帖数: 100 | 1 【 以下文字转载自 Programming 讨论区 】
发信人: CplusplusFan (C++ Fan), 信区: Programming
标 题: 为啥用mmap访问文件的效率高呢?
发信站: BBS 未名空间站 (Thu Apr 22 01:21:40 2010, 美东)
mmap把磁盘上的一个文件映射到内存,据说这样对文件操作就可以加速了。
不过我不明白的是虽然mmap把文件从磁盘映射到内存,但程序实际上还是要从磁盘读文
件的把。为啥mmap这么一搞就快了呢? | u*****r 发帖数: 176 | 2 I think read/write involves copy data from userspace into page cache and
mmap only need need one copy. read/write also validate the address passing
to kernel and checking atime/mtime of the inode...
and mmap transparently fault pages and read ahead and all other nasty jobs. |
|