lkml.org 
[lkml]   [2000]   [Nov]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[patch-2.4.0-test11] free_uid() optimization
Hi Alan,

Instead of having SMP-specific code and doing a sequence of (on SMP):

test if count is 0
take a spinlock
test if count is still 0

we could make use of the atomic primitive

atomic_dec_and_lock()

and do it in one go, which is cleaner, imho.

Regards,
Tigran

--- linux.kernel/user.c Mon Nov 27 12:01:34 2000
+++ work/kernel/user.c Mon Nov 27 12:03:20 2000
@@ -74,27 +74,12 @@
}
}

-/*
- * For SMP, we need to re-test the user struct counter
- * after having acquired the spinlock. This allows us to do
- * the common case (not freeing anything) without having
- * any locking.
- */
-#ifdef CONFIG_SMP
- #define uid_hash_free(up) (!atomic_read(&(up)->__count))
-#else
- #define uid_hash_free(up) (1)
-#endif
-
void free_uid(struct user_struct *up)
{
if (up) {
- if (atomic_dec_and_test(&up->__count)) {
- spin_lock(&uidhash_lock);
- if (uid_hash_free(up)) {
- uid_hash_remove(up);
- kmem_cache_free(uid_cachep, up);
- }
+ if (atomic_dec_and_lock(&up->__count, &uidhash_lock)) {
+ uid_hash_remove(up);
+ kmem_cache_free(uid_cachep, up);
spin_unlock(&uidhash_lock);
}
}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 12:47    [W:0.022 / U:47.628 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site