mmap/read inconsistency

Nickolai Zeldovich kolya at mit.edu
Thu May 17 08:16:53 CEST 2001


After having the user reproduce the problem another couple of times,
I was able to distill the bug to this seemigly reproducible case: if
a file F has been previously mmap()'ed (but not held open anymore),
doing open("F", O_WRONLY), without O_TRUNC, followed by a write()
will not invalidate the mmap'ed cached(?) copy, though subsequent
read()'s will return coherent data.  Including O_TRUNC makes mmap
work properly.

I've attached a small shell script that demonstrates the problem on
my machine.  In the process, I've also updated to the latest version
of arla-0-35-branch, which didn't fix the problem.  FTR, the output
on my system is:

    read:
    a
    b
    mmap:
    a

-- kolya

#!/bin/sh

## this script assumes that "cp" uses mmap() and "cat" uses read(),
## which is the case on FreeBSD 4.2-STABLE

## create an initial file
echo a > a.txt

## cp will mmap() it, which is key for this bug
cp a.txt q

## now modify the file, without O_TRUNC
echo b >> a.txt

## look at the file using read()
echo "read:" ; cat a.txt

## now copy it using mmap() and look at the copy using read()
cp a.txt q
echo "mmap:" ; cat q

## clean up
rm -f q a.txt





More information about the Arla-drinkers mailing list