From: Josef Bacik <jbacik@fusionio.com>
To: <linux-btrfs@vger.kernel.org>, <walken@google.com>,
<mingo@elte.hu>, <akpm@linux-foundation.org>,
<linux-kernel@vger.kernel.org>
Subject: [PATCH] rwsem: add rwsem_is_contended
Date: Fri, 30 Aug 2013 10:14:01 -0400 [thread overview]
Message-ID: <1377872041-390-1-git-send-email-jbacik@fusionio.com> (raw)
Btrfs uses an rwsem to control access to its extent tree. Threads will hold a
read lock on this rwsem while they scan the extent tree, and if need_resched()
they will drop the lock and schedule. The transaction commit needs to take a
write lock for this rwsem for a very short period to switch out the commit
roots. If there are a lot of threads doing this caching operation we can starve
out the committers which slows everybody out. To address this we want to add
this functionality to see if our rwsem has anybody waiting to take a write lock
so we can drop it and schedule for a bit to allow the commit to continue.
Thanks,
Signed-off-by: Josef Bacik <jbacik@fusionio.com>
---
I've cc'ed people who seemed like they may be in charge/familiar with this code,
hopefully I got the right people.
include/linux/rwsem.h | 1 +
lib/rwsem.c | 17 +++++++++++++++++
2 files changed, 18 insertions(+), 0 deletions(-)
diff --git a/include/linux/rwsem.h b/include/linux/rwsem.h
index 0616ffe..61a8802 100644
--- a/include/linux/rwsem.h
+++ b/include/linux/rwsem.h
@@ -35,6 +35,7 @@ extern struct rw_semaphore *rwsem_down_read_failed(struct rw_semaphore *sem);
extern struct rw_semaphore *rwsem_down_write_failed(struct rw_semaphore *sem);
extern struct rw_semaphore *rwsem_wake(struct rw_semaphore *);
extern struct rw_semaphore *rwsem_downgrade_wake(struct rw_semaphore *sem);
+extern int rwsem_is_contended(struct rw_semaphore *sem);
/* Include the arch specific part */
#include <asm/rwsem.h>
diff --git a/lib/rwsem.c b/lib/rwsem.c
index 19c5fa9..20858cd 100644
--- a/lib/rwsem.c
+++ b/lib/rwsem.c
@@ -287,6 +287,23 @@ struct rw_semaphore *rwsem_downgrade_wake(struct rw_semaphore *sem)
return sem;
}
+/*
+ * check to see if the rwsem we're holding has anybody waiting to acquire it.
+ */
+int rwsem_is_contended(struct rw_semaphore *sem)
+{
+ int ret = 0;
+ unsigned long flags;
+
+ if (!raw_spin_trylock_irqsave(&sem->wait_lock, flags))
+ return 1;
+ if (!list_empty(&sem->wait_list))
+ ret = 1;
+ raw_spin_unlock_irqrestore(&sem->wait_lock, flags);
+ return ret;
+}
+
+EXPORT_SYMBOL(rwsem_is_contended);
EXPORT_SYMBOL(rwsem_down_read_failed);
EXPORT_SYMBOL(rwsem_down_write_failed);
EXPORT_SYMBOL(rwsem_wake);
--
1.7.7.6
next reply other threads:[~2013-08-30 14:14 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-30 14:14 Josef Bacik [this message]
2013-08-31 14:51 ` [PATCH] rwsem: add rwsem_is_contended Peter Zijlstra
2013-09-03 15:49 ` Josef Bacik
2013-09-01 8:32 ` Michel Lespinasse
2013-09-02 17:18 ` Peter Hurley
2013-09-03 13:18 ` Josef Bacik
2013-09-04 11:46 ` Peter Hurley
2013-09-04 12:13 ` Josef Bacik
2013-09-03 15:47 ` Josef Bacik
2013-09-04 12:11 ` Peter Hurley
2013-09-16 23:05 ` Andrew Morton
2013-09-17 0:05 ` Josef Bacik
2013-09-17 0:29 ` David Daney
2013-09-17 0:37 ` Peter Hurley
2013-09-17 1:08 ` David Daney
2013-09-17 1:11 ` Josef Bacik
2013-09-17 1:22 ` Peter Hurley
2013-09-17 6:53 ` Ingo Molnar
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=1377872041-390-1-git-send-email-jbacik@fusionio.com \
--to=jbacik@fusionio.com \
--cc=akpm@linux-foundation.org \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=walken@google.com \
/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;
as well as URLs for NNTP newsgroup(s).