mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@osdl.org>
To: Klaus Ripke <paul@malete.org>
Cc: Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: mm/filemap.c: atomic file read(2)/write(2) ?
Date: Sat, 10 Jan 2004 08:35:11 -0800 (PST)	[thread overview]
Message-ID: <Pine.LNX.4.58.0401092144330.1877@evo.osdl.org> (raw)
In-Reply-To: <200401091308.45802.paul@malete.org>



On Fri, 9 Jan 2004, Klaus Ripke wrote:
> 
> judging from mm/filemap.c it seems like
> ordinary reads/writes should be atomic to each other
> (read sees write completely or not at all,
> not only where it "can be proven to be after the write"),
> if

Nope. There are file descriptors that have atomicity guarantees (pipes(, 
but regular files do not. In particular, even on UP you'll see nonatomic 
reads with PREEMPT enabled.

Even without preempt you could see interesting partial updates if you take 
a page fault. That's true even if your user space only ever reads or 
writes within a whole page, since what you can get on the read() path is:

 - read one word from the page cache
 - try to write it to user space
 - take a page fault - sleep

 - writer now comes in and updates the region

 - the reader comes back after the page fault
 - the reader completes the copy_to_user(), but the _first_ word was read 
   from the old page cache contents and not re-read.

(This will depend on which particular version of copy_to_user() you use: a
"rep movs" will re-read the page cache and give an "atomic" read, while
all other forms of memory copies will only re-try the destination write
instruction, with the old value read from the source).

		Linus

      reply	other threads:[~2004-01-10 17:01 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-01-09 12:08 Klaus Ripke
2004-01-10 16:35 ` Linus Torvalds [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=Pine.LNX.4.58.0401092144330.1877@evo.osdl.org \
    --to=torvalds@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paul@malete.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

all inboxes | Powered by JetHome®