On Wed, 2013-06-26 at 15:40 -0700, Davidlohr Bueso wrote:
> On Wed, 2013-06-26 at 15:28 -0700, Tim Chen wrote:
> > We want to add optimistic spinning to rwsems because we've noticed that
> > the writer rwsem does not perform as well as mutexes. Tim noticed that
> > for exim (mail server) workloads, when reverting commit 4fc3f1d6 and 
> > Davidlohr
> > noticed it when converting the i_mmap_mutex to a rwsem in some aim7
> > workloads. We've noticed that the biggest difference, in a nutshell, is
> > when we fail to acquire a mutex in the fastpath, optimistic spinning
> > comes in to play and we can avoid a large amount of unnecessary sleeping
> > and wait queue overhead.
> > 
> > For rwsems on the other hand, upon entering the writer slowpath in
> > rwsem_down_write_failed(), we just acquire the ->wait_lock, add
> > ourselves to the wait_queue and blocking until we get the lock.
> > 
> > Reviewed-by: Peter Zijlstra <[email protected]>
> > Reviewed-by: Peter Hurley <[email protected]>
> > Signed-off-by: Tim Chen <[email protected]>
> > Signed-off-by: Davidlohr Bueso <[email protected]>
> > ---
> >  include/linux/rwsem.h |    3 +
> >  init/Kconfig          |    9 +++
> >  kernel/rwsem.c        |   29 +++++++++-
> >  lib/rwsem.c           |  150 
> > +++++++++++++++++++++++++++++++++++++++++++++----
> >  4 files changed, 179 insertions(+), 12 deletions(-)
> > 
> > diff --git a/include/linux/rwsem.h b/include/linux/rwsem.h
> > index 0616ffe..0c5933b 100644
> > --- a/include/linux/rwsem.h
> > +++ b/include/linux/rwsem.h
> > @@ -29,6 +29,9 @@ struct rw_semaphore {
> >  #ifdef CONFIG_DEBUG_LOCK_ALLOC
> >     struct lockdep_map      dep_map;
> >  #endif
> > +#ifdef CONFIG_RWSEM_SPIN_ON_WRITE_OWNER
> > +   struct task_struct      *owner;
> > +#endif
> >  };
> >  
> >  extern struct rw_semaphore *rwsem_down_read_failed(struct rw_semaphore 
> > *sem);
> > diff --git a/init/Kconfig b/init/Kconfig
> > index 9d3a788..1c582d1 100644
> > --- a/init/Kconfig
> > +++ b/init/Kconfig
> > @@ -1595,6 +1595,15 @@ config TRACEPOINTS
> >  
> >  source "arch/Kconfig"
> >  
> > +config RWSEM_SPIN_ON_WRITE_OWNER
> > +   bool "Optimistic spin write acquisition for writer owned rw-sem"
> > +   default n
> > +   depends on SMP
> > +   help
> > +     Allows a writer to perform optimistic spinning if another writer own
> > +     the read write semaphore.  This gives a greater chance for writer to
> > +     acquire a semaphore before blocking it and putting it to sleep.
> > +
> 
> Quoting from kernel/mutex.c:
> 
> "The rationale is that if the lock owner is running, it is likely to
> release the lock soon." 
> 
> It would be good to add that to the Kconfig.

Sounds good.

Tim


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

Reply via email to