mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jamie Lokier <lk@tantalophile.demon.co.uk>
To: Andi Kleen <ak@suse.de>
Cc: Hirokazu Takahashi <taka@valinux.co.jp>,
	davem@redhat.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] zerocopy NFS updated
Date: Fri, 12 Apr 2002 22:22:52 +0100	[thread overview]
Message-ID: <20020412222252.A25184@kushida.apsleyroad.org> (raw)
In-Reply-To: <20020410.193045.32403941.davem@redhat.com> <20020411.154651.51706443.taka@valinux.co.jp> <20020410.234821.122842406.davem@redhat.com> <20020412.213011.45159995.taka@valinux.co.jp> <20020412143559.A25386@wotan.suse.de>

Andi Kleen wrote:
> > I wondered if regular truncate() and read() might have the same
> > problem, so I tested again and again.
> > And I realized it will occur on any local filesystems.
> > Sometime I could get partly zero filled data instead of file contents.
> > 
> I don't see it as a big problem and would just leave it as it is (for NFS
> and local) 
> Adding more locking would slow down read() a lot and there should be 
> a good reason to take such a performance hit. Linux did this forever
> and I don't think anybody ever reported it as a bug, so we can probably
> safely assume that this behaviour (non atomic truncate) is not a problem for 
> users in practice.

Ouch!  I have a program which can output incorrect results if this is
the case.  It may seem to use an esoteric locking strategy, but I had no
idea it was acceptable for read to return data that truncate is in the
middle of zeroing.

The program keeps a cache on disk of generated files.  For each cached
object, there is a metadata file.  Metadata files are text files,
written in such a way that the first line looks similar to "=12296.0"
and so does the last line, but none of the intermediate lines have that
form.

Multiple programs can access the disk cache at the same time, and must
be able to check the metadata files being written by other programs,
blocking if necessary while a cached object is being generated.

When a metadata file is being written, first it is created, then the
cached object is created and written to a related file, and finally the
metadata including the first and last marker line is written to the
metadata file.

When a program reads a metadata file, it reads as much as it can and
then checks the first and last lines are identical.  If they are, the
middle of the file is valid otherwise it isn't -- perhaps the process
generating that file died, or has the metadata file locked.

This strategy is used so that there's no need to lock the file, in the
cache of a cache hit with no complications.  If there's a complication
we lock with LOCK_SH and try again.

>From time to time, when a cache object is invalid, it's appropriate to
truncate the metadata file.  If that were atomic, end of story.
Unfortunately I've just now heard that a read() can successfully
interleave some zeros from a parallel truncate.

If the timing is right, that means it's possible for the reading
process to see a hole of zeros in the middle of the file.  The first and
last lines would be intact, and the reader would think that the whole
file is therefore valid.  Bad!

This occurs if the reader copies the initial bytes from the page, then
the truncation process catches up and zeros out some bytes, but then the
reader catches up and beats the truncation process to the end of the
file.

I'm not advocating more locking in read() -- there's no need, and it is
quite important that it is fast!  But I would very much appreciate an
understanding of the rules that relate reading, writing and truncating
processes.  How much ordering & atomicity can I depend on?  Anything at all?

cheers,
-- Jamie

  reply	other threads:[~2002-04-12 21:23 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20020410.190550.83626375.taka@valinux.co.jp.suse.lists.linux.kernel>
2002-04-10 19:32 ` Andi Kleen
2002-04-11  2:30   ` David S. Miller
2002-04-11  6:46     ` Hirokazu Takahashi
2002-04-11  6:48       ` David S. Miller
2002-04-11  7:41         ` Hirokazu Takahashi
2002-04-11  7:52           ` David S. Miller
2002-04-11 11:38             ` Hirokazu Takahashi
2002-04-11 11:36               ` David S. Miller
2002-04-11 18:00                 ` Denis Vlasenko
2002-04-11 13:16                   ` Andi Kleen
2002-04-11 17:36                     ` Benjamin LaHaise
2002-04-16  0:17                     ` Mike Fedyk
2002-04-16 15:37                       ` Oliver Xymoron
2002-04-11 17:33             ` Benjamin LaHaise
2002-04-12  8:10               ` Hirokazu Takahashi
2002-04-12 12:30         ` Hirokazu Takahashi
2002-04-12 12:35           ` Andi Kleen
2002-04-12 21:22             ` Jamie Lokier [this message]
2002-04-12 21:31               ` David S. Miller
2002-04-13  0:21                 ` Jamie Lokier
2002-04-13  6:39                   ` Andi Kleen
2002-04-13  8:01                     ` Hirokazu Takahashi
2002-04-13 19:19                     ` Eric W. Biederman
2002-04-13 19:37                       ` Andi Kleen
2002-04-13 20:34                         ` Eric W. Biederman
2002-04-24 23:11                           ` Mike Fedyk
2002-04-25 17:11                             ` Andreas Dilger
2002-04-13 18:52                 ` Chris Wedgwood
2002-04-14  0:07                   ` Keith Owens
2002-04-14  8:19                     ` Chris Wedgwood
2002-04-14  8:40                       ` Keith Owens
2002-04-12 21:39             ` David S. Miller
2002-04-15  1:30               ` Hirokazu Takahashi
2002-04-15  4:23                 ` David S. Miller
2002-04-16  1:03                   ` Hirokazu Takahashi
2002-04-16  1:41                     ` Jakob Østergaard
2002-04-16  2:20                       ` Hirokazu Takahashi
2002-04-18  5:01                       ` Hirokazu Takahashi
2002-04-18  7:58                         ` Jakob Østergaard
2002-04-18  8:53                         ` Trond Myklebust
2002-04-19  3:21                           ` Hirokazu Takahashi
2002-04-19  9:18                             ` Trond Myklebust
2002-04-20  7:47                               ` Hirokazu Takahashi
2002-04-25 12:37                                 ` Possible bug with UDP and SO_REUSEADDR. Was " Terje Eggestad
2002-04-26  2:43                                   ` David S. Miller
2002-04-26  7:38                                     ` Terje Eggestad
2002-04-29  0:41                                     ` Possible bug with UDP and SO_REUSEADDR David Schwartz
2002-04-29  8:06                                       ` Terje Eggestad
2002-04-29  8:44                                         ` David Schwartz
2002-04-29 10:03                                           ` Terje Eggestad
2002-04-29 10:38                                             ` David Schwartz
2002-04-29 14:20                                               ` Terje Eggestad
     [not found]                               ` <200204192128.QAA24592@popmail.austin.ibm.com>
2002-04-20 10:14                                 ` [PATCH] zerocopy NFS updated Hirokazu Takahashi
2002-04-20 15:49                                   ` Andrew Theurer
2002-04-10 10:05 Hirokazu Takahashi

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=20020412222252.A25184@kushida.apsleyroad.org \
    --to=lk@tantalophile.demon.co.uk \
    --cc=ak@suse.de \
    --cc=davem@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=taka@valinux.co.jp \
    /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®