Hi folks
I have a program which is trying to read a page from the page cache
for a certain file
it calls mmap (PROT_NONE, MAP_SHARED |MAP_LOCKED).
Then it calls mincore to check if the page is in memory
If it does exist, it remaps the same offset using mmap(PROT_READ,
MAP_SHARED|MAP_LOCKED)
After this, it is tries to do a read (memcpy) from the returned
address of the second mmap.
Unfortunately, I am getting a SIGBUS in cases where there is another
thread in the same process trying to write to the same file (though
not at the same offset)
when I look in /proc/<pid>/smaps, I see that the mapped address has
RSS=0 (not in memory) and LOCKED=0 (not locked) which is strange since
I have locked the page and called mincore on it.
I added checking for the filesize (fstat) before the first mmap but
still get a SIGBUS. I also changed the second and first mmaps to do
MAP_PRIVATE hoping it would give a private copy of the page but that
didnt help either.
Is there some race condition which resets the vma_flags when another
thread in the same process is writing to the same file offset being
read ?
thanks
-Sandeep