Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758001Ab1BRAiV (ORCPT ); Thu, 17 Feb 2011 19:38:21 -0500 Received: from e4.ny.us.ibm.com ([32.97.182.144]:46651 "EHLO e4.ny.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757805Ab1BRAiL (ORCPT ); Thu, 17 Feb 2011 19:38:11 -0500 From: Matt Helsley To: linux-kernel@vger.kernel.org Cc: Matt Helsley , David Howells , Pavel Emelyanov , Alexey Dobriyan , "Serge E. Hallyn" , containers@lists.linux-foundation.org Subject: [PATCH] Reduce uidhash lock hold time when lookup succeeds Date: Thu, 17 Feb 2011 15:52:53 -0800 Message-Id: X-Mailer: git-send-email 1.6.3.3 X-Content-Scanned: Fidelis XPS MAILER Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1465 Lines: 50 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 Cc: David Howells Cc: Pavel Emelyanov Cc: Alexey Dobriyan Cc: "Serge E. Hallyn" 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 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/