Can mmap and O_DIRECT be used together?

时间:2015-10-30 23:13:03

标签: linux file io mmap

As I understand it, when you mmap a file you are basically mapping the pages from the page cache for that file directly into your process, and when you use O_DIRECT you are bypassing the page cache. Does it ever make sense to use the two together? If my understanding is right how would it even work? mmap seems to rely on the file being in the page cache and O_DIRECT seems to prevent it from going there (assuming nothing else on the system has the file open). I found this question but the answerer seems to think it's perfectly normal to do.

1 个答案:

答案 0 :(得分:0)

我认为它没有多大意义。

O_DIRECT 表示所有 I/O 都应尽快(无缓存)反映在存储中。

映射的页面是内存中存储(文件)的副本。反映每次对内存的读取和写入将不得不执行一些 I/O,这将是巨大的性能损失。