]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/3.11.6/ipc-shm-introduce-lockless-functions-to-obtain-the-ipc-object.patch
4.14-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 3.11.6 / ipc-shm-introduce-lockless-functions-to-obtain-the-ipc-object.patch
CommitLineData
d66c7e8f
GKH
1From 8b8d52ac382b17a19906b930cd69e2edb0aca8ba Mon Sep 17 00:00:00 2001
2From: Davidlohr Bueso <davidlohr.bueso@hp.com>
3Date: Wed, 11 Sep 2013 14:26:15 -0700
4Subject: ipc,shm: introduce lockless functions to obtain the ipc object
5
6From: Davidlohr Bueso <davidlohr.bueso@hp.com>
7
8commit 8b8d52ac382b17a19906b930cd69e2edb0aca8ba upstream.
9
10This is the third and final patchset that deals with reducing the amount
11of contention we impose on the ipc lock (kern_ipc_perm.lock). These
12changes mostly deal with shared memory, previous work has already been
13done for semaphores and message queues:
14
15 http://lkml.org/lkml/2013/3/20/546 (sems)
16 http://lkml.org/lkml/2013/5/15/584 (mqueues)
17
18With these patches applied, a custom shm microbenchmark stressing shmctl
19doing IPC_STAT with 4 threads a million times, reduces the execution
20time by 50%. A similar run, this time with IPC_SET, reduces the
21execution time from 3 mins and 35 secs to 27 seconds.
22
23Patches 1-8: replaces blindly taking the ipc lock for a smarter
24combination of rcu and ipc_obtain_object, only acquiring the spinlock
25when updating.
26
27Patch 9: renames the ids rw_mutex to rwsem, which is what it already was.
28
29Patch 10: is a trivial mqueue leftover cleanup
30
31Patch 11: adds a brief lock scheme description, requested by Andrew.
32
33This patch:
34
35Add shm_obtain_object() and shm_obtain_object_check(), which will allow us
36to get the ipc object without acquiring the lock. Just as with other
37forms of ipc, these functions are basically wrappers around
38ipc_obtain_object*().
39
40Signed-off-by: Davidlohr Bueso <davidlohr.bueso@hp.com>
41Tested-by: Sedat Dilek <sedat.dilek@gmail.com>
42Cc: Rik van Riel <riel@redhat.com>
43Cc: Manfred Spraul <manfred@colorfullife.com>
44Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
45Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
46Cc: Mike Galbraith <efault@gmx.de>
47Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
48
49---
50 ipc/shm.c | 20 ++++++++++++++++++++
51 1 file changed, 20 insertions(+)
52
53--- a/ipc/shm.c
54+++ b/ipc/shm.c
55@@ -124,6 +124,26 @@ void __init shm_init (void)
56 IPC_SHM_IDS, sysvipc_shm_proc_show);
57 }
58
59+static inline struct shmid_kernel *shm_obtain_object(struct ipc_namespace *ns, int id)
60+{
61+ struct kern_ipc_perm *ipcp = ipc_obtain_object(&shm_ids(ns), id);
62+
63+ if (IS_ERR(ipcp))
64+ return ERR_CAST(ipcp);
65+
66+ return container_of(ipcp, struct shmid_kernel, shm_perm);
67+}
68+
69+static inline struct shmid_kernel *shm_obtain_object_check(struct ipc_namespace *ns, int id)
70+{
71+ struct kern_ipc_perm *ipcp = ipc_obtain_object_check(&shm_ids(ns), id);
72+
73+ if (IS_ERR(ipcp))
74+ return ERR_CAST(ipcp);
75+
76+ return container_of(ipcp, struct shmid_kernel, shm_perm);
77+}
78+
79 /*
80 * shm_lock_(check_) routines are called in the paths where the rw_mutex
81 * is not necessarily held.