Re: [PATCH 22/27] locking/lockdep: Reuse list entries that are no longer in use

From: Bart Van Assche
Date: Tue Dec 04 2018 - 11:08:27 EST


On Tue, 2018-12-04 at 09:14 +-0100, Peter Zijlstra wrote:
+AD4 On Mon, Dec 03, 2018 at 10:16:59AM -0800, Bart Van Assche wrote:
+AD4 +AD4 On Mon, 2018-12-03 at 18:32 +-0100, Peter Zijlstra wrote:
+AD4 +AD4 +AD4 On Mon, Dec 03, 2018 at 08:40:48AM -0800, Bart Van Assche wrote:
+AD4 +AD4 +AD4 +AD4 How about the following alternative which requires only two bitmaps instead
+AD4 +AD4 +AD4 +AD4 of three:
+AD4 +AD4 +AD4 +AD4 - Maintain two bitmaps, one for the free entries and one for the entries
+AD4 +AD4 +AD4 +AD4 that are being freed.
+AD4 +AD4 +AD4 +AD4 - Protect all accesses to both bitmaps with the graph lock.
+AD4 +AD4 +AD4 +AD4 - zap+AF8-class() sets a bit in the +ACI-being freed+ACI bitmap for the entries that
+AD4 +AD4 +AD4 +AD4 should be freed after a GP.
+AD4 +AD4 +AD4 +AD4 - Instead of making free+AF8-zapped+AF8-classes() wait for a grace period by calling
+AD4 +AD4 +AD4 +AD4 synchronize+AF8-sched(), use call+AF8-rcu() and do the freeing work from inside the
+AD4 +AD4 +AD4 +AD4 RCU callback.
+AD4 +AD4 +AD4 +AD4 - From inside the RCU callback, set a bit in the +ACI-free+ACI bitmap for all entries
+AD4 +AD4 +AD4 +AD4 that have a bit set in the +ACI-being freed+ACI bitmap and clears the +ACI-being freed+ACI
+AD4 +AD4 +AD4 +AD4 bitmap.
+AD4 +AD4 +AD4
+AD4 +AD4 +AD4 What happens when another unreg happens while the rcu+AF8-call thing is
+AD4 +AD4 +AD4 still pending?
+AD4 +AD4
+AD4 +AD4 A new flag will have to keep track of whether or not an RCU callback has
+AD4 +AD4 already been scheduled via rcu+AF8-call() but not yet executed to avoid double
+AD4 +AD4 RCU call complaints.
+AD4
+AD4 That's not the only problem there. You either then have to synchronously
+AD4 wait for that flag / rcu+AF8-call to complete, or, if you modify the bitmap,
+AD4 ensure it re-queues itself for another GP before committing, which is
+AD4 starvation prone.

Can you have a look at free+AF8-zapped+AF8-classes() and schedule+AF8-free+AF8-zapped+AF8-classes()
in v2 of this patch series? In v2 the call+AF8-rcu(), manipulation of the boolean
and processing of the bitmaps are all protected by the graph
lock to avoid the issues that you described. See also
+ACo +AFs-PATCH v2 17/24+AF0 locking/lockdep: Free lock classes that are no longer in use
(https://lore.kernel.org/lkml/20181204002833.55452-18-bvanassche+AEA-acm.org/).
+ACo +AFs-PATCH v2 18/24+AF0 locking/lockdep: Reuse list entries that are no longer in use
(https://lore.kernel.org/lkml/20181204002833.55452-19-bvanassche+AEA-acm.org/).

Thanks,

Bart.