Release Memory Mapped Memory

让人想犯罪 __ 提交于 2020-01-11 09:23:34

问题


I am memory mapping a large file (~200GB) into a single region/view and sequentially writing to it. Every now and then I perform a boost::interprocess::mapped_region::flush(last, current, false).

After a while the process uses up the entire system memory. Which, from what I understand, is normal as it will be releasing the memory as other process request memory.

This works well on Windows 8. However, running on Windows 7 it doesn't seem to play well with the drivers for AJA video cards and it starts affecting performance (dropping IO packets).

Is there any way I can force the Windows 7 to flush parts of the memory to disk (after the data is written it is only interesting for a few seconds, and remember I am writing sequentially through the entire file), as to not use up the entire available system memory?


回答1:


Flushing has nothing to with reclamation, IYAM. It just makes sure dirty pages are written out (I think you still need a disk sync to make sure it actually /hit the disk/).

So, you're looking for a way to unmap.

Maybe you can use a function like

  • EmptyWorkingSet to evict as many pages as possible
  • SetProcessWorkingSetSize to temporarily reduce the allowed process working set.

Of course, in a more portable fashion, you might just get away with unmapping and remapping. If the access is to spinning HDD and remains sequential across remaps, there might not be a performance penalty (there might be though, if the kernel prefetched data e.g. due to madvise() or the windows equivalent thereof)



来源:https://stackoverflow.com/questions/24249763/release-memory-mapped-memory

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