ucount: use RCU for ucounts lookups
The ucounts element is looked up under ucounts_lock. This can be optimized by using RCU for a lockless lookup and return and element if the reference can be obtained. Replace hlist_head with hlist_nulls_head which is RCU compatible. Let find_ucounts() search for the required item within a RCU section and return the item if a reference could be obtained. This means alloc_ucounts() will always return an element (unless the memory allocation failed). Let put_ucounts() RCU free the element if the reference counter dropped to zero. Link: https://lkml.kernel.org/r/20250203150525.456525-4-bigeasy@linutronix.de Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Reviewed-by: Paul E. McKenney <paulmck@kernel.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Boqun Feng <boqun.feng@gmail.com> Cc: Joel Fernandes <joel@joelfernandes.org> Cc: Josh Triplett <josh@joshtriplett.org> Cc: Lai jiangshan <jiangshanlai@gmail.com> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Cc: Mengen Sun <mengensun@tencent.com> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: "Uladzislau Rezki (Sony)" <urezki@gmail.com> Cc: YueHong Wu <yuehongwu@tencent.com> Cc: Zqiang <qiang.zhang1211@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
committed by
Andrew Morton
parent
328152e677
commit
5f01a22c5b
@@ -5,6 +5,7 @@
|
||||
#include <linux/kref.h>
|
||||
#include <linux/nsproxy.h>
|
||||
#include <linux/ns_common.h>
|
||||
#include <linux/rculist_nulls.h>
|
||||
#include <linux/sched.h>
|
||||
#include <linux/workqueue.h>
|
||||
#include <linux/rwsem.h>
|
||||
@@ -115,9 +116,10 @@ struct user_namespace {
|
||||
} __randomize_layout;
|
||||
|
||||
struct ucounts {
|
||||
struct hlist_node node;
|
||||
struct hlist_nulls_node node;
|
||||
struct user_namespace *ns;
|
||||
kuid_t uid;
|
||||
struct rcu_head rcu;
|
||||
atomic_t count;
|
||||
atomic_long_t ucount[UCOUNT_COUNTS];
|
||||
atomic_long_t rlimit[UCOUNT_RLIMIT_COUNTS];
|
||||
|
||||
Reference in New Issue
Block a user