Noticing a strange performance behaviour while using shared memory that are file backed (i.e open user defined file and mmap() the same into process space). While doing a memcpy() into the shared memory section, sometimes a delay is observed in the order of milliseconds. To be specific, in normal scenarios 2048 bytes are copied in 0.4us but sometimes the same number of bytes takes about 10 - 20 milliseconds to copy. This happens randomly any time. The next 2048 frame of data goes back to the normal time.
Kernel version is 2.6.27.23-0.1-preempt.
Appreciate any clues from anyone, about what is happening and why the delay is seen. I have even tried by using shm_open() and then mmap(), with no difference
The mmap calls look like this:
int fd = ::open("somefile", flags, 0666);
if(fd != -1) {
myBasePointer = ::mmap(0, sizeInBytes,
PROT_READ|PROT_WRITE, MAP_SHARED,
fd, offsetInBytes);
}
One process creates the file and mmaps, the other processes opens the file and mmaps itinto their address space. The file is a normal file on an ordinary filesystem.