From: Andrew Morton Date: Fri, 24 Mar 2006 11:15:47 +0000 (-0800) Subject: [PATCH] free_uid() locking improvement X-Git-Tag: v2.6.17-rc1~945 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=36f574135e36b86bb6ae794bf1d0fce3efa5601f;p=linux-2.6 [PATCH] free_uid() locking improvement Reduce lock hold times in free_uid(). Cc: Ingo Molnar Cc: "Paul E. McKenney" Cc: David Howells Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/kernel/user.c b/kernel/user.c index d9deae43a9..2116642f42 100644 --- a/kernel/user.c +++ b/kernel/user.c @@ -105,15 +105,19 @@ void free_uid(struct user_struct *up) { unsigned long flags; + if (!up) + return; + local_irq_save(flags); - if (up && atomic_dec_and_lock(&up->__count, &uidhash_lock)) { + if (atomic_dec_and_lock(&up->__count, &uidhash_lock)) { uid_hash_remove(up); + spin_unlock_irqrestore(&uidhash_lock, flags); key_put(up->uid_keyring); key_put(up->session_keyring); kmem_cache_free(uid_cachep, up); - spin_unlock(&uidhash_lock); + } else { + local_irq_restore(flags); } - local_irq_restore(flags); } struct user_struct * alloc_uid(uid_t uid)