public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] Remove unused list_for_each_safe_rcu() API
@ 2005-10-29  2:59 Paul E. McKenney
  2005-10-29  3:07 ` [PATCH 2/2] Remove hlist_for_each_rcu() API, convert existing use to hlist_for_each_entry_rcu Paul E. McKenney
  0 siblings, 1 reply; 2+ messages in thread
From: Paul E. McKenney @ 2005-10-29  2:59 UTC (permalink / raw)
  To: linux-kernel; +Cc: akpm, dipankar, manfred, paulmck

Hello!

This patch removes the unused list_for_each_safe_rcu() API.  Any out-of-tree
uses of this interface can instead use list_for_each_rcu(), as noted in
the documentation updates.  Builds, passes kernbench and LTP.

Signed-off-by: <paulmck@us.ibm.com>

---

 Documentation/RCU/checklist.txt |    8 ++++----
 Documentation/RCU/whatisRCU.txt |   23 ++++++++++++++++++++++-
 include/linux/list.h            |   16 ----------------
 3 files changed, 26 insertions(+), 21 deletions(-)

diff -urpNa -X dontdiff linux-2.6.14/Documentation/RCU/checklist.txt linux-2.6.14-RCUdoc/Documentation/RCU/checklist.txt
--- linux-2.6.14/Documentation/RCU/checklist.txt	2005-10-27 17:02:08.000000000 -0700
+++ linux-2.6.14-RCUdoc/Documentation/RCU/checklist.txt	2005-10-28 14:08:56.000000000 -0700
@@ -149,10 +149,10 @@ over a rather long period of time, but i
 	should be used in preference to call_rcu().
 
 9.	All RCU list-traversal primitives, which include
-	list_for_each_rcu(), list_for_each_entry_rcu(),
-	list_for_each_continue_rcu(), and list_for_each_safe_rcu(),
-	must be within an RCU read-side critical section.  RCU
-	read-side critical sections are delimited by rcu_read_lock()
+	list_for_each_rcu(), list_for_each_entry_rcu(), and
+	list_for_each_continue_rcu() must be within an RCU read-side
+	critical section (or under the corresponding update-side lock).
+	RCU read-side critical sections are delimited by rcu_read_lock()
 	and rcu_read_unlock(), or by similar primitives such as
 	rcu_read_lock_bh() and rcu_read_unlock_bh().
 
diff -urpNa -X dontdiff linux-2.6.14/Documentation/RCU/whatisRCU.txt linux-2.6.14-RCUdoc/Documentation/RCU/whatisRCU.txt
--- linux-2.6.14/Documentation/RCU/whatisRCU.txt	2005-10-27 17:02:08.000000000 -0700
+++ linux-2.6.14-RCUdoc/Documentation/RCU/whatisRCU.txt	2005-10-28 14:40:47.000000000 -0700
@@ -768,7 +768,6 @@ RCU pointer/list traversal:
 	rcu_dereference
 	list_for_each_rcu		(to be deprecated in favor of
 					 list_for_each_entry_rcu)
-	list_for_each_safe_rcu		(deprecated, not used)
 	list_for_each_entry_rcu
 	list_for_each_continue_rcu	(to be deprecated in favor of new
 					 list_for_each_entry_continue_rcu)
@@ -798,6 +797,9 @@ RCU grace period:
 See the comment headers in the source code (or the docbook generated
 from them) for more information.
 
+Quick Quiz #4:  Why isn't there a list_for_each_safe_rcu() and
+		a list_for_each_entry_safe_rcu()?
+
 
 8.  ANSWERS TO QUICK QUIZZES
 
@@ -892,6 +894,25 @@ Answer:		Just as PREEMPT_RT permits pree
 		Besides, how does the computer know what pizza parlor
 		the human being went to???
 
+Quick Quiz #4:  Why isn't there a list_for_each_safe_rcu() and
+		a list_for_each_entry_safe_rcu()?
+
+Answer:		They are not needed.  Any place you might be tempted
+		to use list_for_each_safe_rcu(), you should instead use
+		list_for_each_rcu().  Similarly, any place you might
+		want to use list_for_each_entry_safe_rcu() you should
+		instead use list_for_each_entry_rcu().
+
+		To see the reason for this substitution, consider that
+		the whole point of the _safe_ macros is to handle the
+		case where the body of the loop deletes the list
+		entry being examined.  But RCU takes care of this deletion
+		case automatically, since any removed list element cannot
+		be freed until after all RCU read-side critical sections,
+		including the one containing the list macro, have completed.
+		Since RCU provides the safety, there is no need for a
+		special "safe" variant of the list macros.
+
 
 ACKNOWLEDGEMENTS
 
diff -urpNa -X dontdiff linux-2.6.14/include/linux/list.h linux-2.6.14-RCUdoc/include/linux/list.h
--- linux-2.6.14/include/linux/list.h	2005-10-27 17:02:08.000000000 -0700
+++ linux-2.6.14-RCUdoc/include/linux/list.h	2005-10-28 14:40:52.000000000 -0700
@@ -452,22 +452,6 @@ static inline void list_splice_init(stru
         	pos = pos->next)
 
 /**
- * list_for_each_safe_rcu	-	iterate over an rcu-protected list safe
- *					against removal of list entry
- * @pos:	the &struct list_head to use as a loop counter.
- * @n:		another &struct list_head to use as temporary storage
- * @head:	the head for your list.
- *
- * This list-traversal primitive may safely run concurrently with
- * the _rcu list-mutation primitives such as list_add_rcu()
- * as long as the traversal is guarded by rcu_read_lock().
- */
-#define list_for_each_safe_rcu(pos, n, head) \
-	for (pos = (head)->next; \
-		n = rcu_dereference(pos)->next, pos != (head); \
-		pos = n)
-
-/**
  * list_for_each_entry_rcu	-	iterate over rcu list of given type
  * @pos:	the type * to use as a loop counter.
  * @head:	the head for your list.

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

* [PATCH 2/2] Remove hlist_for_each_rcu() API, convert existing use to hlist_for_each_entry_rcu
  2005-10-29  2:59 [PATCH 1/2] Remove unused list_for_each_safe_rcu() API Paul E. McKenney
@ 2005-10-29  3:07 ` Paul E. McKenney
  0 siblings, 0 replies; 2+ messages in thread
