From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932147AbcEKJRr (ORCPT ); Wed, 11 May 2016 05:17:47 -0400 Received: from merlin.infradead.org ([205.233.59.134]:59476 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751400AbcEKJRp (ORCPT ); Wed, 11 May 2016 05:17:45 -0400 Date: Wed, 11 May 2016 11:17:33 +0200 From: Peter Zijlstra To: Michal Hocko Cc: Tetsuo Handa , LKML , Ingo Molnar , Thomas Gleixner , "H. Peter Anvin" , "David S. Miller" , Tony Luck , Andrew Morton , Chris Zankel , Max Filippov , Davidlohr Bueso , Waiman Long Subject: Re: [PATCH 03/11] locking, rwsem: introduce basis for down_write_killable Message-ID: <20160511091733.GC3192@twins.programming.kicks-ass.net> References: <1459508695-14915-1-git-send-email-mhocko@kernel.org> <1459508695-14915-4-git-send-email-mhocko@kernel.org> <8bd03bdc-0373-a3bb-da12-045322efb797@I-love.SAKURA.ne.jp> <20160510115320.GJ23576@dhcp22.suse.cz> <20160510123806.GB3193@twins.programming.kicks-ass.net> <20160511072357.GC16677@dhcp22.suse.cz> <20160511082853.GF16677@dhcp22.suse.cz> <20160511084401.GH3193@twins.programming.kicks-ass.net> <20160511090442.GH16677@dhcp22.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160511090442.GH16677@dhcp22.suse.cz> User-Agent: Mutt/1.5.21 (2012-12-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 11, 2016 at 11:04:42AM +0200, Michal Hocko wrote: > On Wed 11-05-16 10:44:01, Peter Zijlstra wrote: > [...] > > @@ -504,6 +502,18 @@ __rwsem_down_write_failed_common(struct rw_semaphore *sem, int state) > > raw_spin_unlock_irq(&sem->wait_lock); > > > > return ret; > > + > > +out_nolock: > > + __set_current_state(TASK_RUNNING); > > + raw_spin_lock_irq(&sem->wait_lock); > > + list_del(&waiter.list); > > + if (list_empty(&sem->wait_list)) > > + rwsem_atomic_update(-RWSEM_WAITING_BIAS, sem); > > + else > > + __rwsem_do_wake(sem, RWSEM_WAKE_READERS); > > + raw_spin_unlock_irq(&sem->wait_lock); > > + > > + return ERR_PTR(-EINTR); > > } > > Looks much better but don't we have to check the count for potentially > pending writers? Ah, so I was thinking that if we get here, there must still be an owner, otherwise we'd have acquired the lock. And if there is an owner, we cannot go wake writers. Hence the WAKE_READERS thing. Then again, WAKE_ANY would not harm, in that if we do wake a pending writer it will not proceed if it cannot and it'll go back to sleep again. So yeah, maybe WAKE_ANY is the prudent thing to do.