Re: [PATCH 2/6] locking: Introduce range reader/writer lock

From: Peter Zijlstra
Date: Mon May 15 2017 - 09:03:10 EST


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.

While I wait, someone else comes in at [b,m], they too wait.

[a,n] is released, per ordering [b,m] acquires, I still wait.

[a,n] returns to wait.

[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.