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