Thread (90 messages) flat view 90 messages, 12 authors, 2021-06-20

Re: [RFC][PATCH] sched: Use lightweight hazard pointers to grab lazy mms

From: "Andy Lutomirski" <luto@kernel.org>
Date: 2021-06-17 14:07:03
Also in: lkml


On Thu, Jun 17, 2021, at 2:13 AM, Peter Zijlstra wrote:
On Thu, Jun 17, 2021 at 11:08:03AM +0200, Peter Zijlstra wrote:
quoted
+static void mmdrop_lazy(struct rq *rq)
+{
+	struct mm_struct *old_mm;
+
+	if (likely(!READ_ONCE(rq->drop_mm)))
+		return;
+
+	/*
+	 * Slow path.  This only happens when we recently stopped using
+	 * an mm that is exiting.
+	 */
+	old_mm = xchg(&rq->drop_mm, NULL);
+	if (old_mm)
+		mmdrop(old_mm);
+}
AFAICT if we observe a !NULL value on the load, the xchg() *MUST* also
see !NULL (although it might see a different !NULL value). So do we want
to write it something like so instead?
Like so?
static void mmdrop_lazy(struct rq *rq)
{
	struct mm_struct *old_mm;

	if (likely(!READ_ONCE(rq->drop_mm)))
		return;

	/*
	 * Slow path.  This only happens when we recently stopped using
	 * an mm that is exiting.
* This xchg is the only thing that can change rq->drop_mm from non-NULL to NULL, and
* multiple mmdrop_lazy() calls can't run concurrently on the same CPU.
	 */
	old_mm = xchg(&rq->drop_mm, NULL);
	if (WARN_ON_ONCE(!old_mm))
		return;

	mmdrop(old_mm);
}
--Andy
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help