public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "David B. Stevens" <dsteven3@maine.rr.com>
To: Valdis.Kletnieks@vt.edu
Cc: nagendra_tomar@adaptec.com, Timo Sirainen <tss@iki.fi>,
	Jamie Lokier <jamie@shareable.org>,
	root@chaos.analogic.com,
	Martin Konold <martin.konold@erfrakon.de>,
	linux-kernel@vger.kernel.org
Subject: Re: Lockless file reading
Date: Thu, 28 Aug 2003 16:13:14 -0400	[thread overview]
Message-ID: <3F4E625A.8080002@maine.rr.com> (raw)
In-Reply-To: <200308280842.h7S8gCln032095@turing-police.cc.vt.edu>

Valdis.Kletnieks@vt.edu wrote:
> On Thu, 28 Aug 2003 00:12:30 +0530, Nagendra Singh Tomar said:
> 
> 
>>Why do u require file locking if there is a *single* writer ?? I don't 
>>understand why a 123 written over XXX can result in 1X3.
> 
> 
> You'd be *amazed* at what can go strange (not wrong, just strange) at the
> hardware level.  Let's assume for the sake of argument that  in your '123' and
> 'XXX', each character represents 4 or 8 or however many bytes wide your memory
> bus is (so "123" is really a 24 byte string).  The following can happen
> (especially if your hardware doesn't have cache coherency):
> 
> 1) CPU 0 stores the 24 bytes, and it splits across a cache line boundary.
> The '12' goes in one line, '3' in the next.
> 
> 2) Cache controller 0 does the writeback of '3' first.
> 
> 3) Cache controller 0 starts the writeback of the other cache line,
> and gets the '1' written, still waiting for next memory cycle to write '2'.
> 
> 4) CPU 1 or a DMA device snarfs up the 24 bytes before the '2' gets there.
> '3' got there, '1' got there, '2' will get there the *NEXT* bus cycle.
> 
> 1X3.  Whoops. 
> 
> Real hardware does this sort of thing all the time. Consider *this* gem from
> the IBM S/370 Principles of Operation (GA22-7000-10, page 5-12):
> 

Snip

 >
 >
>  In addition, if the format
> *used* to be a %4d that wrote to the last 4 bytes of a page, and somebody nails
> it to be a %8d halfway through, we may or may not get a SEGV when we scribble 4
> bytes onto the next page in memory, even if it's a readonly page we scribbled
> on....
> 

Ah, but the scribble will not take place.

> The description of what order things are seen to happen in runs for 11 pages,
> *not* including special-cases like the above....
> 

BTW you are quoting from my all time favorite book. Conceptual order is 
not always the real order and all those mind games.

Cheers,
   Dave


  reply	other threads:[~2003-08-28 20:11 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-08-27 12:37 Lockless file reading Timo Sirainen
2003-08-27 12:42 ` Martin Konold
2003-08-27 12:52   ` Timo Sirainen
2003-08-27 13:40     ` Richard B. Johnson
2003-08-27 14:56       ` Timo Sirainen
2003-08-27 23:39         ` Jamie Lokier
2003-08-28  0:52           ` Timo Sirainen
2003-08-27 18:42             ` Nagendra Singh Tomar
2003-08-28  8:40               ` Timo Sirainen
2003-08-27 21:15                 ` Nagendra Singh Tomar
2003-08-28  9:35                   ` Timo Sirainen
2003-08-27 21:52                     ` Nagendra Singh Tomar
2003-08-28 13:26                       ` Matthias Andree
2003-08-28  9:17                 ` David Schwartz
2003-08-28  8:42               ` Valdis.Kletnieks
2003-08-28 20:13                 ` David B. Stevens [this message]
2003-08-28  1:50             ` Jamie Lokier
2003-08-28  3:17               ` Timo Sirainen
2003-08-28  6:01                 ` Valdis.Kletnieks
2003-08-28  6:13                 ` Jamie Lokier
2003-08-28  8:57                   ` Timo Sirainen
2003-08-28  9:56                     ` David Schwartz
2003-08-28 10:26                       ` Timo Sirainen
2003-08-27 22:58                         ` Nagendra Singh Tomar
2003-08-28 12:18                           ` Jamie Lokier
2003-08-28  0:39                             ` Nagendra Singh Tomar
2003-08-28 13:00                               ` Jamie Lokier
2003-08-28  1:06                                 ` Nagendra Singh Tomar
2003-08-28 21:49                             ` Bernd Eckenfels
2003-08-28 12:01                         ` Jamie Lokier
2003-08-28 13:28                           ` Timo Sirainen
2003-08-28 20:24                         ` David Schwartz
2003-08-28 12:44                       ` Ragnar Hojland Espinosa
2003-08-28 13:03                         ` Jamie Lokier
2003-08-28 17:26                           ` root
2003-08-28 17:35                             ` Jamie Lokier
2003-08-28 18:10                               ` root
2003-08-28 21:59                             ` Bernd Eckenfels
2003-08-28 23:02                               ` Jamie Lokier
2003-08-28 23:44                               ` Lockless file readingu root
2003-08-29 10:00                                 ` jlnance
2003-08-29 11:55                                   ` David Schwartz
2003-08-29 15:43                                   ` William Lee Irwin III
2003-08-28 20:37                         ` Lockless file reading David Schwartz
2003-08-28 22:11                           ` Bernd Eckenfels
2003-08-28 23:00                             ` Jamie Lokier
2003-08-29  0:47                             ` David Schwartz
2003-08-28  9:13                 ` Martin Konold
2003-08-28  9:27                   ` Timo Sirainen
2003-08-28  9:48                     ` Martin Konold
2003-08-28  0:03       ` Jamie Lokier
2003-08-28 12:08         ` Richard B. Johnson
2003-08-28 12:39           ` Jamie Lokier
2003-08-28 10:08   ` Matthias Andree
2003-08-28 10:54 ` Robin Rosenberg
2003-08-28 12:42   ` Jamie Lokier

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=3F4E625A.8080002@maine.rr.com \
    --to=dsteven3@maine.rr.com \
    --cc=Valdis.Kletnieks@vt.edu \
    --cc=jamie@shareable.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.konold@erfrakon.de \
    --cc=nagendra_tomar@adaptec.com \
    --cc=root@chaos.analogic.com \
    --cc=tss@iki.fi \
    /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