From: Manfred Spraul <manfred@colorfullife.com>
To: Andrew Morton <akpm@linux-foundation.org>,
Linus Torvalds <torvalds@linux-foundation.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
Rik van Riel <riel@redhat.com>,
Davidlohr Bueso <davidlohr.bueso@hp.com>,
hhuang@redhat.com, Mike Galbraith <efault@gmx.de>,
Manfred Spraul <manfred@colorfullife.com>,
Mike Galbraith <bitbucket@online.de>
Subject: [PATCH 2/2] ipc/sem.c: optimize sem_lock().
Date: Sat, 14 Sep 2013 23:34:56 +0200 [thread overview]
Message-ID: <1379194496-4642-2-git-send-email-manfred@colorfullife.com> (raw)
In-Reply-To: <1379194496-4642-1-git-send-email-manfred@colorfullife.com>
Operations that need access to the whole array must guarantee that there are
no simple operations ongoing. Right now this is achieved by
spin_unlock_wait(sem->lock) on all semaphores.
If complex_count is nonzero, then this spin_unlock_wait() is not necessary,
because it was already performed in the past by the thread that increased
complex_count and even though sem_perm.lock was dropped inbetween, no simple
operation could have started, because simple operations cannot start when
complex_count is non-zero.
What do you think?
The patch survived some testing.
Its not a bugfix - thus I don't know if it should go into linux-next first.
Signed-off-by: Manfred Spraul <manfred@colorfullife.com>
Cc: Mike Galbraith <bitbucket@online.de>
Cc: Rik van Riel <riel@redhat.com>
Cc: Davidlohr Bueso <davidlohr.bueso@hp.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
---
ipc/sem.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/ipc/sem.c b/ipc/sem.c
index 4836ea7..5274ed1 100644
--- a/ipc/sem.c
+++ b/ipc/sem.c
@@ -248,12 +248,20 @@ static void merge_queues(struct sem_array *sma)
* Caller must own sem_perm.lock.
* New simple ops can start, because simple ops first check
* that sem_perm.lock is free.
+ * that a) sem_perm.lock is free and b) complex_count is 0.
*/
static void sem_wait_array(struct sem_array *sma)
{
int i;
struct sem *sem;
+ if (sma->complex_count) {
+ /* The thread that increased sma->complex_count waited on
+ * all sem->lock locks. Thus we don't need to wait again.
+ */
+ return;
+ }
+
for (i = 0; i < sma->sem_nsems; i++) {
sem = sma->sem_base + i;
spin_unlock_wait(&sem->lock);
--
1.8.3.1
next prev parent reply other threads:[~2013-09-14 21:35 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-14 21:34 [PATCH 1/2] ipc/sem.c: Race in sem_lock() Manfred Spraul
2013-09-14 21:34 ` Manfred Spraul [this message]
2013-09-15 6:09 ` Mike Galbraith
2013-09-15 8:06 ` Mike Galbraith
2013-09-16 11:03 ` Mike Galbraith
2013-09-15 11:34 ` Manfred Spraul
2013-09-15 19:30 ` Davidlohr Bueso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1379194496-4642-2-git-send-email-manfred@colorfullife.com \
--to=manfred@colorfullife.com \
--cc=akpm@linux-foundation.org \
--cc=bitbucket@online.de \
--cc=davidlohr.bueso@hp.com \
--cc=efault@gmx.de \
--cc=hhuang@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=riel@redhat.com \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®