linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] percpu-refcount: support synchronous switch to atomic mode.
@ 2017-03-22  1:50 NeilBrown
  2017-03-22 15:00 ` Tejun Heo
  0 siblings, 1 reply; 3+ messages in thread
From: NeilBrown @ 2017-03-22  1:50 UTC (permalink / raw)
  To: Tejun Heo, Christoph Lameter; +Cc: linux-kernel, Shaohua Li, Linux-RAID

[-- Attachment #1: Type: text/plain, Size: 2566 bytes --]


percpu_ref_switch_to_atomic_sync() schedules the switch
to atomic mode, then waits for it to complete.

Also export percpu_ref_switch_to_* so they can be used from modules.

This will be used in md/raid to count the number of pending write
requests to an array.
We occasionally need to check if the count is zero, but most often
we don't care.
We always want updates to the counter to be fast, as in some cases
we count every 4K page.

Signed-off-by: NeilBrown <neilb@suse.com>
---
 include/linux/percpu-refcount.h |  1 +
 lib/percpu-refcount.c           | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/include/linux/percpu-refcount.h b/include/linux/percpu-refcount.h
index 3a481a49546e..c13dceb87b60 100644
--- a/include/linux/percpu-refcount.h
+++ b/include/linux/percpu-refcount.h
@@ -99,6 +99,7 @@ int __must_check percpu_ref_init(struct percpu_ref *ref,
 void percpu_ref_exit(struct percpu_ref *ref);
 void percpu_ref_switch_to_atomic(struct percpu_ref *ref,
 				 percpu_ref_func_t *confirm_switch);
+void percpu_ref_switch_to_atomic_sync(struct percpu_ref *ref);
 void percpu_ref_switch_to_percpu(struct percpu_ref *ref);
 void percpu_ref_kill_and_confirm(struct percpu_ref *ref,
 				 percpu_ref_func_t *confirm_kill);
diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
index 9ac959ef4cae..d133ed43a375 100644
--- a/lib/percpu-refcount.c
+++ b/lib/percpu-refcount.c
@@ -260,6 +260,23 @@ void percpu_ref_switch_to_atomic(struct percpu_ref *ref,
 
 	spin_unlock_irqrestore(&percpu_ref_switch_lock, flags);
 }
+EXPORT_SYMBOL_GPL(percpu_ref_switch_to_atomic);
+
+/**
+ * percpu_ref_switch_to_atomic_sync - switch a percpu_ref to atomic mode
+ * @ref: percpu_ref to switch to atomic mode
+ *
+ * Schedule switching the ref to atomic mode, and wait for the
+ * switch to complete.  Caller must ensure that no other thread
+ * will switch back to percpu mode.
+ *
+ */
+void percpu_ref_switch_to_atomic_sync(struct percpu_ref *ref)
+{
+	percpu_ref_switch_to_atomic(ref, NULL);
+	wait_event(percpu_ref_switch_waitq, !ref->confirm_switch);
+}
+EXPORT_SYMBOL_GPL(percpu_ref_switch_to_atomic_sync);
 
 /**
  * percpu_ref_switch_to_percpu - switch a percpu_ref to percpu mode
@@ -290,6 +307,7 @@ void percpu_ref_switch_to_percpu(struct percpu_ref *ref)
 
 	spin_unlock_irqrestore(&percpu_ref_switch_lock, flags);
 }
+EXPORT_SYMBOL_GPL(percpu_ref_switch_to_percpu);
 
 /**
  * percpu_ref_kill_and_confirm - drop the initial ref and schedule confirmation
-- 
2.12.0


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] percpu-refcount: support synchronous switch to atomic mode.
  2017-03-22  1:50 [PATCH] percpu-refcount: support synchronous switch to atomic mode NeilBrown
@ 2017-03-22 15:00 ` Tejun Heo
  2017-03-23  2:20   ` Shaohua Li
  0 siblings, 1 reply; 3+ messages in thread
From: Tejun Heo @ 2017-03-22 15:00 UTC (permalink / raw)
  To: NeilBrown; +Cc: Christoph Lameter, linux-kernel, Shaohua Li, Linux-RAID

On Wed, Mar 22, 2017 at 12:50:12PM +1100, NeilBrown wrote:
> 
> percpu_ref_switch_to_atomic_sync() schedules the switch
> to atomic mode, then waits for it to complete.
> 
> Also export percpu_ref_switch_to_* so they can be used from modules.
> 
> This will be used in md/raid to count the number of pending write
> requests to an array.
> We occasionally need to check if the count is zero, but most often
> we don't care.
> We always want updates to the counter to be fast, as in some cases
> we count every 4K page.
> 
> Signed-off-by: NeilBrown <neilb@suse.com>

Acked-by: Tejun Heo <tj@kernel.org>

Please feel free to route through other patches through md tree.  If
preferable, I can route it through percpu/for-4.12.

Thanks.

-- 
tejun

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] percpu-refcount: support synchronous switch to atomic mode.
  2017-03-22 15:00 ` Tejun Heo
@ 2017-03-23  2:20   ` Shaohua Li
  0 siblings, 0 replies; 3+ messages in thread
From: Shaohua Li @ 2017-03-23  2:20 UTC (permalink / raw)
  To: Tejun Heo; +Cc: NeilBrown, Christoph Lameter, linux-kernel, Linux-RAID

On Wed, Mar 22, 2017 at 11:00:29AM -0400, Tejun Heo wrote:
> On Wed, Mar 22, 2017 at 12:50:12PM +1100, NeilBrown wrote:
> > 
> > percpu_ref_switch_to_atomic_sync() schedules the switch
> > to atomic mode, then waits for it to complete.
> > 
> > Also export percpu_ref_switch_to_* so they can be used from modules.
> > 
> > This will be used in md/raid to count the number of pending write
> > requests to an array.
> > We occasionally need to check if the count is zero, but most often
> > we don't care.
> > We always want updates to the counter to be fast, as in some cases
> > we count every 4K page.
> > 
> > Signed-off-by: NeilBrown <neilb@suse.com>
> 
> Acked-by: Tejun Heo <tj@kernel.org>
> 
> Please feel free to route through other patches through md tree.  If
> preferable, I can route it through percpu/for-4.12.

Thanks, Tejun. I applied it to md tree, that will avoid a lot of troubles.

Thanks,
Shaohua

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-03-23  2:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-22  1:50 [PATCH] percpu-refcount: support synchronous switch to atomic mode NeilBrown
2017-03-22 15:00 ` Tejun Heo
2017-03-23  2:20   ` Shaohua Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).