From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756170AbbDIVHW (ORCPT ); Thu, 9 Apr 2015 17:07:22 -0400 Received: from e33.co.us.ibm.com ([32.97.110.151]:36267 "EHLO e33.co.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754151AbbDIVHT (ORCPT ); Thu, 9 Apr 2015 17:07:19 -0400 Date: Thu, 9 Apr 2015 14:07:11 -0700 From: "Paul E. McKenney" To: Jason Low Cc: Linus Torvalds , Ingo Molnar , Peter Zijlstra , Davidlohr Bueso , Tim Chen , Aswin Chandramouleeswaran , LKML Subject: Re: [PATCH 2/2] locking/rwsem: Use a return variable in rwsem_spin_on_owner() Message-ID: <20150409210711.GQ6464@linux.vnet.ibm.com> Reply-To: paulmck@linux.vnet.ibm.com References: <20150409053725.GB13871@gmail.com> <1428561611.3506.78.camel@j-VirtualBox> <20150409075311.GA4645@gmail.com> <20150409175652.GI6464@linux.vnet.ibm.com> <1428608618.12911.9.camel@j-VirtualBox> <20150409195849.GN6464@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15040921-0009-0000-0000-000009FD5E69 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 09, 2015 at 01:58:16PM -0700, Jason Low wrote: > On Thu, Apr 9, 2015 at 12:58 PM, Paul E. McKenney > wrote: > > On Thu, Apr 09, 2015 at 12:43:38PM -0700, Jason Low wrote: > >> On Thu, 2015-04-09 at 11:16 -0700, Linus Torvalds wrote: > >> > On Thu, Apr 9, 2015 at 11:08 AM, Linus Torvalds > >> > wrote: > >> > > > >> > > The pointer is a known-safe kernel pointer - it's just that it was > >> > > "known safe" a few instructions ago, and might be rcu-free'd at any > >> > > time. > >> > > >> > Actually, we could even do something like this: > >> > > >> > static inline int sem_owner_on_cpu(struct semaphore *sem, struct > >> > task_struct *owner) > >> > { > >> > int on_cpu; > >> > > >> > #ifdef CONFIG_DEBUG_PAGEALLOC > >> > rcu_read_lock(); > >> > #endif > >> > on_cpu = sem->owner == owner && owner->on_cpu; > >> > #ifdef CONFIG_DEBUG_PAGEALLOC > >> > rcu_read_unlock(); > >> > #endif > >> > return on_cpu; > >> > } > >> > > >> > because we really don't need to hold the RCU lock over the whole loop, > >> > we just need to validate that the semaphore owner still matches, and > >> > if so, check that it's on_cpu. > >> > > >> > And if CONFIG_DEBUG_PAGEALLOC is set, we don't care about performance > >> > *at*all*. We will have worse performance problems than doing some RCU > >> > read-locking inside the loop. > >> > > >> > And if CONFIG_DEBUG_PAGEALLOC isn't set, we don't really care about > >> > locking, since at worst we just access stale memory for one iteration. > >> > > >> > Hmm. It's not pretty, but neither is the current "let's just take a > >> > rcu lock that we don't really need over a loop that doesn't have very > >> > strict bounding". > >> > > >> > Comments? > >> > >> So that looks more similar to how the original code was where the > >> rcu_read_lock() and rcu_read_unlock() was done inside the owner_running > >> helper function (though without the CONFIG_DEBUG_PAGEALLOC), before > >> commit 307bf9803f25 ("sched: Simplify mutex_spin_on_owner()") modified > >> it to be done outside the loop. > > > > Another approach would be to post a timer before entering the spinloop, > > and have the timer handler set the resched bit. Then the loop would > > be bounded, safe, and would run at full speed. > > Though posting a timer, ect... would also add more overhead right? It would. Not on each pass through the loop, though. But yes, might be too much overhead. Thanx, Paul