sigbus on memcpy despite calling mincore

From: Sandeep Joshi
Date: Mon Jan 20 2014 - 04:50:19 EST

Hi folks

I have a program which is trying to read a page from the page cache
for a certain file


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,

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 ?

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at