From: Steffen Klassert <steffen.klassert@secunet.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Herbert Xu <herbert@gondor.hengli.com.au>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 6/8] padata: Use a timer to handle the reorder queues
Date: Fri, 30 Apr 2010 13:20:00 +0200 [thread overview]
Message-ID: <20100430112000.GM5275@secunet.com> (raw)
In-Reply-To: <20100429160644.4dee414d.akpm@linux-foundation.org>
On Thu, Apr 29, 2010 at 04:06:44PM -0700, Andrew Morton wrote:
> On Thu, 29 Apr 2010 14:43:37 +0200
> Steffen Klassert <steffen.klassert@secunet.com> wrote:
>
> > padata_get_next had a bogus check that returned always true,
> > so the try_again loop in padata_reorder was never taken.
>
> A better changelog would have told us what this "bogus check" _is_.
>
> > This can lead to object leaks in some rare cases.
>
> And a better changelog would describe those leaks!
I'll try to write a better one and resent.
>
> > This patch
> > implements a timer that processes the reorder queues if noone
> > else does it in appropriate time.
>
> Under what circumstances would "noone else do it in appropriate time"?
> Would that be a bug, or what?
>
We need to ensure that only one cpu can work on dequeueing of the reorder
queue the time. Calculating in which percpu reorder queue the next object
will arrive takes some time. A spinlock would be highly contended. Also
it is not clear in which order the objects arrive to the reorder queues.
So a cpu could wait to get the lock just to notice that there is nothing to
do at the moment. Therefore we use a trylock and let the holder of the
lock care for all the objects enqueued during the holdtime of the lock.
The timer is to handle a race that appears with the trylock. If cpu1 queues
an object to the reorder queue while cpu2 holds the pd->lock but left the
while loop in padata_reorder already, cpu2 can't care for this object but cpu1
exits because it can't get the lock. Usually the next cpu that takes the
lock cares for this object too. We need the timer just if this object was the
last one that arrives to the reorder queues. The timer function sends it out
in this case.
> > @@ -273,13 +274,22 @@ try_again:
> >
> > spin_unlock_bh(&pd->lock);
> >
> > - if (atomic_read(&pd->reorder_objects))
> > - goto try_again;
> > + if (atomic_read(&pd->reorder_objects)
> > + && !(pinst->flags & PADATA_RESET))
> > + mod_timer(&pd->timer, jiffies + HZ);
> > + else
> > + del_timer(&pd->timer);
> >
> > -out:
> > return;
> > }
>
> I'd feel more comfortable if the above was in the locked region. Is
> there a race whereby another CPU can set pd->reorder_objects, but we
> forgot to arm the timer?
>
We could hit the race that the timer handles, if we move this into the lock.
cpu1 cpu2
spin_trylock_bh()
|
|
|
test pd->reorder_objects == 0
delete timer
|
hardinterrupt
| set pd->reorder_objects == 1
| enqueue object
| spin_trylock_bh() busy
| exit
|
spin_unlock_bh()
next prev parent reply other threads:[~2010-04-30 18:18 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-29 12:36 [PATCH 0/8] padata: fixes/cleanups Steffen Klassert
2010-04-29 12:37 ` [PATCH 1/8] padata: Dont scale the parallel objects with the cpus Steffen Klassert
2010-04-29 12:40 ` [PATCH 2/8] padata: cpu hotplug code should depend on CONFIG_HOTPLUG_CPU Steffen Klassert
2010-04-29 12:40 ` [PATCH 3/8] padata: Remove superfluous might_sleep Steffen Klassert
2010-04-29 12:41 ` [PATCH 4/8] padata: Initialize the padata queues only for the used cpus Steffen Klassert
2010-04-29 12:42 ` [PATCH 5/8] padata: Use get_online_cpus/put_online_cpus Steffen Klassert
2010-04-29 12:43 ` [PATCH 6/8] padata: Use a timer to handle the reorder queues Steffen Klassert
2010-04-29 23:06 ` Andrew Morton
2010-04-30 11:20 ` Steffen Klassert [this message]
2010-05-03 3:38 ` Herbert Xu
2010-04-29 12:44 ` [PATCH 7/8] padata: Flush the padata queues actively Steffen Klassert
2010-04-29 23:11 ` Andrew Morton
2010-04-30 11:24 ` Steffen Klassert
2010-04-29 12:45 ` [PATCH 8/8] padata: Add some code comments Steffen Klassert
2010-04-29 23:13 ` [PATCH 0/8] padata: fixes/cleanups Andrew Morton
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=20100430112000.GM5275@secunet.com \
--to=steffen.klassert@secunet.com \
--cc=akpm@linux-foundation.org \
--cc=herbert@gondor.hengli.com.au \
--cc=linux-kernel@vger.kernel.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