Skip to contentSkip to conversation

Docs/RCU/rculist_nulls: Minor fixups

PATCH Superseded SeongJae Park 2 participants 7 messages Jun 13, 2023 – Jun 15, 2023

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover Docs/RCU/rculist_nulls: Minor fixups

Changes from v1
(https://lore.kernel.org/rcu/[email protected]/)
- Add Reviewed-by tags from Joel Fernandes for first three patches
- Fix the text for wrong extra _release()

---

Fix minor problems in example code snippets and the text of rculist_nulls.rst file.

SeongJae Park (4):
Docs/RCU/rculist_nulls: Fix trivial coding style Docs/RCU/rculist_nulls: Assign 'obj' before use from the examples Docs/RCU/rculist_nulls: Fix hlist_head field name of 'obj' Docs/RCU/rculist_nulls: Fix wrong text about atomic_set_release()

 Documentation/RCU/rculist_nulls.rst | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH v2 1/4 Docs/RCU/rculist_nulls: Fix trivial coding style

Lookup example of non-hlist_nulls management is missing a semicolon, and having inconsistent indentation (one line is using single space indentation while others are using two spaces indentation). Fix the trivial issues.

---
 Documentation/RCU/rculist_nulls.rst | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
Documentation/RCU/rculist_nulls.rst +3 -3
index 9a734bf54b76..253ecd869fc2 100644
@@ -26,7 +26,7 @@ algorithms:
 ::
 
   begin:
-  rcu_read_lock()
+  rcu_read_lock();
   obj = lockless_lookup(key);
   if (obj) {
     if (!try_get_ref(obj)) // might fail for free objects
@@ -68,8 +68,8 @@ And note the traditional hlist_for_each_entry_rcu() misses this smp_rmb()::
        pos && ({ prefetch(pos->next); 1; }) &&
        ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1; });
        pos = rcu_dereference(pos->next))
-   if (obj->key == key)
-     return obj;
+    if (obj->key == key)
+      return obj;
   return NULL;
 
 Quoting Corey Minyard::
Signature · 1 line
2.25.1
#2 lore raw

PATCH v2 2/4 Docs/RCU/rculist_nulls: Assign 'obj' before use from the examples

In reply to SeongJae Park

Lookup example code snippets in rculist_nulls.rst are using 'obj' without assignment. Fix the code to assign it properly.

---
 Documentation/RCU/rculist_nulls.rst | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Documentation/RCU/rculist_nulls.rst +2 -2
index 253ecd869fc2..94a8bfe9f560 100644
@@ -54,7 +54,7 @@ but a version with an additional memory barrier (smp_rmb())
     struct hlist_node *node, *next;
     for (pos = rcu_dereference((head)->first);
          pos && ({ next = pos->next; smp_rmb(); prefetch(next); 1; }) &&
-         ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1; });
+         ({ obj = hlist_entry(pos, typeof(*obj), member); 1; });
          pos = rcu_dereference(next))
       if (obj->key == key)
         return obj;
@@ -66,7 +66,7 @@ And note the traditional hlist_for_each_entry_rcu() misses this smp_rmb()::
   struct hlist_node *node;
   for (pos = rcu_dereference((head)->first);
        pos && ({ prefetch(pos->next); 1; }) &&
-       ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1; });
+       ({ obj = hlist_entry(pos, typeof(*obj), member); 1; });
        pos = rcu_dereference(pos->next))
     if (obj->key == key)
       return obj;
Signature · 1 line
2.25.1
#6 lore raw

PATCH v2 4/4 Docs/RCU/rculist_nulls: Fix wrong text about atomic_set_release()

In reply to SeongJae Park

The document says we can avoid extra _release() in insert function when hlist_nulls is used, but that's not true[1]. Drop it.

[1] https://lore.kernel.org/rcu/46440869-644a-4982-b790-b71b43976c66@paulmck-laptop/

---
 Documentation/RCU/rculist_nulls.rst | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
Documentation/RCU/rculist_nulls.rst +4 -2
index 5cd6f3f8810f..018cc100d19b 100644
@@ -129,8 +129,7 @@ very very fast (before the end of RCU grace period)
 Avoiding extra smp_rmb()
 ========================
 
-With hlist_nulls we can avoid extra smp_rmb() in lockless_lookup()
-and extra _release() in insert function.
+With hlist_nulls we can avoid extra smp_rmb() in lockless_lookup().
 
 For example, if we choose to store the slot number as the 'nulls'
 end-of-list marker for each slot of the hash table, we can detect
@@ -182,6 +181,9 @@ scan the list again without harm.
 2) Insert algorithm
 -------------------
 
+Same to the above one, but uses hlist_nulls_add_head_rcu() instead of
+hlist_add_head_rcu().
+
 ::
 
   /*
Signature · 1 line
2.25.1
#3 lore raw

PATCH v2 3/4 Docs/RCU/rculist_nulls: Fix hlist_head field name of 'obj'

In reply to SeongJae Park

The example code snippets on rculist_nulls.rst are assuming 'obj' to have the 'hlist_head' field named 'obj_node', but a sentence is wrongly mentioning 'obj->obj_node.next' as 'obj->obj_next'. Fix it.

---
 Documentation/RCU/rculist_nulls.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Documentation/RCU/rculist_nulls.rst +1 -1
index 94a8bfe9f560..5cd6f3f8810f 100644
@@ -86,7 +86,7 @@ Quoting Corey Minyard::
 2) Insertion algorithm
 ----------------------
 
-We need to make sure a reader cannot read the new 'obj->obj_next' value
+We need to make sure a reader cannot read the new 'obj->obj_node.next' value
 and previous value of 'obj->key'. Otherwise, an item could be deleted
 from a chain, and inserted into another chain. If new chain was empty
 before the move, 'next' pointer is NULL, and lockless reader can not
Signature · 1 line
2.25.1
maintainer
#4 lore raw

Re: [PATCH v2 3/4] Docs/RCU/rculist_nulls: Fix hlist_head field name of 'obj'

Quoted 15 lines · SeongJae Park

The example code snippets on rculist_nulls.rst are assuming 'obj' to have the 'hlist_head' field named 'obj_node', but a sentence is wrongly mentioning 'obj->obj_node.next' as 'obj->obj_next'. Fix it.

---
 Documentation/RCU/rculist_nulls.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Documentation/RCU/rculist_nulls.rst +0 -0
index 94a8bfe9f560..5cd6f3f8810f 100644

Documentation/RCU/rculist_nulls.rst Quoting Corey Minyard:: · line 89

Quoted 5 lines
Documentation/RCU/rculist_nulls.rst +1 -1
@@ -86,7 +86,7 @@ Quoting Corey Minyard::
 2) Insertion algorithm
 ----------------------
 
-We need to make sure a reader cannot read the new 'obj->obj_next' value
+We need to make sure a reader cannot read the new 'obj->obj_node.next' value

I do like this being more specific, but if we are going do add this level of specificity, shouldn't we refer to a definition of ->obj_node?

(I queued and pushed 1/4 and 2/4, thank you, and stopped here.)

Thanx, Paul

Quoted 6 lines
Documentation/RCU/rculist_nulls.rst +0 -0
 and previous value of 'obj->key'. Otherwise, an item could be deleted
 from a chain, and inserted into another chain. If new chain was empty
 before the move, 'next' pointer is NULL, and lockless reader can not
Signature · 1 line
2.25.1
#5 lore raw

Re: [PATCH v2 3/4] Docs/RCU/rculist_nulls: Fix hlist_head field name of 'obj'

Quoted 19 lines · On Wed, 14 Jun 2023 09:36:50 -0700 "Paul E. McKenney" <[email protected]>…
Quoted 18 lines · SeongJae Park

The example code snippets on rculist_nulls.rst are assuming 'obj' to have the 'hlist_head' field named 'obj_node', but a sentence is wrongly mentioning 'obj->obj_node.next' as 'obj->obj_next'. Fix it.

---
 Documentation/RCU/rculist_nulls.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Documentation/RCU/rculist_nulls.rst +0 -0
index 94a8bfe9f560..5cd6f3f8810f 100644
@@ -86,7 +86,7 @@ Quoting Corey Minyard::
 2) Insertion algorithm
 ----------------------
 
Quoted 5 lines

Documentation/RCU/rculist_nulls.rst Quoting Corey Minyard:: · line 89

Quoted 2 lines
Documentation/RCU/rculist_nulls.rst +1 -1
-We need to make sure a reader cannot read the new 'obj->obj_next' value
+We need to make sure a reader cannot read the new 'obj->obj_node.next' value

I do like this being more specific, but if we are going do add this level of specificity, shouldn't we refer to a definition of ->obj_node?

Agreed, I will add the example definition in the next spin. I also found we would better to further fix wrong 'member' field assumption, like below:

- ({ obj = hlist_entry(pos, typeof(*obj), member); 1; });
+ ({ obj = hlist_entry(pos, typeof(*obj), obj_node); 1; });

Thanks,
SJ

Quoted 12 lines

(I queued and pushed 1/4 and 2/4, thank you, and stopped here.)

Thanx, Paul

Quoted 6 lines
Documentation/RCU/rculist_nulls.rst +0 -0
 and previous value of 'obj->key'. Otherwise, an item could be deleted
 from a chain, and inserted into another chain. If new chain was empty
 before the move, 'next' pointer is NULL, and lockless reader can not
Signature · 1 line
2.25.1