3 ms·
How do you batch writes to mmap-ed region?
by riobard 14y ago
How do you batch writes to mmap-ed region?
- hosay123 14y agoptr = mmap(..., len, ..) /* do stuff with ptr */ msync(ptr, len) No sane OS will pay attention to an mmapped region while it isn't under memory pressure, so dirty pages are effectively buffered until you explicitly tell the OS to start writeback.
- otterley 14y agoLinux flushes dirty pages in mmapped regions to disk every 30 seconds by default whether you like it or not (see vm.dirty_expire_centisecs). Unlike FreeBSD, Linux doesn't yet have support for the MAP_NOSYNC flag to mmap(2).
- hosay123 14y agoGood point, though I think for a machine averaging even 40mb/sec this only amounts to one 'batch' every 1.2gb receiving an extra sync. Linux recently changed so that pdflush doesn't exist at all, when the dirty list fills, a per-device thread is created that sleeps for 5 seconds before starting work, so maybe it's a bit less than 1.2gb.
- riobard 14y agoDoes this mean that I have to msync multiple mmap'ed chunks in order to batch write? For example msync(ptr1, len1) msync(ptr2, len2) msync(ptr3, len3) Where [ptr1, ptr1+len1], [ptr2, ptr2+len2], ... are the chunks within a big mmap'ed region where changes occur and need to be written to disk for persistence. Or do I just msync the whole region then hope and pray that the OS will do the right thing?
- deleted 14y ago[deleted]