Skip to contentSkip to conversation

percpu_ref: Fix comment regarding percpu_ref_init flags

PATCH RESEND In review [email protected] 3 participants 5 messages Feb 21, 2020 – Mar 5, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 percpu_ref: Fix comment regarding percpu_ref_init flags

From: Ira Weiny <[email protected]>

The comment for percpu_ref_init() implies that using PERCPU_REF_ALLOW_REINIT will cause the refcount to start at 0. But this is not true. PERCPU_REF_ALLOW_REINIT starts the count at 1 as if the flags were zero. Add this fact to the kernel doc comment.

---
RESEND:

	Add more people on the CC list to see if I'm wrong here.
	https://lore.kernel.org/lkml/[email protected]/

---

 lib/percpu-refcount.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
lib/percpu-refcount.c +3 -3
index 4f6c6ebbbbde..48d7fcff70b6 100644
@@ -50,9 +50,9 @@ static unsigned long __percpu *percpu_count_ptr(struct percpu_ref *ref)
  * @flags: PERCPU_REF_INIT_* flags
  * @gfp: allocation mask to use
  *
- * Initializes @ref.  If @flags is zero, @ref starts in percpu mode with a
- * refcount of 1; analagous to atomic_long_set(ref, 1).  See the
- * definitions of PERCPU_REF_INIT_* flags for flag behaviors.
+ * Initializes @ref.  If @flags is zero or PERCPU_REF_ALLOW_REINIT, @ref starts
+ * in percpu mode with a refcount of 1; analagous to atomic_long_set(ref, 1).
+ * See the definitions of PERCPU_REF_INIT_* flags for flag behaviors.
  *
  * Note that @release must not sleep - it may potentially be called from RCU
  * callback context by percpu_ref_kill().
Signature · 1 line
2.21.0
maintainer
#1 lore raw

Hi Ira,

Quoted 22 lines · On Fri, Feb 21, 2020 at 03:16:07PM -0800, [email protected] wrote:

From: Ira Weiny <[email protected]>

The comment for percpu_ref_init() implies that using PERCPU_REF_ALLOW_REINIT will cause the refcount to start at 0. But this is not true. PERCPU_REF_ALLOW_REINIT starts the count at 1 as if the flags were zero. Add this fact to the kernel doc comment.

---
RESEND:

	Add more people on the CC list to see if I'm wrong here.
	https://lore.kernel.org/lkml/[email protected]/

---

 lib/percpu-refcount.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
lib/percpu-refcount.c +0 -0
index 4f6c6ebbbbde..48d7fcff70b6 100644

lib/percpu-refcount.c static unsigned long __percpu *percpu_count_ptr(struct percpu_ref *ref) · line 55

Quoted 9 lines
lib/percpu-refcount.c +3 -3
@@ -50,9 +50,9 @@ static unsigned long __percpu *percpu_count_ptr(struct percpu_ref *ref)
  * @flags: PERCPU_REF_INIT_* flags
  * @gfp: allocation mask to use
  *
- * Initializes @ref.  If @flags is zero, @ref starts in percpu mode with a
- * refcount of 1; analagous to atomic_long_set(ref, 1).  See the
- * definitions of PERCPU_REF_INIT_* flags for flag behaviors.
+ * Initializes @ref.  If @flags is zero or PERCPU_REF_ALLOW_REINIT, @ref starts
+ * in percpu mode with a refcount of 1; analagous to atomic_long_set(ref, 1).
+ * See the definitions of PERCPU_REF_INIT_* flags for flag behaviors.

Yeah. Prior we had both PERCPU_REF_INIT_ATOMIC and PERCPU_REF_INIT_DEAD with the latter implying the former. So 0 meant percpu and the others meant atomic. With PERCPU_REF_ALLOW_REINIT, it's probably easier to understand by saying if neither PERCPU_REF_INIT_ATOMIC or PERCPU_REF_INIT_DEAD is set, it starts out in percpu mode which is mentioned in the comments where the flags are defined. It's not great having implied flags, but it's worked so far.

