From: "Robert Mueller" <robm@fastmail.fm>
To: "Linus Torvalds" <torvalds@linux-foundation.org>,
"Bron Gondwana" <brong@fastmail.fm>
Cc: "Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>,
"Nick Piggin" <npiggin@suse.de>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Andi Kleen" <andi@firstfloor.org>, "Ingo Molnar" <mingo@elte.hu>,
"Ken Murchison" <murch@andrew.cmu.edu>
Subject: Re: Cyrus mmap vs lseek/write usage - (WAS: BUG: mmapfile/writev spurious zero bytes (x86_64/not i386, bisected, reproducable))
Date: Thu, 19 Jun 2008 09:45:59 +1000 [thread overview]
Message-ID: <1213832759.32537.1259210597@webmail.messagingengine.com> (raw)
In-Reply-To: <alpine.LFD.1.10.0806180858250.2907@woody.linux-foundation.org>
>> It actually does use MAP_SHARED already, but only for reading.
>> Writing is all done with seeks and writes, followed by a map
>> "refresh", which is really just an unmmap/mmap if the file has
>> extended past the "SLOP" (between 8 and 16 k after the end of the
>> file length at last mapping).
>
> So the more traditional way would be to do an all-mmap thing, and
> extend the file with ftruncate(), not write. That's somethign that
> programs like nntpd have been doing for decades, so it's a very
> "traditional" model and thus much more likely to be safe. It also
> avoids all the aliasing issues, if all accesses are done the same way.
As noted above, one thing cyrus does which does seem to be plain "wrong"
is that it mmaps a region greater the file size (rounds to an 8k
boundary, but 8k-16k past the current end of the file) and then assumes
that when it writes to the end of the file (but less than the end of the
mmap region) that there's no need to remmap and that data is immediately
available within the previous mmaped region.
Apparently that works on most OS's (but is what this bug actually
exposed), but according to the mmap docs:
---
If the size of the mapped file changes after the call to mmap() as a
result of some other operation on the mapped file, the effect of
references to portions of the mapped region that correspond to added or
removed portions of the file is unspecified.
---
The way I read that, even if you mmap a file with a size past the end of
the file currently, if you subsequently write to the end of that file,
you shouldn't assume that written data is available in the region you
previously mmaped, which cyrus definitely does do.
Amazingly (apart from HP/UX) no OS actually seems to have a problem with
this since there would be massive cyrus bug reports otherwise.
Rob
----------
robm@fastmail.fm
Sign up at http://fastmail.fm for fast, ad free, IMAP accessible email
next prev parent reply other threads:[~2008-06-19 0:06 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-17 6:00 BUG: mmapfile/writev spurious zero bytes (x86_64/not i386, bisected, reproducable) Bron Gondwana
2008-06-17 6:02 ` Bron Gondwana
2008-06-17 17:08 ` Linus Torvalds
2008-06-17 17:45 ` Linus Torvalds
2008-06-17 20:16 ` Linus Torvalds
2008-06-17 20:41 ` Linus Torvalds
2008-06-17 21:06 ` Linus Torvalds
2008-06-17 21:16 ` Andi Kleen
2008-06-17 21:24 ` Linus Torvalds
2008-06-17 21:30 ` Andi Kleen
2008-06-17 21:37 ` Linus Torvalds
2008-06-17 21:36 ` Al Viro
2008-06-17 21:42 ` Andi Kleen
2008-06-17 21:49 ` Linus Torvalds
2008-06-17 22:11 ` Al Viro
2008-06-17 22:21 ` Andi Kleen
2008-06-18 6:22 ` Nick Piggin
2008-06-17 21:20 ` Linus Torvalds
2008-06-18 2:27 ` Bron Gondwana
2008-06-18 3:14 ` Bron Gondwana
2008-06-18 4:03 ` Linus Torvalds
2008-06-18 5:11 ` Cyrus mmap vs lseek/write usage - (WAS: BUG: mmapfile/writev spurious zero bytes (x86_64/not i386, bisected, reproducable)) Bron Gondwana
2008-06-18 16:22 ` Linus Torvalds
2008-06-18 23:45 ` Robert Mueller [this message]
2008-06-19 0:20 ` Linus Torvalds
2008-10-03 11:44 ` BUG: mmapfile/writev spurious zero bytes still in the wild Bron Gondwana
2008-10-03 13:07 ` Andrew Morton
2008-10-04 0:13 ` Bron Gondwana
2008-06-17 21:15 ` BUG: mmapfile/writev spurious zero bytes (x86_64/not i386, bisected, reproducable) Andi Kleen
2008-06-17 20:58 ` Andi Kleen
2008-06-17 21:14 ` Linus Torvalds
2008-06-17 21:26 ` Andi Kleen
2008-06-17 21:31 ` Linus Torvalds
2008-06-17 21:34 ` Linus Torvalds
2008-06-17 21:34 ` Andi Kleen
2008-06-17 21:46 ` Linus Torvalds
2008-06-18 6:10 ` Nick Piggin
2008-06-18 2:21 ` Bron Gondwana
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1213832759.32537.1259210597@webmail.messagingengine.com \
--to=robm@fastmail.fm \
--cc=akpm@linux-foundation.org \
--cc=andi@firstfloor.org \
--cc=brong@fastmail.fm \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=murch@andrew.cmu.edu \
--cc=npiggin@suse.de \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox