Skip to contentSkip to conversation

percpu-refcount: consistently use plain (non-sched) RCU

PATCH Applied Tejun Heo 3 participants 3 messages Jun 12, 2013 – Jun 13, 2013 Per-CPU memory allocator

lore
Share & tools
lore

Tejun Heo

author
#0 lore raw

PATCH 1/1 percpu-refcount: consistently use plain (non-sched) RCU

Quoted 1 line

From e96262150a513ce3d54ff221d4ace8aeec96e0bf Mon Sep 17 00:00:00 2001

From: Tejun Heo <[email protected]>
Date: Wed, 12 Jun 2013 13:37:42 -0700

percpu_ref_get/put() are using preempt_disable/enable() while percpu_ref_kill() is using plain call_rcu() instead of call_rcu_sched(). This is buggy as grace periods of the two may not match. Fix it by using plain RCU in percpu_ref_get/put().

(I suggested using sched RCU in the first place but there's no actual
benefit in doing so unless we're gonna introduce different variants of get/put to be called while preemption is alredy disabled, which we definitely shouldn't.)

---
 include/linux/percpu-refcount.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
include/linux/percpu-refcount.h +4 -4
index 24b31ef..abe1411 100644
@@ -85,7 +85,7 @@ static inline void percpu_ref_get(struct percpu_ref *ref)
 {
 	unsigned __percpu *pcpu_count;
 
-	preempt_disable();
+	rcu_read_lock();
 
 	pcpu_count = ACCESS_ONCE(ref->pcpu_count);
 
@@ -94,7 +94,7 @@ static inline void percpu_ref_get(struct percpu_ref *ref)
 	else
 		atomic_inc(&ref->count);
 
-	preempt_enable();
+	rcu_read_unlock();
 }
 
 /**
@@ -107,7 +107,7 @@ static inline void percpu_ref_put(struct percpu_ref *ref)
 {
 	unsigned __percpu *pcpu_count;
 
-	preempt_disable();
+	rcu_read_lock();
 
 	pcpu_count = ACCESS_ONCE(ref->pcpu_count);
 
@@ -116,7 +116,7 @@ static inline void percpu_ref_put(struct percpu_ref *ref)
 	else if (unlikely(atomic_dec_and_test(&ref->count)))
 		ref->release(ref);
 
-	preempt_enable();
+	rcu_read_unlock();
 }
 
 #endif
Signature · 1 line
1.8.2.1
Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · Tejun Heo

From e96262150a513ce3d54ff221d4ace8aeec96e0bf Mon Sep 17 00:00:00 2001
From: Tejun Heo <[email protected]>
Date: Wed, 12 Jun 2013 13:37:42 -0700

percpu_ref_get/put() are using preempt_disable/enable() while percpu_ref_kill() is using plain call_rcu() instead of call_rcu_sched(). This is buggy as grace periods of the two may not match. Fix it by using plain RCU in percpu_ref_get/put().

Quoted 7 lines

(I suggested using sched RCU in the first place but there's no actual
benefit in doing so unless we're gonna introduce different variants of get/put to be called while preemption is alredy disabled, which we definitely shouldn't.)

maintainer Applied
#2 lore raw
In reply to Tejun Heo
Quoted 9 lines · Tejun Heo

From e96262150a513ce3d54ff221d4ace8aeec96e0bf Mon Sep 17 00:00:00 2001
From: Tejun Heo <[email protected]>
Date: Wed, 12 Jun 2013 13:37:42 -0700

percpu_ref_get/put() are using preempt_disable/enable() while percpu_ref_kill() is using plain call_rcu() instead of call_rcu_sched(). This is buggy as grace periods of the two may not match. Fix it by using plain RCU in percpu_ref_get/put().

Quoted 7 lines

(I suggested using sched RCU in the first place but there's no actual
benefit in doing so unless we're gonna introduce different variants of get/put to be called while preemption is alredy disabled, which we definitely shouldn't.)

Applied to percpu/for-3.11.

Thanks.

Signature · 1 line
tejun