Also, it's not quite analagous to atomic_long_set(ref, 1) as there is a bias to prevent prematurely hitting 0.

I can take this and massage the wording a bit.

Quoted 6 lines
lib/percpu-refcount.c +0 -0
  *
  * Note that @release must not sleep - it may potentially be called from RCU
  * callback context by percpu_ref_kill().
Signature · 1 line
2.21.0

Thanks,
Dennis

#2 lore raw
Quoted 43 lines · Dennis Zhou

Hi Ira,

Quoted 22 lines · On Fri, Feb 21, 2020 at 03:16:07PM -0800, [email protected] wrote:

From: Ira Weiny <[email protected]>

The comment for percpu_ref_init() implies that using PERCPU_REF_ALLOW_REINIT will cause the refcount to start at 0. But this is not true. PERCPU_REF_ALLOW_REINIT starts the count at 1 as if the flags were zero. Add this fact to the kernel doc comment.

---
RESEND:

	Add more people on the CC list to see if I'm wrong here.
	https://lore.kernel.org/lkml/[email protected]/

---

 lib/percpu-refcount.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
lib/percpu-refcount.c +0 -0
index 4f6c6ebbbbde..48d7fcff70b6 100644

lib/percpu-refcount.c static unsigned long __percpu *percpu_count_ptr(struct percpu_ref *ref) · line 55

Quoted 9 lines
lib/percpu-refcount.c +3 -3
@@ -50,9 +50,9 @@ static unsigned long __percpu *percpu_count_ptr(struct percpu_ref *ref)
  * @flags: PERCPU_REF_INIT_* flags
  * @gfp: allocation mask to use
  *
- * Initializes @ref.  If @flags is zero, @ref starts in percpu mode with a
- * refcount of 1; analagous to atomic_long_set(ref, 1).  See the
- * definitions of PERCPU_REF_INIT_* flags for flag behaviors.
+ * Initializes @ref.  If @flags is zero or PERCPU_REF_ALLOW_REINIT, @ref starts
+ * in percpu mode with a refcount of 1; analagous to atomic_long_set(ref, 1).
+ * See the definitions of PERCPU_REF_INIT_* flags for flag behaviors.

Yeah. Prior we had both PERCPU_REF_INIT_ATOMIC and PERCPU_REF_INIT_DEAD with the latter implying the former. So 0 meant percpu and the others meant atomic. With PERCPU_REF_ALLOW_REINIT, it's probably easier to understand by saying if neither PERCPU_REF_INIT_ATOMIC or PERCPU_REF_INIT_DEAD is set, it starts out in percpu mode which is mentioned in the comments where the flags are defined. It's not great having implied flags, but it's worked so far.

Quoted 4 lines

Also, it's not quite analagous to atomic_long_set(ref, 1) as there is a bias to prevent prematurely hitting 0.

I can take this and massage the wording a bit.

Hello Ira! Hello Dennis!

Yeah, I'd simple say that it starts in the percpu mode, except the case when PERCPU_REF_INIT_ATOMIC is set, then (atomic mode, 1) and PERCPU_REF_INIT_DEAD is set, then (atomic mode, 0).

PERCPU_REF_ALLOW_REINIT actually doesn't affect the initial state.

Thanks!

author
#3 lore raw

[snip]

Quoted 28 lines
Quoted 23 lines
Quoted 5 lines
lib/percpu-refcount.c +0 -0
index 4f6c6ebbbbde..48d7fcff70b6 100644

lib/percpu-refcount.c static unsigned long __percpu *percpu_count_ptr(struct percpu_ref *ref) · line 55

Quoted 9 lines
lib/percpu-refcount.c +3 -3
@@ -50,9 +50,9 @@ static unsigned long __percpu *percpu_count_ptr(struct percpu_ref *ref)
  * @flags: PERCPU_REF_INIT_* flags
  * @gfp: allocation mask to use
  *
- * Initializes @ref.  If @flags is zero, @ref starts in percpu mode with a
- * refcount of 1; analagous to atomic_long_set(ref, 1).  See the
- * definitions of PERCPU_REF_INIT_* flags for flag behaviors.
+ * Initializes @ref.  If @flags is zero or PERCPU_REF_ALLOW_REINIT, @ref starts
+ * in percpu mode with a refcount of 1; analagous to atomic_long_set(ref, 1).
+ * See the definitions of PERCPU_REF_INIT_* flags for flag behaviors.

Yeah. Prior we had both PERCPU_REF_INIT_ATOMIC and PERCPU_REF_INIT_DEAD with the latter implying the former. So 0 meant percpu and the others meant atomic. With PERCPU_REF_ALLOW_REINIT, it's probably easier to understand by saying if neither PERCPU_REF_INIT_ATOMIC or PERCPU_REF_INIT_DEAD is set, it starts out in percpu mode which is mentioned in the comments where the flags are defined. It's not great having implied flags, but it's worked so far.

Quoted 4 lines

Also, it's not quite analagous to atomic_long_set(ref, 1) as there is a bias to prevent prematurely hitting 0.

I can take this and massage the wording a bit.

Quoted 8 lines

Hello Ira! Hello Dennis!

Yeah, I'd simple say that it starts in the percpu mode, except the case when PERCPU_REF_INIT_ATOMIC is set, then (atomic mode, 1) and PERCPU_REF_INIT_DEAD is set, then (atomic mode, 0).

PERCPU_REF_ALLOW_REINIT actually doesn't affect the initial state.

Thanks for the clarification. Dennis let me know if you want me to resubmit the patch.

Thanks!
Ira

maintainer
#4 lore raw
Quoted 37 lines · Ira Weiny

[snip]

Quoted 34 lines
Quoted 23 lines
Quoted 5 lines
lib/percpu-refcount.c +0 -0
index 4f6c6ebbbbde..48d7fcff70b6 100644

lib/percpu-refcount.c static unsigned long __percpu *percpu_count_ptr(struct percpu_ref *ref) · line 55

Quoted 9 lines
lib/percpu-refcount.c +3 -3
@@ -50,9 +50,9 @@ static unsigned long __percpu *percpu_count_ptr(struct percpu_ref *ref)
  * @flags: PERCPU_REF_INIT_* flags
  * @gfp: allocation mask to use
  *
- * Initializes @ref.  If @flags is zero, @ref starts in percpu mode with a
- * refcount of 1; analagous to atomic_long_set(ref, 1).  See the
- * definitions of PERCPU_REF_INIT_* flags for flag behaviors.
+ * Initializes @ref.  If @flags is zero or PERCPU_REF_ALLOW_REINIT, @ref starts
+ * in percpu mode with a refcount of 1; analagous to atomic_long_set(ref, 1).
+ * See the definitions of PERCPU_REF_INIT_* flags for flag behaviors.

Yeah. Prior we had both PERCPU_REF_INIT_ATOMIC and PERCPU_REF_INIT_DEAD with the latter implying the former. So 0 meant percpu and the others meant atomic. With PERCPU_REF_ALLOW_REINIT, it's probably easier to understand by saying if neither PERCPU_REF_INIT_ATOMIC or PERCPU_REF_INIT_DEAD is set, it starts out in percpu mode which is mentioned in the comments where the flags are defined. It's not great having implied flags, but it's worked so far.

Quoted 4 lines

Also, it's not quite analagous to atomic_long_set(ref, 1) as there is a bias to prevent prematurely hitting 0.

I can take this and massage the wording a bit.

Hello Ira! Hello Dennis!

Yeah, I'd simple say that it starts in the percpu mode, except the case when PERCPU_REF_INIT_ATOMIC is set, then (atomic mode, 1) and PERCPU_REF_INIT_DEAD is set, then (atomic mode, 0).

Quoted 9 lines
Quoted 2 lines

PERCPU_REF_ALLOW_REINIT actually doesn't affect the initial state.

Thanks for the clarification. Dennis let me know if you want me to resubmit the patch.

Thanks!
Ira

Sorry for the delay. I've applied it to for-5.7.

Thanks,
Dennis