public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Write is not atomic?
@ 2012-10-15 21:36 Juliusz Chroboczek
  2012-10-15 22:21 ` Max Filippov
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Juliusz Chroboczek @ 2012-10-15 21:36 UTC (permalink / raw)
  To: linux-kernel

Hi,

The Linux manual page for write(2) says:

    The adjustment of the file offset and the write operation are
    performed as an atomic step.

This is apparently an extension to POSIX, which says

    This volume of IEEE Std 1003.1-2001 does not specify behavior of
    concurrent writes to a file from multiple processes. Applications
    should use some form of concurrency control.

The following fragment of code

    int fd;
    fd = open("exemple", O_CREAT | O_WRONLY | O_TRUNC, 0666);
    fork();
    write(fd, "Ouille", 6);
    close(fd);

produces "OuilleOuille", as expected, on ext4 on two machines running
Linux 3.2 AMD64.  However, over XFS on an old Pentium III at 500 MHz
running 2.6.32, it produces just "Ouille" roughly once in three times.

Sorry for not being able to give more test cases, but I cannot easily
change either the filesystem or the kernel on the Pentium server.

-- Juliusz Chroboczek

P.S. I'll appreciate being copied with any replies.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2012-10-16  6:22 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-15 21:36 Write is not atomic? Juliusz Chroboczek
2012-10-15 22:21 ` Max Filippov
2012-10-15 23:36   ` Juliusz Chroboczek
2012-10-15 23:13 ` Dave Chinner
2012-10-15 23:24   ` Philippe Troin
2012-10-15 23:42     ` Max Filippov
2012-10-15 23:40 ` Jochen Striepe
2012-10-16  6:21   ` Juliusz Chroboczek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox