From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935586AbbCPRVP (ORCPT ); Mon, 16 Mar 2015 13:21:15 -0400 Received: from casper.infradead.org ([85.118.1.10]:44035 "EHLO casper.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934088AbbCPRVM (ORCPT ); Mon, 16 Mar 2015 13:21:12 -0400 Date: Mon, 16 Mar 2015 18:21:04 +0100 From: Peter Zijlstra To: Mathieu Desnoyers Cc: linux-kernel@vger.kernel.org, KOSAKI Motohiro , Steven Rostedt , "Paul E. McKenney" , Nicholas Miell , Linus Torvalds , Ingo Molnar , Alan Cox , Lai Jiangshan , Stephen Hemminger , Andrew Morton , Josh Triplett , Thomas Gleixner , David Howells , Nick Piggin Subject: Re: [RFC PATCH] sys_membarrier(): system/process-wide memory barrier (x86) (v12) Message-ID: <20150316172104.GH21418@twins.programming.kicks-ass.net> References: <1426447459-28620-1-git-send-email-mathieu.desnoyers@efficios.com> <20150316141939.GE21418@twins.programming.kicks-ass.net> <1203077851.9491.1426520636551.JavaMail.zimbra@efficios.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1203077851.9491.1426520636551.JavaMail.zimbra@efficios.com> 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 Mon, Mar 16, 2015 at 03:43:56PM +0000, Mathieu Desnoyers wrote: > > On which; I absolutely hate that rq->lock thing in there. What is > > 'wrong' with doing a lockless compare there? Other than not actually > > being able to deref rq->curr of course, but we need to fix that anyhow. > > If we can make sure rq->curr deref could be done without holding the rq > lock, then I think all we would need is to ensure that updates to rq->curr > are surrounded by memory barriers. Therefore, we would have the following: > > * When a thread is scheduled out, a memory barrier would be issued before > rq->curr is updated to the next thread task_struct. > > * Before a thread is scheduled in, a memory barrier needs to be issued > after rq->curr is updated to the incoming thread. I'm not entirely awake atm but I'm not seeing why it would need to be that strict; I think the current single MB on task switch is sufficient because if we're in the middle of schedule, userspace isn't actually running. So from the point of userspace the task switch is atomic. Therefore even if we do not get a barrier before setting ->curr, the expedited thing missing us doesn't matter as userspace cannot observe the difference. > In order to be able to dereference rq->curr->mm without holding the > rq->lock, do you envision we should protect task reclaim with RCU-sched ? A recent discussion had Linus suggest SLAB_DESTROY_BY_RCU, although I think Oleg did mention it would still be 'interesting'. I've not yet had time to really think about that.