some files written via mmap end up corrupted

Mikhail Teterin mi+kde at
Tue Nov 22 12:48:03 GMT 2005

On Tuesday 22 November 2005 02:45 am, Dan Nelson wrote:
= In the last episode (Nov 21), Mikhail Teterin said:
= > I must not be using the API properly :-(
= > 
= > The writes to the mmap-ed area and then fsync-s the opened file,
= > munmaps it, and exits.
= > 
= > Sometimes, the files end up corrupted at the end, however -- in about
= > 10% of cases.
= What kind of corruption are you seeing?  Blocks of zeroes?

Hard to say -- the files are (supposed to be) gzip-ed at the end. But
`gzip -t' detects corruption in some of them.

= Maybe you need to call msync() before unmapping the region? Or call
= munmap before fsync.

mmap(2) page says, msync() is obsolete now, and that fsync(2) "will
flush all dirty data and metadata associated with a file, including
dirty NOSYNC VM data, to physical media"

= Can't tell that for sure without seeing the code :)

The ending sequence was fsync->close->munmap. I changed it to
fsync->munmap->close (not that it should matter), and am going to try
again now.

mmap is such a beautiful interface, too bad people don't use it and it
bitrots :-(



More information about the freebsd-questions mailing list