From: Paul E. McKenney @ 2005-10-29  3:07 UTC (permalink / raw)
  To: linux-kernel; +Cc: akpm, dipankar, manfred, maneesh, erikj, ak

Hello!

This patch removes the hlist_for_each_rcu() API, which is used only
in one place, and is trivially converted to hlist_for_each_entry_rcu(),
making the code shorter and more readable.  Any out-of-tree uses may
be similarly converted.

Signed-off-by: <paulmck@us.ibm.com>

---

 Documentation/RCU/whatisRCU.txt |    2 --
 fs/dcache.c                     |   10 ++++------
 include/linux/list.h            |   13 ++++---------
 3 files changed, 8 insertions(+), 17 deletions(-)

diff -urpNa -X dontdiff linux-2.6.14-RCUdoc/Documentation/RCU/whatisRCU.txt linux-2.6.14-kill-hlist_for_each_rcu/Documentation/RCU/whatisRCU.txt
--- linux-2.6.14-RCUdoc/Documentation/RCU/whatisRCU.txt	2005-10-28 14:40:47.000000000 -0700
+++ linux-2.6.14-kill-hlist_for_each_rcu/Documentation/RCU/whatisRCU.txt	2005-10-28 17:29:10.000000000 -0700
@@ -771,8 +771,6 @@ RCU pointer/list traversal:
 	list_for_each_entry_rcu
 	list_for_each_continue_rcu	(to be deprecated in favor of new
 					 list_for_each_entry_continue_rcu)
-	hlist_for_each_rcu		(to be deprecated in favor of
-					 hlist_for_each_entry_rcu)
 	hlist_for_each_entry_rcu
 
 RCU pointer update:
