From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f195.google.com ([209.85.128.195]:44095 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750841AbeERJk4 (ORCPT ); Fri, 18 May 2018 05:40:56 -0400 Date: Fri, 18 May 2018 11:40:52 +0200 From: Ingo Molnar To: Oleg Nesterov Cc: Matthew Wilcox , Waiman Long , Ingo Molnar , Peter Zijlstra , Thomas Gleixner , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Davidlohr Bueso , "Theodore Y. Ts'o" , Amir Goldstein , Jan Kara Subject: Re: [PATCH v4 1/2] locking/rwsem: Add a new RWSEM_ANONYMOUSLY_OWNED flag Message-ID: <20180518094052.GA26150@gmail.com> References: <1526420991-21213-1-git-send-email-longman@redhat.com> <1526420991-21213-2-git-send-email-longman@redhat.com> <20180516121947.GE20670@bombadil.infradead.org> <20180518070258.GA20971@gmail.com> <20180518084122.GA14307@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180518084122.GA14307@redhat.com> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: * Oleg Nesterov wrote: > On 05/18, Ingo Molnar wrote: > > > > > > * Matthew Wilcox wrote: > > > > > This is confusingly written. I think you mean ... > > > > > > if (!owner) > > > goto done; > > > if (!is_rwsem_owner_spinnable(owner)) { > > > ret = false; > > > goto done; > > > } > > > > Yes, that's cleaner. Waiman, mind sending a followup patch that cleans this up? > > Or simply > > static inline bool owner_on_cpu(struct task_struct *owner) > { > return owner->on_cpu && !vcpu_is_preempted(task_cpu(owner)); > } > > static inline bool rwsem_can_spin_on_owner(struct rw_semaphore *sem) > { > struct task_struct *owner; > bool ret = true; > > if (need_resched()) > return false; > > rcu_read_lock(); > owner = READ_ONCE(sem->owner); > if (owner) { > ret = is_rwsem_owner_spinnable(owner) && > owner_on_cpu(owner); > } > rcu_read_unlock(); > return ret; > } > > note that rwsem_spin_on_owner() can use the new owner_on_cpu() helper too, > > if (need_resched() || !owner_on_cpu(owner)) { > rcu_read_unlock(); > return false; > } > > looks a bit better than the current code: > > if (!owner->on_cpu || need_resched() || > vcpu_is_preempted(task_cpu(owner))) { > rcu_read_unlock(); > return false; > } > > Oleg. That looks good to me too - mind sending a patch on top of latest -tip? Thanks, Ingo