I am pasting some code here which uses boost iostream to mmap & then writes to the mapped file:
typedef unordered_map work;
int m
VIRT will increase immediately (all pages are mapped into the process address space). RES will increase whenever pages are used, which causes them to be paged into the physical memory.
This happens for as long as there is sufficient memory available, after which the OS starts purging LRU pages from the reserved sets (unless they were VirtualLock
/mlock
-ed or are otherwise unmovable (like kernel pages, DMA buffers, security sensitive data etc.).
So, the OS optimistically leaves the pages reserved as long as possible (which improves performance as long as no other processes contend for the memory).
This signifies that the OS is doing it's job.
You're writing to disk. Disk access is (a lot) slower than memory access. How often the data actually gets written out to disk depends on tuning. This answer lists some of the tuning parameters that are available on linux (which you seem to be using):