Re: Severe performance regression w/ 4.4+ on Android due to cgroup locking changes
From: Peter Zijlstra
Date: Thu Jul 14 2016 - 14:36:19 EST
On Thu, Jul 14, 2016 at 08:09:52PM +0200, Oleg Nesterov wrote:
> On 07/14, Peter Zijlstra wrote:
> >
> > The below is a compile tested only first draft so far. I'll go give it
> > some runtime next.
>
> So I will wait for the new version, but at first glance this matches the
> code I already reviewed in the past (at least, tried hard to review ;)
> and it looks correct.
>
> Just a couple of almost cosmetic nits, feel free to ignore.
Drat, I just mailed out the patches.. I can do a second version later.
> > --- a/include/linux/percpu-rwsem.h
> > +++ b/include/linux/percpu-rwsem.h
> > @@ -10,29 +10,107 @@
> >
> > struct percpu_rw_semaphore {
> > struct rcu_sync rss;
> > - unsigned int __percpu *fast_read_ctr;
> > + unsigned int __percpu *refcount;
> > struct rw_semaphore rw_sem;
> > - atomic_t slow_read_ctr;
> > - wait_queue_head_t write_waitq;
> > + wait_queue_head_t writer;
> > + int state;
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
> I think that this "int state" and "enum { readers_slow, readers_block }"
> just add a bit of complication/confusion.
>
> All we need is the simple "bool readers_block" in percpu_rw_semaphore,
> no?
So I detest bool in structures because sizeof(bool) isn't defined.
Obviously an implementation needs to pick a size, but this is typically
architecture ABIs, so sizes can differ between architectures.
But yes, I suppose "int readers_block" will do just fine.
IIRC, earlier version had more states, but that all went away.
> > +void percpu_down_write(struct percpu_rw_semaphore *sem)
> > {
> > + down_write(&sem->rw_sem);
> > +
> > + /* Notify readers to take the slow path. */
> > + rcu_sync_enter(&sem->rss);
>
> I'd suggest to call rcu_sync_enter() before down_write(). This can help
> when we wait for another writer which holds this lock.
Hurm, I think I figured that might have issues, but I cannot seem to
think of any just now :-), yes can do.