mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Keith Owens <kaos@ocs.com.au>
To: torvalds@transmeta.com (Linus Torvalds)
Cc: linux-kernel@vger.kernel.org
Subject: Re: [Lse-tech] Re: RFC: patch to allow lock-free traversal of lists with insertion
Date: Wed, 10 Oct 2001 21:54:39 +1000	[thread overview]
Message-ID: <12638.1002714879@ocs3.intra.ocs.com.au> (raw)
In-Reply-To: Your message of "Wed, 10 Oct 2001 05:05:10 GMT." <9q0ku6$175$1@penguin.transmeta.com>

On Wed, 10 Oct 2001 05:05:10 +0000 (UTC), 
torvalds@transmeta.com (Linus Torvalds) wrote:
>Now, before people get all excited, what is this particular code
>actually _good_ for?
>
>Creating a lock-free list that allows insertion concurrently with lookup
>is _easy_.
>
>But what's the point? If you insert stuff, you eventually have to remove
>it. What goes up must come down. Insert-inane-quote-here.
>
>And THAT is the hard part. Doing lookup without locks ends up being
>pretty much worthless, because you need the locks for the removal
>anyway, at which point the whole thing looks pretty moot.

<pedantic>

It is possible to do completely lock free queue management, I have done
it (once).  There are several major requirements :-

* Storage must never change its type (type stable storage).  Once a
  block has been assigned as struct foo, it must always contain struct
  foo.  This can be relaxed slightly as long as the data types have a
  common header format.

  The biggest problem this causes is that storage can never be released
  and unmapped.  You never know if somebody is going to follow an old
  pointer to access storage that you freed.  You must put the storage
  on a free list for struct foo instead of unmapping it, to maintain
  the type stable storage.

* Every piece of code that traverses the data tree for structure foo
  must take a copy of each struct foo into local storage.  After taking
  a copy it must verify that its local copy is self consistent, via
  validity indicators in each struct.  The validity indicators are
  typically generation numbers, whatever you use, the indicators must
  be atomically updated and atomically read, with suitable wmb and rmb
  barriers for machines with weak memory ordering.

* After following a pointer in your local copy of struct foo to access
  another data area, you must verify that the master version of your
  local copy has not been changed.  If the master copy has changed then
  the pointer you just followed is no longer reliable.  In almost every
  case you have to start the traversal from the beginning.  It makes
  for very convoluted reader and updater code.

</pedantic>

The only reason I used lock free read and update was to hook into an
existing system that mandated sub second responses.  Some of the new
operations that were performed during list traversal and update were
subject to unbounded delays that were completely outside my control.  I
could not afford to lock the data structures during traversal because
any delay in the new operations would completely stall the existing
system, also the existing system had to be able to retrieve and delete
data for the new operations at any time.

I don't recommend doing lock free unless you have absolutely no
alternative.  It requires convoluted code, it is difficult to debug, it
is expensive on memory bandwidth (forget zero copy) and tends to be
expensive on storage as well.

If you are interested in lock free work, take a look at
http://www.cs.pitt.edu/~moir/papers.html, particularly Practical
Implementations of Non-Blocking Synchronization Primitives.  But
beware, that paper has an error which caused intermittent bugs that
took me 5 months to track down.  Section 3.3, proc Copy, line 6 should
be

6:     y := addr->data[i];


  parent reply	other threads:[~2001-10-10 11:54 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-10-09 15:45 Paul McKenney
2001-10-09 17:00 ` Richard Henderson
2001-10-10  2:05 ` [Lse-tech] " Andrea Arcangeli
2001-10-10  5:05   ` Linus Torvalds
2001-10-10  5:17     ` BALBIR SINGH
2001-10-10  5:29       ` Davide Libenzi
2001-10-10  5:46       ` Linus Torvalds
2001-10-10  6:01         ` BALBIR SINGH
2001-10-10 15:23           ` Victor Yodaiken
2001-10-10  7:14         ` kdb requires kallsyms Kirill Ratkin
2001-10-10  7:38           ` BALBIR SINGH
2001-10-10 11:54     ` Keith Owens [this message]
2001-10-10 13:42       ` AIC7XXX war
2001-10-10 21:40         ` AIC7XXX Luigi Genoni
2001-10-10  6:16   ` [Lse-tech] Re: RFC: patch to allow lock-free traversal of lists with insertion Paul Mackerras
2001-10-10  6:30     ` Linus Torvalds
2001-10-10  7:36   ` Paul Mackerras
2001-10-10 15:54     ` Victor Yodaiken
2001-10-10 21:56       ` Keith Owens
2001-10-10 22:24         ` Victor Yodaiken
2001-10-10 23:46         ` David S. Miller
2001-10-11  0:24           ` Davide Libenzi
2001-10-10 13:24   ` Ivan Kokshaysky
2001-10-10 13:41     ` Andrea Arcangeli
2001-10-10  3:33 ` Paul Mackerras
2001-10-10 17:02   ` Richard Henderson
2001-10-10  4:43 [Lse-tech] " Paul McKenney
2001-10-10  6:54 Dipankar Sarma
2001-10-10  7:06 Dipankar Sarma
2001-10-10  7:21 ` BALBIR SINGH
2001-10-10  9:06   ` Dipankar Sarma
2001-10-10  7:58 Dipankar Sarma
2001-10-10 10:06 Dipankar Sarma
2001-10-10 10:18 ` Linus Torvalds
2001-10-10 11:43   ` Dipankar Sarma
2001-10-12  3:27 ` Rusty Russell
2001-10-12 16:56   ` Linus Torvalds
2001-10-12 18:53     ` Dipankar Sarma
2001-10-13  7:25     ` Rusty Russell
2001-10-10 15:24 Paul McKenney
2001-10-10 16:58 ` Andrea Arcangeli
2001-10-10 17:25   ` Linus Torvalds
2001-10-12  5:06   ` Rusty Russell
2001-10-12 16:28     ` Linus Torvalds
2001-10-12 19:50       ` Al Dunsmuir
2001-10-13  7:38       ` Rusty Russell
2001-10-13  1:07     ` Paul Mackerras
2001-10-13  1:54       ` Davide Libenzi
2001-10-13  2:04         ` Linus Torvalds
2001-10-13  2:31           ` Davide Libenzi
2001-10-13  2:46             ` Davide Libenzi
2001-10-13  3:30             ` Linus Torvalds
2001-10-13  2:49         ` Paul Mackerras
2001-10-13  2:00       ` Linus Torvalds
2001-10-10 16:00 Paul McKenney
2001-10-10 21:44 Paul McKenney
     [not found] <20011010182730.0077454b.rusty@rustcorp.com.au>
2001-10-10  9:36 ` Linus Torvalds
2001-10-11  6:50 ` Rusty Russell
2001-10-11 10:34 Dipankar Sarma
2001-10-13 14:42 Paul McKenney
2001-10-13 17:23 ` Linus Torvalds
2001-10-13 17:28   ` Linus Torvalds
2001-10-14  7:25     ` Dipankar Sarma
2001-10-13 18:42   ` Andi Kleen
2001-10-13 19:15     ` Alexander Viro
2001-10-13 20:44     ` Rusty Russell
2001-10-13 21:19   ` Rusty Russell

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=12638.1002714879@ocs3.intra.ocs.com.au \
    --to=kaos@ocs.com.au \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@transmeta.com \
    /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®