From: Tigran Aivazian <tigran@veritas.com>
To: Alan Cox <alan@lxorguk.ukuu.org.uk>
Cc: linux-kernel@vger.kernel.org
Subject: [patch-2.4.0-test11] free_uid() optimization
Date: Mon, 27 Nov 2000 12:07:45 +0000 (GMT) [thread overview]
Message-ID: <Pine.LNX.4.21.0011271203520.827-100000@penguin.homenet> (raw)
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/
reply other threads:[~2000-11-27 12:36 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=Pine.LNX.4.21.0011271203520.827-100000@penguin.homenet \
--to=tigran@veritas.com \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=linux-kernel@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).