]>
Commit | Line | Data |
---|---|---|
d66c7e8f GKH |
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 | |
5 | ||
6 | From: Davidlohr Bueso <davidlohr.bueso@hp.com> | |
7 | ||
8 | commit 8b8d52ac382b17a19906b930cd69e2edb0aca8ba upstream. | |
9 | ||
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: | |
14 | ||
15 | http://lkml.org/lkml/2013/3/20/546 (sems) | |
16 | http://lkml.org/lkml/2013/5/15/584 (mqueues) | |
17 | ||
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. | |
22 | ||
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 | |
25 | when updating. | |
26 | ||
27 | Patch 9: renames the ids rw_mutex to rwsem, which is what it already was. | |
28 | ||
29 | Patch 10: is a trivial mqueue leftover cleanup | |
30 | ||
31 | Patch 11: adds a brief lock scheme description, requested by Andrew. | |
32 | ||
33 | This patch: | |
34 | ||
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 | |
38 | ipc_obtain_object*(). | |
39 | ||
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> | |
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. |