Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1220548 > unrolled thread
| Started by | Ingo Molnar <mingo@kernel.org> |
|---|---|
| First post | 2015-09-08 09:40 +0200 |
| Last post | 2015-09-14 12:00 +0200 |
| Articles | 3 — 2 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: [RFC][PATCH RT 0/3] RT: Fix trylock deadlock without msleep() hack Ingo Molnar <mingo@kernel.org> - 2015-09-08 09:40 +0200
Re: [RFC][PATCH RT 0/3] RT: Fix trylock deadlock without msleep() hack Thomas Gleixner <tglx@linutronix.de> - 2015-09-08 10:20 +0200
Re: [RFC][PATCH RT 0/3] RT: Fix trylock deadlock without msleep() hack Ingo Molnar <mingo@kernel.org> - 2015-09-14 12:00 +0200
| From | Ingo Molnar <mingo@kernel.org> |
|---|---|
| Date | 2015-09-08 09:40 +0200 |
| Subject | Re: [RFC][PATCH RT 0/3] RT: Fix trylock deadlock without msleep() hack |
| Message-ID | <q6lFw-63O-11@gated-at.bofh.it> |
* Thomas Gleixner <tglx@linutronix.de> wrote:
> 3) sched_yield() makes me shudder
>
> CPU0 CPU1
>
> taskA
> lock(x->lock)
>
> preemption
> taskC
> taskB
> lock(y->lock);
> x = y->x;
> if (!try_lock(x->lock)) {
> unlock(y->lock);
> boost(taskA);
> sched_yield(); <- returns immediately
So I'm still struggling with properly parsing the usecase.
If y->x might become invalid the moment we drop y->lock, what makes the 'taskA'
use (after we've dropped y->lock) safe? Shouldn't we at least also have a
task_get(taskA)/task_put(taskA) reference count, to make sure the boosted task
stays around?
And if we are into getting reference counts, why not solve it at a higher level
and get a reference count to 'x' to make sure it's safe to use? Then we could do:
lock(y->lock);
retry:
x = y->x;
if (!trylock(x->lock)) {
get_ref(x->count)
unlock(y->lock);
lock(x->lock);
lock(y->lock);
put_ref(x->count);
if (y->x != x) { /* Retry if 'x' got dropped meanwhile */
unlock(x->lock);
goto retry;
}
}
Or so.
Note how much safer this sequence is, and still just as fast in the common case
(which I suppose is the main motivation within dcache.c?).
Thanks,
Ingo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [next] | [standalone]
| From | Thomas Gleixner <tglx@linutronix.de> |
|---|---|
| Date | 2015-09-08 10:20 +0200 |
| Message-ID | <q6mif-72x-31@gated-at.bofh.it> |
| In reply to | #1220548 |
On Tue, 8 Sep 2015, Ingo Molnar wrote:
>
> * Thomas Gleixner <tglx@linutronix.de> wrote:
>
> > 3) sched_yield() makes me shudder
> >
> > CPU0 CPU1
> >
> > taskA
> > lock(x->lock)
> >
> > preemption
> > taskC
> > taskB
> > lock(y->lock);
> > x = y->x;
> > if (!try_lock(x->lock)) {
> > unlock(y->lock);
> > boost(taskA);
> > sched_yield(); <- returns immediately
>
> So I'm still struggling with properly parsing the usecase.
>
> If y->x might become invalid the moment we drop y->lock, what makes
> the 'taskA' use (after we've dropped y->lock) safe? Shouldn't we at
> least also have a task_get(taskA)/task_put(taskA) reference count,
> to make sure the boosted task stays around?
Stevens trylock_and_boost() function makes sure that taskA cannot go
away while doing the boosting. It's a bug in my pseudo code, but that
does not make the issue above going away.
> And if we are into getting reference counts, why not solve it at a
> higher level and get a reference count to 'x' to make sure it's safe
> to use? Then we could do:
>
> lock(y->lock);
> retry:
> x = y->x;
> if (!trylock(x->lock)) {
> get_ref(x->count)
> unlock(y->lock);
> lock(x->lock);
> lock(y->lock);
> put_ref(x->count);
> if (y->x != x) { /* Retry if 'x' got dropped meanwhile */
> unlock(x->lock);
> goto retry;
> }
> }
>
> Or so.
In the case of dcache::dentry_kill() we probably do not have to take
refcounts and it might be actually counterproductive to do so. y->x,
i.e. dentry->parent, cannot vanish under us, if I understand the life
time rules correctly.
Aside of that, yes, I was thinking about a similar scheme for
that. I need some more time to grok all the rules there :)
Thanks,
tglx
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Ingo Molnar <mingo@kernel.org> |
|---|---|
| Date | 2015-09-14 12:00 +0200 |
| Message-ID | <q8yIh-2Dr-1@gated-at.bofh.it> |
| In reply to | #1220590 |
* Thomas Gleixner <tglx@linutronix.de> wrote:
> > And if we are into getting reference counts, why not solve it at a higher
> > level and get a reference count to 'x' to make sure it's safe to use? Then we
> > could do:
> >
> > lock(y->lock);
> > retry:
> > x = y->x;
> > if (!trylock(x->lock)) {
> > get_ref(x->count)
> > unlock(y->lock);
> > lock(x->lock);
> > lock(y->lock);
> > put_ref(x->count);
> > if (y->x != x) { /* Retry if 'x' got dropped meanwhile */
> > unlock(x->lock);
> > goto retry;
> > }
> > }
> >
> > Or so.
>
> In the case of dcache::dentry_kill() we probably do not have to take refcounts
> and it might be actually counterproductive to do so. y->x, i.e. dentry->parent,
> cannot vanish under us, if I understand the life time rules correctly.
Ok, that's even better.
> Aside of that, yes, I was thinking about a similar scheme for that. I need some
> more time to grok all the rules there :)
Ok, great! :-)
I really don't think we need a new locking primitive - and with something like the
above we could improve the code upstream as well and make it scale better in some
scenarios, right?
Thanks,
Ingo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web