Skip to contentSkip to conversation

ipc-msg-mitigate-the-lock-contention-with-percpu-counter.patch removed from -mm tree

merged mm-nonmm-stable Andrew Morton 1 participant 1 message Oct 3, 2022

lore
Share & tools
lore

Andrew Morton

author tree notice Applied
#0 lore raw

The quilt patch titled
Subject: ipc/msg: mitigate the lock contention with percpu counter
has been removed from the -mm tree. Its filename was
ipc-msg-mitigate-the-lock-contention-with-percpu-counter.patch

This patch was dropped because it was merged into the mm-nonmm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

------------------------------------------------------
From: Jiebin Sun <[email protected]>
Subject: ipc/msg: mitigate the lock contention with percpu counter
Date: Wed, 14 Sep 2022 03:25:38 +0800

The msg_bytes and msg_hdrs atomic counters are frequently updated when IPC msg queue is in heavy use, causing heavy cache bounce and overhead. Change them to percpu_counter greatly improve the performance. Since there is one percpu struct per namespace, additional memory cost is minimal. Reading of the count done in msgctl call, which is infrequent. So the need to sum up the counts in each CPU is infrequent.

Apply the patch and test the pts/stress-ng-1.4.0
-- system v message passing (160 threads).

Score gain: 3.99x

CPU: ICX 8380 x 2 sockets
Core number: 40 x 2 physical cores
Benchmark: pts/stress-ng-1.4.0
-- system v message passing (160 threads)

[[email protected]: coding-style cleanups]
[[email protected]: avoid negative value by overflow in msginfo]
[[email protected]: fix min() warnings]
Cc Alexander Mikhalitsyn <[email protected]>
Cc Alexey Gladkov <[email protected]>
Cc Christoph Lameter <[email protected]>
Cc Davidlohr Bueso <[email protected]>
Cc Dennis Zhou <[email protected]>
Cc "Eric W . Biederman" <[email protected]>
Cc Manfred Spraul <[email protected]>
Cc Shakeel Butt <[email protected]>
Cc Tejun Heo <[email protected]>
Cc Vasily Averin <[email protected]>

---

 include/linux/ipc_namespace.h |    5 ++-
 ipc/msg.c                     |   48 ++++++++++++++++++++++----------
 ipc/namespace.c               |    5 ++-
 ipc/util.h                    |    4 +-
 4 files changed, 43 insertions(+), 19 deletions(-)
include/linux/ipc_namespace.h renamed from include/linux/ipc_namespace.h~ipc-msg-mitigate-the-lock-contention-with-percpu-counter +3 -2
@@ -11,6 +11,7 @@
 #include <linux/refcount.h>
 #include <linux/rhashtable-types.h>
 #include <linux/sysctl.h>
+#include <linux/percpu_counter.h>
 
 struct user_namespace;
 
@@ -36,8 +37,8 @@ struct ipc_namespace {
 	unsigned int	msg_ctlmax;
 	unsigned int	msg_ctlmnb;
 	unsigned int	msg_ctlmni;
-	atomic_t	msg_bytes;
-	atomic_t	msg_hdrs;
+	struct percpu_counter percpu_msg_bytes;
+	struct percpu_counter percpu_msg_hdrs;
 
 	size_t		shm_ctlmax;
 	size_t		shm_ctlall;
ipc/msg.c renamed from ipc/msg.c~ipc-msg-mitigate-the-lock-contention-with-percpu-counter +34 -14

103 lines not on this page · raw message

ipc/namespace.c renamed from ipc/namespace.c~ipc-msg-mitigate-the-lock-contention-with-percpu-counter +4 -1
@@ -66,8 +66,11 @@ static struct ipc_namespace *create_ipc_
 	if (!setup_ipc_sysctls(ns))
 		goto fail_mq;
 
+	err = msg_init_ns(ns);
+	if (err)
+		goto fail_put;
+
 	sem_init_ns(ns);
-	msg_init_ns(ns);
 	shm_init_ns(ns);
 
 	return ns;
ipc/util.h renamed from ipc/util.h~ipc-msg-mitigate-the-lock-contention-with-percpu-counter +2 -2
@@ -64,7 +64,7 @@ static inline void mq_put_mnt(struct ipc
 
 #ifdef CONFIG_SYSVIPC
 void sem_init_ns(struct ipc_namespace *ns);
-void msg_init_ns(struct ipc_namespace *ns);
+int msg_init_ns(struct ipc_namespace *ns);
 void shm_init_ns(struct ipc_namespace *ns);
 
 void sem_exit_ns(struct ipc_namespace *ns);
@@ -72,7 +72,7 @@ void msg_exit_ns(struct ipc_namespace *n
 void shm_exit_ns(struct ipc_namespace *ns);
 #else
 static inline void sem_init_ns(struct ipc_namespace *ns) { }
-static inline void msg_init_ns(struct ipc_namespace *ns) { }
+static inline int msg_init_ns(struct ipc_namespace *ns) { return 0; }
 static inline void shm_init_ns(struct ipc_namespace *ns) { }
 
 static inline void sem_exit_ns(struct ipc_namespace *ns) { }

_

Patches currently in -mm which might be from [email protected] are