diff -urpNa -X dontdiff linux-2.6.14-RCUdoc/fs/dcache.c linux-2.6.14-kill-hlist_for_each_rcu/fs/dcache.c
--- linux-2.6.14-RCUdoc/fs/dcache.c	2005-10-27 17:02:08.000000000 -0700
+++ linux-2.6.14-kill-hlist_for_each_rcu/fs/dcache.c	2005-10-28 17:34:01.000000000 -0700
@@ -644,7 +644,7 @@ void shrink_dcache_parent(struct dentry 
  *
  * Prune the dentries that are anonymous
  *
- * parsing d_hash list does not hlist_for_each_rcu() as it
+ * parsing d_hash list does not hlist_for_each_entry_rcu() as it
  * done under dcache_lock.
  *
  */
@@ -1043,15 +1043,13 @@ struct dentry * __d_lookup(struct dentry
 	struct hlist_head *head = d_hash(parent,hash);
 	struct dentry *found = NULL;
 	struct hlist_node *node;
+	struct dentry *dentry; 
 
 	rcu_read_lock();
 	
-	hlist_for_each_rcu(node, head) {
-		struct dentry *dentry; 
+	hlist_for_each_entry_rcu(dentry, node, head, d_hash) {
 		struct qstr *qstr;
 
-		dentry = hlist_entry(node, struct dentry, d_hash);
-
 		if (dentry->d_name.hash != hash)
 			continue;
 		if (dentry->d_parent != parent)
@@ -1123,7 +1121,7 @@ int d_validate(struct dentry *dentry, st
 	spin_lock(&dcache_lock);
 	base = d_hash(dparent, dentry->d_name.hash);
 	hlist_for_each(lhp,base) { 
-		/* hlist_for_each_rcu() not required for d_hash list
+		/* hlist_for_each_entry_rcu() not required for d_hash list
 		 * as it is parsed under dcache_lock
 		 */
 		if (dentry == hlist_entry(lhp, struct dentry, d_hash)) {
diff -urpNa -X dontdiff linux-2.6.14-RCUdoc/include/linux/list.h linux-2.6.14-kill-hlist_for_each_rcu/include/linux/list.h
--- linux-2.6.14-RCUdoc/include/linux/list.h	2005-10-28 14:40:52.000000000 -0700
+++ linux-2.6.14-kill-hlist_for_each_rcu/include/linux/list.h	2005-10-28 17:30:18.000000000 -0700
@@ -585,7 +585,7 @@ static inline void hlist_add_head(struct
  * or hlist_del_rcu(), running on this same list.
  * However, it is perfectly legal to run concurrently with
  * the _rcu list-traversal primitives, such as
- * hlist_for_each_rcu(), used to prevent memory-consistency
+ * hlist_for_each_entry_rcu(), used to prevent memory-consistency
  * problems on Alpha CPUs.  Regardless of the type of CPU, the
  * list-traversal primitive must be guarded by rcu_read_lock().
  */
@@ -634,7 +634,7 @@ static inline void hlist_add_after(struc
  * or hlist_del_rcu(), running on this same list.
  * However, it is perfectly legal to run concurrently with
  * the _rcu list-traversal primitives, such as
- * hlist_for_each_rcu(), used to prevent memory-consistency
+ * hlist_for_each_entry_rcu(), used to prevent memory-consistency
  * problems on Alpha CPUs.
  */
 static inline void hlist_add_before_rcu(struct hlist_node *n,
@@ -659,7 +659,7 @@ static inline void hlist_add_before_rcu(
  * or hlist_del_rcu(), running on this same list.
  * However, it is perfectly legal to run concurrently with
  * the _rcu list-traversal primitives, such as
- * hlist_for_each_rcu(), used to prevent memory-consistency
+ * hlist_for_each_entry_rcu(), used to prevent memory-consistency
  * problems on Alpha CPUs.
  */
 static inline void hlist_add_after_rcu(struct hlist_node *prev,
@@ -683,11 +683,6 @@ static inline void hlist_add_after_rcu(s
 	for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \
 	     pos = n)
 
-#define hlist_for_each_rcu(pos, head) \
-	for ((pos) = (head)->first; \
-		rcu_dereference((pos)) && ({ prefetch((pos)->next); 1; }); \
-		(pos) = (pos)->next)
-
 /**
  * hlist_for_each_entry	- iterate over list of given type
  * @tpos:	the type * to use as a loop counter.
@@ -740,7 +735,7 @@ static inline void hlist_add_after_rcu(s
 
 /**
  * hlist_for_each_entry_rcu - iterate over rcu list of given type
- * @pos:	the type * to use as a loop counter.
+ * @tpos:	the type * to use as a loop counter.
  * @pos:	the &struct hlist_node to use as a loop counter.
  * @head:	the head for your list.
  * @member:	the name of the hlist_node within the struct.

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

end of thread, other threads:[~2005-10-29  3:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-10-29  2:59 [PATCH 1/2] Remove unused list_for_each_safe_rcu() API Paul E. McKenney
2005-10-29  3:07 ` [PATCH 2/2] Remove hlist_for_each_rcu() API, convert existing use to hlist_for_each_entry_rcu Paul E. McKenney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox