Skip to contentSkip to conversation

Patches for Section Deferred Processing

PATCH In review Junchang Wang 2 participants 6 messages Nov 24, 2018 – Nov 25, 2018

lore
Share & tools
lore
#0 lore raw

cover Patches for Section Deferred Processing

Hi Paul,

This is the patch sets for Section Deferred Processing. Please take a look.

The first patch fixes a dependency issue in compiling route_hazptr.c.

The second patch fixes a memory leak bug in hazptr.c.

The last one fixes a typo in writing.

Thanks,
--Junchang

Junchang Wang (3):
route_hazptr: Add dependency to hazptr
route_hazptr: Fix a memory leak bug
defer: Fix a typo

 CodeSamples/defer/Makefile | 2 +-
 CodeSamples/defer/hazptr.c | 4 ++++
 defer/hazptr.tex           | 2 +-
 3 files changed, 6 insertions(+), 2 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/3 route_hazptr: Add dependency to hazptr

Target route_hazptr depends on hazptr.c and hazptr.h. So add this dependency to Makefile.

---
 CodeSamples/defer/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
CodeSamples/defer/Makefile +1 -1
index 5a08c1f..270c151 100644
@@ -123,7 +123,7 @@ rcu_sig: rcu_sig.c rcu_sig.h ../api.h rcutorture.h
 rcu_ts: rcu_ts.c rcu_ts.h ../api.h rcutorture.h
 	cc $(GCC_ARGS) -o rcu_ts -DTEST rcu_ts.c -lpthread
 
-route_hazptr: route_hazptr.c ../api.h ../lib/random.h ../lib/random.c routetorture.h
+route_hazptr: route_hazptr.c hazptr.c hazptr.h ../api.h ../lib/random.h ../lib/random.c routetorture.h
 	cc $(GCC_ARGS) -o route_hazptr route_hazptr.c hazptr.c ../lib/random.c -lpthread
 
 route_rcu: route_rcu.c ../api.h ../lib/random.h ../lib/random.c routetorture.h
Signature · 1 line
2.7.4
#2 lore raw

PATCH 2/3 route_hazptr: Fix a memory leak bug

In reply to Junchang Wang

Global pointer gplist is used to record hazard pointer array once it's allocated. This can avoid allocating and freeing hazptr array each time function hazptr_scan() is invoked. This patch fixes a memory leak bug and helps achieve the design goal.

---
 CodeSamples/defer/hazptr.c | 4 ++++
 1 file changed, 4 insertions(+)
CodeSamples/defer/hazptr.c +4 -0
index 91df310..061ca2c 100644
@@ -53,6 +53,9 @@ void hazptr_thread_exit(void)
 		hazptr_scan();
 		poll(NULL, 0, 1);
 	}
+
+	if (gplist != NULL)
+		free(gplist);
 }
 
 void hazptr_reinitialize()
@@ -103,6 +106,7 @@ void hazptr_scan()
 			fprintf(stderr, "hazptr_scan: out of memory\n");
 			exit(EXIT_FAILURE);
 		}
+		gplist = plist;
 	}
 
 	/*
Signature · 1 line
2.7.4
#3 lore raw

PATCH 3/3 defer: Fix a typo

In reply to Junchang Wang
---
 defer/hazptr.tex | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
defer/hazptr.tex +1 -1
index 346146f..09c5f21 100644
@@ -91,7 +91,7 @@ recorded a hazard pointer for the data element.
 	It might be inefficient in some sense, but the fact is that
 	such restarting is absolutely required for correctness.
 	To see this, consider a hazard-pointer-protected linked list
-	containing elements~A, B, and~C that is subjecte to the
+	containing elements~A, B, and~C that is subjected to the
 	following sequence of events:
 
 	\begin{enumerate}
Signature · 1 line
2.7.4
#4 lore raw
In reply to Junchang Wang
Quoted 6 lines · Junchang Wang

Hi Paul,

This is the patch sets for Section Deferred Processing. Please take a look.

The first patch fixes a dependency issue in compiling route_hazptr.c.

Quoted 7 lines

The second patch fixes a memory leak bug in hazptr.c.

The last one fixes a typo in writing.

Thanks,
--Junchang

Good catches, applied, thank you!

On the memory-leak bug, I removed the "if" due to POSIX specifying that free() is a no-op when given a NULL pointer.

	http://pubs.opengroup.org/onlinepubs/009695399/functions/free.html

Please see below for the updated commit, and please let me know if I messed anything up.

Thanx, Paul

Quoted 9 lines

Junchang Wang (3):
route_hazptr: Add dependency to hazptr
route_hazptr: Fix a memory leak bug
defer: Fix a typo

 CodeSamples/defer/Makefile | 2 +-
 CodeSamples/defer/hazptr.c | 4 ++++
 defer/hazptr.tex           | 2 +-
 3 files changed, 6 insertions(+), 2 deletions(-)

------------------------------------------------------------------------

commit b8c1647f53ddedf10bf2973371f6f685dfd31d62

Author: Junchang Wang <[email protected]>
Date:   Sat Nov 24 17:34:53 2018 +0800

route_hazptr: Fix a memory leak bug

Global pointer gplist is used to record hazard pointer array once it's allocated. This can avoid allocating and freeing hazptr array each time function hazptr_scan() is invoked. This patch fixes a memory leak bug and helps achieve the design goal.

[ paulmck: Remove redundant "if" because free() ignores NULL argument. ]
CodeSamples/defer/hazptr.c +3 -0
index 91df310e24a2..fdb387e59ea1 100644
@@ -53,6 +53,8 @@ void hazptr_thread_exit(void)
 		hazptr_scan();
 		poll(NULL, 0, 1);
 	}
+
+	free(gplist);
 }
 
 void hazptr_reinitialize()
@@ -103,6 +105,7 @@ void hazptr_scan()
 			fprintf(stderr, "hazptr_scan: out of memory\n");
 			exit(EXIT_FAILURE);
 		}
+		gplist = plist;
 	}
 
 	/*
#5 lore raw
Quoted 18 lines · Paul E. McKenney
Quoted 6 lines · Junchang Wang

Hi Paul,

This is the patch sets for Section Deferred Processing. Please take a look.

The first patch fixes a dependency issue in compiling route_hazptr.c.

Quoted 7 lines

The second patch fixes a memory leak bug in hazptr.c.

The last one fixes a typo in writing.

Thanks,
--Junchang

Good catches, applied, thank you!

Quoted 8 lines

On the memory-leak bug, I removed the "if" due to POSIX specifying that free() is a no-op when given a NULL pointer.

        http://pubs.opengroup.org/onlinepubs/009695399/functions/free.html

Please see below for the updated commit, and please let me know if I messed anything up.

That's right. Thanks a lot for the comment and link :-).

Thanks,
--Junchang

Quoted 51 lines

Thanx, Paul

Quoted 9 lines

Junchang Wang (3):
route_hazptr: Add dependency to hazptr
route_hazptr: Fix a memory leak bug
defer: Fix a typo

 CodeSamples/defer/Makefile | 2 +-
 CodeSamples/defer/hazptr.c | 4 ++++
 defer/hazptr.tex           | 2 +-
 3 files changed, 6 insertions(+), 2 deletions(-)

------------------------------------------------------------------------

commit b8c1647f53ddedf10bf2973371f6f685dfd31d62

Author: Junchang Wang <[email protected]>
Date:   Sat Nov 24 17:34:53 2018 +0800

route_hazptr: Fix a memory leak bug

Global pointer gplist is used to record hazard pointer array once it's allocated. This can avoid allocating and freeing hazptr array each time function hazptr_scan() is invoked. This patch fixes a memory leak bug and helps achieve the design goal.

[ paulmck: Remove redundant "if" because free() ignores NULL argument. ]
CodeSamples/defer/hazptr.c +3 -0
index 91df310e24a2..fdb387e59ea1 100644
@@ -53,6 +53,8 @@ void hazptr_thread_exit(void)
                hazptr_scan();
                poll(NULL, 0, 1);
        }
+
+       free(gplist);
 }
 
 void hazptr_reinitialize()
@@ -103,6 +105,7 @@ void hazptr_scan()
                        fprintf(stderr, "hazptr_scan: out of memory\n");
                        exit(EXIT_FAILURE);
                }
+               gplist = plist;
        }
 
        /*