From: Andi Kleen <ak@muc.de>
To: chris_friesen@sympatico.ca (Chris Friesen)
Cc: linux-kernel@vger.kernel.org
Subject: Re: nitpicky questions regarding mmap() and msync()
Date: 10 Aug 2001 13:12:26 +0200 [thread overview]
Message-ID: <k28zgsdv8l.fsf@zero.aec.at> (raw)
In-Reply-To: <3B732DAE.CD117CBA@sympatico.ca>
In-Reply-To: chris_friesen@sympatico.ca's message of "Fri, 10 Aug 2001 00:42:52 +0000 (UTC)"
In article <3B732DAE.CD117CBA@sympatico.ca>,
chris_friesen@sympatico.ca (Chris Friesen) writes:
> A couple questions about mmap()'d files.
> 1) If I have an mmap()'d file and I write to it and then I am hit with a SIGKILL
> before I have a chance to msync(), am I guaranteed that changes I've made to the
> information in the file will be available if I restart and try to mmap() the
> same file? The man page says only that there is no guarantee that changes are
> written back to disk if msync() is not called, but some informal testing seems
> to indicate that changes are in fact written out. Is this a timing issue or
> does the system guarantee this?
The system does guarantee it. There is no special case for SIGKILL exit,
it is just an ordinary exit and it does properly munmap all your mappings.
> 2) If I make changes to the contents of an mmap()'d file, am I guaranteed that
> the order I make the changes is the same order that they will be available to
> another process that has mmap()'d the same file? (Or can I be bit by
> optimization reordering? If this is the case, can I get around this by reading
> it as volatile and using the barrie() macro?)
When two processes access the same mapping in Linux they always work
on the same block of memory, so standard memory ordering rules apply.
On a lot of architectures that means you need to use appropiate read and
write barriers to avoid reordering on SMP systems.
[on some architectures like early mips chips there can be nasty issues
with virtual cache aliases though, but that should not concern you here]
The memory can be flushed to disk and reread at any time, in this
regard it is no different from any other anonymous memory, except that
it is not written to swap but to your backing file.
The order in which the changes are flushed to disk is completely undefined.
-Andi
prev parent reply other threads:[~2001-08-10 11:12 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-08-10 0:41 nitpicky questions regarding mmap() and msync() Chris Friesen
2001-08-10 11:12 ` Andi Kleen [this message]
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=k28zgsdv8l.fsf@zero.aec.at \
--to=ak@muc.de \
--cc=chris_friesen@sympatico.ca \
--cc=linux-kernel@vger.kernel.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