Memory mapped file usage
I am using memory mapped file in my application with single file handle and a file lock. Now we are planning to go for Multiple file handle to avoid the single file handle , and we are planning to go with Multiple Memory mapped file. My doubt is will multiple memory mapped file for each file handle. will it degrade the performance. Please suggest me on this.
Manikandan MurugesanPosted Jul 10, 2017, 8:25 PM
I think the advantage is really that you reduce the amount of data copying required over traditional methods of reading a file.
If your application can use the data "in place" in a memory-mapped file, it can come in without being copied; if you use a system call (e.g. Linux's pread() ) then that typically involves the kernel copying the data from its own buffers into user space. This extra copying not only takes time, but decreases the effectiveness of the CPU's caches by accessing this extra copy of the data.
If the data actually have to be read from the disc (as in physical I/O), then the OS still has to read them in, a page fault probably isn't any better performance-wise than a system call, but if they don't (i.e. already in the OS cache), performance should in theory be much better.
On the downside, there's no asynchronous interface to memory-mapped files - if you attempt to access a page which isn't mapped in, it generates a page fault then makes the thread wait for the I/O.