public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: David Howells <dhowells@redhat.com>
To: Linus Torvalds <torvalds@osdl.org>
Cc: akpm@osdl.org, trond.myklebust@fys.uio.no, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] keys: Discard key spinlock and use RCU for key payload
Date: Wed, 09 Mar 2005 18:43:52 +0000	[thread overview]
Message-ID: <28732.1110393832@redhat.com> (raw)
In-Reply-To: <Pine.LNX.4.58.0503091019060.2530@ppc970.osdl.org>

Linus Torvalds <torvalds@osdl.org> wrote:

> > The attached patch changes the key implementation in a number of ways:
> > 
> >  (1) It removes the spinlock from the key structure.
> > 
> >  (2) The key flags are now accessed using atomic bitops instead of
> >      write-locking the key spinlock and using C bitwise operators.
> 
> I'd suggest against using __set_bit() for the initialization. Either use
> the proper set_bit() (which is slow, but at least consistent), or just
> initialize it with (1ul << KEY_FLAG_IN_QUOTA). __set_bit is generally
> slower than setting a value (it's pretty guaranteed not to be faster, and
> at least on x86 is clearly slower), so using it as an "optimization" is
> misguided.

Yeah... fair enough.

> RCU seems to fit the key model pretty well, but I still wonder whether the 
> conceptual complexity is worth it. Was this done on a whim, or was there 
> some real reason for it?

There are two parts to the reason:

 (1) Keys are for the most part invariant. Whilst they can be modified if the
     type supports it, this should be uncommon. Except in the case of
     keyrings, that is, but they're a special case anyway.

 (2) Anything that accesses a key's payload (which includes the keyring search
     algorithm) must hold the key's spinlock whilst it is looking at it, for
     as long as it is looking at it.

     With RCU, this is no longer necessary. You just can't schedule until
     you've finished looking at it.

Given that for the most part keys don't change, it'd be very nice not to have
to get a read lock on them. For something like NFS or AFS, the key will
probably have to be accessed for every remote procedure call, for example; and
a process's keyrings will have to be searched on every open call, assuming
keys are associated with struct files or struct inodes.

The current locking model is quite complicated, and great care has to be taken
to avoid recursive deadlocks; so in some ways the RCU model is actually
simpler.

> I'd love for that to be documented while you're at it..

I need to update the key documentation to reflect the changes in locking, but
the base kernel doesn't have the previous sets of doc changes; something I'd
like to build on.

When you or Andrew have released such a kernel, I'll update the docs too.

David

      reply	other threads:[~2005-03-09 18:50 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-09 17:59 [PATCH] keys: Discard key spinlock and use RCU for key payload David Howells
2005-03-09 18:24 ` Linus Torvalds
2005-03-09 18:43   ` David Howells [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=28732.1110393832@redhat.com \
    --to=dhowells@redhat.com \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@osdl.org \
    --cc=trond.myklebust@fys.uio.no \
    /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