Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1731990 > unrolled thread

[PATCH] mm,compaction: serialize waitqueue_active() checks (for real)

Started byDavidlohr Bueso <dave@stgolabs.net>
First post2017-09-14 02:10 +0200
Last post2017-09-14 20:00 +0200
Articles 2 — 1 participant

Back to article view | Back to linux.kernel


Contents

  [PATCH] mm,compaction: serialize waitqueue_active() checks (for real) Davidlohr Bueso <dave@stgolabs.net> - 2017-09-14 02:10 +0200
    Re: [PATCH] mm,compaction: serialize waitqueue_active() checks (for  real) Davidlohr Bueso <dave@stgolabs.net> - 2017-09-14 20:00 +0200

#1731990 — [PATCH] mm,compaction: serialize waitqueue_active() checks (for real)

FromDavidlohr Bueso <dave@stgolabs.net>
Date2017-09-14 02:10 +0200
Subject[PATCH] mm,compaction: serialize waitqueue_active() checks (for real)
Message-ID<uppTc-5UG-5@gated-at.bofh.it>
Andrea brought to my attention that the L->{L,S} guarantees
are completely bogus for this case. I was looking at the diagram,
from the offending commit, when that _is_ the race, we had the
load reordered already.

What we need is at least S->L semantics, thus simply use
wq_has_sleeper() to serialize the call for good.

Fixes: 46acef048a6 (mm,compaction: serialize waitqueue_active() checks)
Reported-by: Andrea Parri <parri.andrea@gmail.com>
Signed-off-by: Davidlohr Bueso <dbueso@suse.de>
---
 mm/compaction.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/mm/compaction.c b/mm/compaction.c
index fb548e4c7bd4..d1ad2cf6c758 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -1999,17 +1999,16 @@ void wakeup_kcompactd(pg_data_t *pgdat, int order, int classzone_idx)
 	if (pgdat->kcompactd_max_order < order)
 		pgdat->kcompactd_max_order = order;
 
-	/*
-	 * Pairs with implicit barrier in wait_event_freezable()
-	 * such that wakeups are not missed in the lockless
-	 * waitqueue_active() call.
-	 */
 	smp_acquire__after_ctrl_dep();
 
 	if (pgdat->kcompactd_classzone_idx > classzone_idx)
 		pgdat->kcompactd_classzone_idx = classzone_idx;
 
-	if (!waitqueue_active(&pgdat->kcompactd_wait))
+	/*
+	 * Pairs with implicit barrier in wait_event_freezable()
+	 * such that wakeups are not missed.
+	 */
+	if (!wq_has_sleeper(&pgdat->kcompactd_wait))
 		return;
 
 	if (!kcompactd_node_suitable(pgdat))
-- 
2.12.0

[toc] | [next] | [standalone]


#1732487 — Re: [PATCH] mm,compaction: serialize waitqueue_active() checks (for real)

FromDavidlohr Bueso <dave@stgolabs.net>
Date2017-09-14 20:00 +0200
SubjectRe: [PATCH] mm,compaction: serialize waitqueue_active() checks (for real)
Message-ID<upGAF-88i-1@gated-at.bofh.it>
In reply to#1731990
On Wed, 13 Sep 2017, Davidlohr Bueso wrote:

>-	/*
>-	 * Pairs with implicit barrier in wait_event_freezable()
>-	 * such that wakeups are not missed in the lockless
>-	 * waitqueue_active() call.
>-	 */
> 	smp_acquire__after_ctrl_dep();

sorry, forgot to delete this. Here's v2.

-----8<-----------------------------------------------------
[PATCH v2] mm,compaction: serialize waitqueue_active() checks (for real)

Andrea brought to my attention that the L->{L,S} guarantees
are completely bogus for this case. I was looking at the diagram,
from the offending commit, when that _is_ the race, we had the
load reordered already.

What we need is at least S->L semantics, thus simply use
wq_has_sleeper() to serialize the call for good.

Fixes: 46acef048a6 (mm,compaction: serialize waitqueue_active() checks)
Reported-by: Andrea Parri <parri.andrea@gmail.com>
Signed-off-by: Davidlohr Bueso <dbueso@suse.de>
---
 mm/compaction.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/mm/compaction.c b/mm/compaction.c
index fb548e4c7bd4..03d31a875341 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -1999,17 +1999,14 @@ void wakeup_kcompactd(pg_data_t *pgdat, int order, int classzone_idx)
 	if (pgdat->kcompactd_max_order < order)
 		pgdat->kcompactd_max_order = order;
 
-	/*
-	 * Pairs with implicit barrier in wait_event_freezable()
-	 * such that wakeups are not missed in the lockless
-	 * waitqueue_active() call.
-	 */
-	smp_acquire__after_ctrl_dep();
-
 	if (pgdat->kcompactd_classzone_idx > classzone_idx)
 		pgdat->kcompactd_classzone_idx = classzone_idx;
 
-	if (!waitqueue_active(&pgdat->kcompactd_wait))
+	/*
+	 * Pairs with implicit barrier in wait_event_freezable()
+	 * such that wakeups are not missed.
+	 */
+	if (!wq_has_sleeper(&pgdat->kcompactd_wait))
 		return;
 
 	if (!kcompactd_node_suitable(pgdat))
-- 
2.12.0

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web