]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Call rcu_barrier() five times in the isc__mem_destroy()
authorOndřej Surý <ondrej@isc.org>
Tue, 27 Jun 2023 06:26:12 +0000 (08:26 +0200)
committerOndřej Surý <ondrej@isc.org>
Mon, 31 Jul 2023 13:51:15 +0000 (15:51 +0200)
Because rcu_barrier() needs to be called as many times as the number of
nested call_rcu() calls (call_rcu() calls made from call_rcu thread),
and currently there's no mechanism to detect whether there are more
call_rcu callbacks scheduled, we simply call the rcu_barrier() multiple
times.  The overhead is negligible and it prevents rare assertion
failures caused by the check for memory leaks in isc__mem_destroy().

lib/isc/mem.c

index 593b610890412de9c7b50ac0b04a4d5d6889cd39..b03e1122d0ba4c5d96b1de9d69562a4b344ee7bd 100644 (file)
@@ -582,9 +582,25 @@ isc__mem_destroy(isc_mem_t **ctxp FLARG) {
 
        /*
         * wait for asynchronous memory reclamation to complete
-        * before checking for memory leaks
+        * before checking for memory leaks.
+        *
+        * Because rcu_barrier() needs to be called as many times
+        * as the number of nested call_rcu() calls (call_rcu()
+        * calls made from call_rcu thread), and currently there's
+        * no mechanism to detect whether there are more call_rcu
+        * callbacks scheduled, we simply call the rcu_barrier()
+        * multiple times.  The overhead is negligible and it
+        * prevents rare assertion failures caused by the check
+        * for memory leaks below.
+        *
+        * If there's more nested call_rcu() calls than five levels,
+        * we are doing something horribly wrong...
         */
        rcu_barrier();
+       rcu_barrier();
+       rcu_barrier();
+       rcu_barrier();
+       rcu_barrier();
 
 #if ISC_MEM_TRACKLINES
        if ((ctx->debugging & ISC_MEM_DEBUGTRACE) != 0) {