All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Serge E. Hallyn" <serge.hallyn@canonical.com>
To: Matt Helsley <matthltc@us.ibm.com>
Cc: linux-kernel@vger.kernel.org,
	Pavel Emelyanov <xemul@parallels.com>,
	containers@lists.linux-foundation.org,
	David Howells <dhowells@redhat.com>,
	Alexey Dobriyan <adobriyan@gmail.com>
Subject: Re: [PATCH] Reduce uidhash lock hold time when lookup succeeds
Date: Fri, 18 Feb 2011 12:25:02 -0600	[thread overview]
Message-ID: <20110218182502.GA22238@localhost> (raw)
In-Reply-To: <caebc7ebaa97599ef72b22d1172dfd2ebe770fce.1297986770.git.matthltc@us.ibm.com>

Quoting Matt Helsley (matthltc@us.ibm.com):
> When lookup succeeds we don't need the "new" user struct which hasn't
> been linked into the uidhash. So we can immediately drop the lock and
> then free "new" rather than free it with the lock held.
> 
> Signed-off-by: Matt Helsley <matthltc@us.ibm.com>
> Cc: David Howells <dhowells@redhat.com>
> Cc: Pavel Emelyanov <xemul@parallels.com>
> Cc: Alexey Dobriyan <adobriyan@gmail.com>
> Cc: "Serge E. Hallyn" <serge@hallyn.com>

Acked-by: Serge E. Hallyn <serge@hallyn.com>

And might I say that the label 'out_unlock' in that function is
sadly named :)

> Cc: containers@lists.linux-foundation.org
> ---
>  kernel/user.c |   12 +++++++-----
>  1 files changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/kernel/user.c b/kernel/user.c
> index 5c598ca..4ea8e58 100644
> --- a/kernel/user.c
> +++ b/kernel/user.c
> @@ -157,16 +157,18 @@ struct user_struct *alloc_uid(struct user_namespace *ns, uid_t uid)
>  		 */
>  		spin_lock_irq(&uidhash_lock);
>  		up = uid_hash_find(uid, hashent);
> -		if (up) {
> +		if (!up) {
> +			uid_hash_insert(new, hashent);
> +			up = new;
> +		}
> +		spin_unlock_irq(&uidhash_lock);
> +
> +		if (up != new) {
>  			put_user_ns(ns);
>  			key_put(new->uid_keyring);
>  			key_put(new->session_keyring);
>  			kmem_cache_free(uid_cachep, new);
> -		} else {
> -			uid_hash_insert(new, hashent);
> -			up = new;
>  		}
> -		spin_unlock_irq(&uidhash_lock);
>  	}
>  
>  	return up;
> -- 
> 1.6.3.3
> 
> _______________________________________________
> Containers mailing list
> Containers@lists.linux-foundation.org
> https://lists.linux-foundation.org/mailman/listinfo/containers

  parent reply	other threads:[~2011-02-18 18:25 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-17 23:52 [PATCH] Reduce uidhash lock hold time when lookup succeeds Matt Helsley
     [not found] ` <caebc7ebaa97599ef72b22d1172dfd2ebe770fce.1297986770.git.matthltc-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2011-02-18 18:25   ` Serge E. Hallyn
2011-02-18 18:25 ` Serge E. Hallyn [this message]
  -- strict thread matches above, loose matches on Subject: below --
2011-02-17 23:52 Matt Helsley

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=20110218182502.GA22238@localhost \
    --to=serge.hallyn@canonical.com \
    --cc=adobriyan@gmail.com \
    --cc=containers@lists.linux-foundation.org \
    --cc=dhowells@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matthltc@us.ibm.com \
    --cc=xemul@parallels.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.