From: Peter Zijlstra <peterz@infradead.org>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Ingo Molnar <mingo@kernel.org>, Michal Hocko <mhocko@kernel.org>,
Al Viro <viro@zeniv.linux.org.uk>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Thomas Gleixner <tglx@linutronix.de>,
Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [GIT PULL] killable rwsems for v4.7
Date: Tue, 17 May 2016 13:02:42 +0200 [thread overview]
Message-ID: <20160517110242.GV3193@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <CA+55aFwvJOw7YSLq7TmUuD92NQy5MCqvn-UtmMnsnMKBB4zKcQ@mail.gmail.com>
On Mon, May 16, 2016 at 01:32:28PM -0700, Linus Torvalds wrote:
> On Mon, May 16, 2016 at 7:55 AM, Ingo Molnar <mingo@kernel.org> wrote:
> >
> > This tree, by Michal Hocko, implements down_write_killable(). The main usecase
> > will be to update mm_sem usage sites to use this new API,
>
> Hmm. Is somebody (Michal?) looking at down_read_killable() too?
>
> The VFS layer will want it with the pending parallel lookup code - the
> inode semaphore is being converted to a rwsem, and there's a couple of
> "killable" users.. The first step actually just wants to the exclusive
> case (ie the write case that this adds), but I think the readdir code
> could really use a reading version too..
Something roughly like so.
Completely untested etc..
---
kernel/locking/rwsem-spinlock.c | 28 +++++++++++++++++++++++-----
kernel/locking/rwsem-xadd.c | 28 +++++++++++++++++++++++++---
2 files changed, 48 insertions(+), 8 deletions(-)
diff --git a/kernel/locking/rwsem-spinlock.c b/kernel/locking/rwsem-spinlock.c
index 1591f6b3539f..d66325970248 100644
--- a/kernel/locking/rwsem-spinlock.c
+++ b/kernel/locking/rwsem-spinlock.c
@@ -125,7 +125,7 @@ __rwsem_wake_one_writer(struct rw_semaphore *sem)
/*
* get a read lock on the semaphore
*/
-void __sched __down_read(struct rw_semaphore *sem)
+int __sched __down_read_common(struct rw_semaphore *sem, int state)
{
struct rwsem_waiter waiter;
struct task_struct *tsk;
@@ -137,11 +137,11 @@ void __sched __down_read(struct rw_semaphore *sem)
/* granted */
sem->count++;
raw_spin_unlock_irqrestore(&sem->wait_lock, flags);
- goto out;
+ return 0;
}
tsk = current;
- set_task_state(tsk, TASK_UNINTERRUPTIBLE);
+ set_task_state(tsk, state);
/* set up my own style of waitqueue */
waiter.task = tsk;
@@ -155,6 +155,8 @@ void __sched __down_read(struct rw_semaphore *sem)
/* wait to be given the lock */
for (;;) {
+ if (signal_pending_state(state, current))
+ goto out_nolock;
if (!waiter.task)
break;
schedule();
@@ -162,8 +164,24 @@ void __sched __down_read(struct rw_semaphore *sem)
}
__set_task_state(tsk, TASK_RUNNING);
- out:
- ;
+ return 0;
+
+out_nolock:
+ raw_spin_lock_irqsave(&sem->wait_lock, flags);
+ if (waiter.task)
+ list_del(&waiter.list);
+ else
+ sem->count--;
+ if (!list_empty(&sem->wait_list))
+ __rwsem_do_wake(sem, 1);
+ raw_spin_unlock_irqrestore(&sem->wait_lock, flags);
+
+ return -EINTR;
+}
+
+void __sched __down_read(struct rw_semaphore *sem)
+{
+ __down_read_common(sem, TASK_UNINTERRUPTIBLE);
}
/*
diff --git a/kernel/locking/rwsem-xadd.c b/kernel/locking/rwsem-xadd.c
index 09e30c6225e5..4f7b1fb1f127 100644
--- a/kernel/locking/rwsem-xadd.c
+++ b/kernel/locking/rwsem-xadd.c
@@ -210,8 +210,8 @@ __rwsem_do_wake(struct rw_semaphore *sem, enum rwsem_wake_type wake_type)
/*
* Wait for the read lock to be granted
*/
-__visible
-struct rw_semaphore __sched *rwsem_down_read_failed(struct rw_semaphore *sem)
+static inline struct rw_semaphore *
+rwsem_down_read_failed_common(struct rw_semaphore *sem, int state)
{
long count, adjustment = -RWSEM_ACTIVE_READ_BIAS;
struct rwsem_waiter waiter;
@@ -244,7 +244,9 @@ struct rw_semaphore __sched *rwsem_down_read_failed(struct rw_semaphore *sem)
/* wait to be given the lock */
while (true) {
- set_task_state(tsk, TASK_UNINTERRUPTIBLE);
+ set_task_state(tsk, state);
+ if (signal_pending_state(state, current))
+ goto out_nolock;
if (!waiter.task)
break;
schedule();
@@ -252,6 +254,26 @@ struct rw_semaphore __sched *rwsem_down_read_failed(struct rw_semaphore *sem)
__set_task_state(tsk, TASK_RUNNING);
return sem;
+
+out_nolock:
+ raw_spin_lock_irq(&sem->wait_lock);
+ if (waiter.task != NULL)
+ list_del(&waiter.list);
+ else
+ rwsem_atomic_update(-RWSEM_ACTIVE_READ_BIAS, sem);
+ if (list_empty(&sem->wait_list))
+ rwsem_atomic_update(-RWSEM_WAITING_BIAS, sem);
+ else
+ __rwsem_do_wake(sem, RWSEM_WAKE_ANY);
+ raw_spin_unlock_irq(&sem->wait_lock);
+
+ return ERR_PTR(-EINTR);
+}
+
+__visible struct rw_semaphore * __sched
+rwsem_down_read_failed(struct rw_semaphore *sem)
+{
+ return rwsem_down_read_failed_common(sem, TASK_UNINTERRUPTIBLE);
}
EXPORT_SYMBOL(rwsem_down_read_failed);
prev parent reply other threads:[~2016-05-17 11:02 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-16 14:55 [GIT PULL] killable rwsems for v4.7 Ingo Molnar
2016-05-16 20:32 ` Linus Torvalds
2016-05-17 7:08 ` Michal Hocko
2016-05-17 18:05 ` Al Viro
2016-05-17 18:31 ` Linus Torvalds
2016-05-17 11:02 ` Peter Zijlstra [this message]
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=20160517110242.GV3193@twins.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mhocko@kernel.org \
--cc=mingo@kernel.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=viro@zeniv.linux.org.uk \
/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).