Write Only Memory Mapping in boost?

拟墨画扇 提交于 2019-12-24 11:04:05

问题


Why doesn't boost interprocess support write only memory mapping?

Maybe I'm missing something but wouldn't a write only mapping be significantly faster than a read/write mapping as the OS doesn't have to read in the pages from the disk, just flush out pages from memory to the disk? Also it would have the benefit of being entirely non blocking (except for flushing and destruction).

Would I benefit by switching from boost to native OS memory mapping?


回答1:


In fact if you allocate a new memory-mapped file of size, say, 20Gb, you'll get a sparse file allocation of that size.

When "mapping in" pages of that files, there need to be a read operation (as the OS might be able to tell that the page is not physically present yet on disk), and only when (if) those pages are dirtied need they be written out.

Of course, this is implementation dependent and I don't think POSIX (can) guarantee this, but it's not unreasonable behaviour IYAM, and would be the equivalent of write-only mapping.




回答2:


Actually, a write-only memmap would not be faster, as the OS can only keep track of changes / provide those mappings in whole-page granularity.

At least, if you want to avoid the prohibitive cost of simulating all access to such pages in kernel-land (not implemented) instead of just mapping a page.

Somehow, I doubt going directly to the OS API instead of going through the Boost-API could provide any significant speed-ups:

The boost API is a thin wrapper over the OS-specific interface and will be completely inlined and thus compiled out by any decent compiler.



来源:https://stackoverflow.com/questions/24352943/write-only-memory-mapping-in-boost

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!