From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753505AbdEPWTT (ORCPT ); Tue, 16 May 2017 18:19:19 -0400 Received: from mx2.suse.de ([195.135.220.15]:60168 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751680AbdEPWTR (ORCPT ); Tue, 16 May 2017 18:19:17 -0400 Date: Tue, 16 May 2017 15:19:03 -0700 From: Davidlohr Bueso To: Peter Zijlstra Cc: mingo@kernel.org, akpm@linux-foundation.org, jack@suse.cz, kirill.shutemov@linux.intel.com, ldufour@linux.vnet.ibm.com, mhocko@suse.com, mgorman@techsingularity.net, linux-kernel@vger.kernel.org, Davidlohr Bueso Subject: Re: [PATCH 2/6] locking: Introduce range reader/writer lock Message-ID: <20170516221903.GE2966@linux-80c1.suse> References: <20170515090725.27055-1-dave@stgolabs.net> <20170515090725.27055-3-dave@stgolabs.net> <20170515130257.n4q72dodbd3x4fvm@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20170515130257.n4q72dodbd3x4fvm@hirez.programming.kicks-ass.net> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 15 May 2017, Peter Zijlstra wrote: >On Mon, May 15, 2017 at 02:07:21AM -0700, Davidlohr Bueso wrote: > >> + * Fairness and freedom of starvation are guaranteed by the lack of lock >> + * stealing, thus range locks depend directly on interval tree semantics. >> + * This is particularly for iterations, where the key for the rbtree is >> + * given by the interval's low endpoint, > > >So suppose the lock is held at [a,n], and I want to acquire [g,z], this >conflicts, therefore I wait. Ok, then, ref [g,z] = 1, ref [a,n] = 0 (lock owner). Per below, at this point the tree will overlap with anything between [a,z], which is the world. > >While I wait, someone else comes in at [b,m], they too wait. [b,m] intersects with both nodes above, thus ref [b,m] = 2. > >[a,n] is released, per ordering [b,m] acquires, I still wait. Now: ref [g,z] = 0 ref [b,m] = 1 So due to reference counting [g,z] is acquired, despite [b,m] being _put() before [g,z]. >[a,n] returns to wait. Similar to the [b,m] case, when [a,n] comes back, it too will get a ref = 2 and hence "go back in line". Iow, lock order does depend on have fifo semantics among contended ranges. > >[b,m] releases, does the iteration then restart and grant it to [a,n] or >will I (at [g,z]) finally acquire? > > >Since the code always does range_interval_tree_foreach() it would appear >to me [b,m] will always win and [g,z] could be made to wait >indefinitely (by always contending with another range that has a lower >starting point). > > > >> and duplicates are walked as it >> + * would an inorder traversal of the tree. > >Are duplicates ordered in FIFO ? Afaict the above is free of actual >semantics. This will strictly depend on the rotation when you have duplicates when more nodes are added later. But again that's the order of walking the tree. Thanks, Davidlohr