Re: [PATCH] posix-timers: RCU conversion

From: Oleg Nesterov
Date: Tue Apr 05 2011 - 10:49:41 EST


On 04/04, john stultz wrote:
>
> On Sun, 2011-04-03 at 18:54 +0200, Eric Dumazet wrote:
> > --- a/include/linux/posix-timers.h
> > +++ b/include/linux/posix-timers.h
> > @@ -81,6 +81,7 @@ struct k_itimer {
> > unsigned long expires;
> > } mmtimer;
> > } it;
> > + struct rcu_head rcu;
> > };

Can't we move this rcu_head into the union above?

> > struct k_clock {
> > diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
> > index 4c01249..acb9be9 100644
> > --- a/kernel/posix-timers.c
> > +++ b/kernel/posix-timers.c
> > @@ -491,6 +491,13 @@ static struct k_itimer * alloc_posix_timer(void)
> > return tmr;
> > }
> >
> > +static void k_itimer_rcu_free(struct rcu_head *head)
> > +{
> > + struct k_itimer *tmr = container_of(head, struct k_itimer, rcu);
> > +
> > + kmem_cache_free(posix_timers_cache, tmr);
> > +}

Not that I really think it makes sense to change the patch... but we
could even use SLAB_DESTROY_BY_RCU, this is more effective. All we
need is ctor which sets ->it_signal = NULL and initializes ->it_lock
for lock_timer().

> > static struct k_itimer *__lock_timer(timer_t timer_id, unsigned long *flags)
> > {
> > struct k_itimer *timr;
> > - /*
> > - * Watch out here. We do a irqsave on the idr_lock and pass the
> > - * flags part over to the timer lock. Must not let interrupts in
> > - * while we are moving the lock.
> > - */
> > - spin_lock_irqsave(&idr_lock, *flags);
> > +
> > + rcu_read_lock();
> > timr = idr_find(&posix_timers_id, (int)timer_id);
> > if (timr) {
> > - spin_lock(&timr->it_lock);
> > + spin_lock_irqsave(&timr->it_lock, *flags);
> > if (timr->it_signal == current->signal) {
> > - spin_unlock(&idr_lock);
> > + rcu_read_unlock();
> > return timr;
> > }
> > - spin_unlock(&timr->it_lock);
> > + spin_unlock_irqrestore(&timr->it_lock, *flags);
> > }
> > - spin_unlock_irqrestore(&idr_lock, *flags);
> > + rcu_read_unlock();

I think this is correct.

The question is, why do we use the global database for the timer ids.
All timers live in signal_struct->posix_timers anyway, perhaps we could
use a per-process array instead.

Oleg.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/