[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240812084823.563277-1-xavier_qy@163.com>
Date: Mon, 12 Aug 2024 16:48:23 +0800
From: Xavier <xavier_qy@....com>
To: tglx@...utronix.de
Cc: anna-maria@...utronix.de,
frederic@...nel.org,
j.granados@...sung.com,
kees@...nel.org,
linux-kernel@...r.kernel.org,
linux@...ssschuh.net,
mcgrof@...nel.org,
xavier_qy@....com
Subject: [PATCH v2] Ucount: Optimize the ucount code
Optimize the memory release operation by placing it outside of the
spin lock in alloc_ucounts.
Signed-off-by: Xavier <xavier_qy@....com>
---
kernel/ucount.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/kernel/ucount.c b/kernel/ucount.c
index 8c07714ff27d..87a773e6ff15 100644
--- a/kernel/ucount.c
+++ b/kernel/ucount.c
@@ -164,7 +164,7 @@ struct ucounts *get_ucounts(struct ucounts *ucounts)
struct ucounts *alloc_ucounts(struct user_namespace *ns, kuid_t uid)
{
struct hlist_head *hashent = ucounts_hashentry(ns, uid);
- struct ucounts *ucounts, *new;
+ struct ucounts *ucounts, *new = NULL;
bool wrapped;
spin_lock_irq(&ucounts_lock);
@@ -182,9 +182,7 @@ struct ucounts *alloc_ucounts(struct user_namespace *ns, kuid_t uid)
spin_lock_irq(&ucounts_lock);
ucounts = find_ucounts(ns, uid, hashent);
- if (ucounts) {
- kfree(new);
- } else {
+ if (!ucounts) {
hlist_add_head(&new->node, hashent);
get_user_ns(new->ns);
spin_unlock_irq(&ucounts_lock);
@@ -193,6 +191,9 @@ struct ucounts *alloc_ucounts(struct user_namespace *ns, kuid_t uid)
}
wrapped = !get_ucounts_or_wrap(ucounts);
spin_unlock_irq(&ucounts_lock);
+ if (new)
+ kfree(new);
+
if (wrapped) {
put_ucounts(ucounts);
return NULL;
--
2.45.2
Powered by blists - more mailing lists