netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* atomic_dec_and_test for child dst needed in dst_destroy?
@ 2005-04-05 18:55 Christoph Lameter
  2005-04-05 19:34 ` David S. Miller
  2005-04-05 21:45 ` Herbert Xu
  0 siblings, 2 replies; 27+ messages in thread
From: Christoph Lameter @ 2005-04-05 18:55 UTC (permalink / raw)
  To: netdev

It seems that the atomic_dec_and_test for the child dst in net/core/dst.c
is really not needed since dst_destroy cannot be called simultanously for
the same dst (frees dst unconditionally via kmem_cache_free). If a dst can
only have one child then the dst may only be deleted from its parent dst.

The refcnt is also incremented via dst_hold and decremented via
dst_release elsewhere (seems that they may race with dst_destroy?) but
there is no provisions to do something special if __refcnt would reach
zero in dst_release. __refcnt is always expected to be always
greater than zero there.

However, it is checked without dec_and_test for zero in various other
locations (dst_free, dst_run_gc, dn_dst_check_expire).

Is the atomic_dec_and_test in dst_destroy just there to join two atomic
operations into one without being necessary for the correctness of freeing
dsts?

Then we really would not need atomic_dec_and_test in dst_destroy() and the
following patch would be safe (There are some ideas for optimizations that
would not be able to preserve the atomic_dec_and_test).

Index: linux-2.6.11/net/core/dst.c
===================================================================
--- linux-2.6.11.orig/net/core/dst.c	2005-03-01 23:38:12.000000000 -0800
+++ linux-2.6.11/net/core/dst.c	2005-04-05 11:04:41.000000000 -0700
@@ -198,7 +198,8 @@ again:

 	dst = child;
 	if (dst) {
-		if (atomic_dec_and_test(&dst->__refcnt)) {
+		atomic_dec(&dst->__refcnt);
+		if (!atomic_read(&dst->__refcnt)) {
 			/* We were real parent of this dst, so kill child. */
 			if (dst->flags&DST_NOHASH)
 				goto again;

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

end of thread, other threads:[~2005-04-09 15:28 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-04-05 18:55 atomic_dec_and_test for child dst needed in dst_destroy? Christoph Lameter
2005-04-05 19:34 ` David S. Miller
2005-04-05 19:47   ` Christoph Lameter
2005-04-05 19:50     ` David S. Miller
2005-04-05 19:58       ` Christoph Lameter
2005-04-05 20:12         ` David S. Miller
2005-04-05 21:45 ` Herbert Xu
2005-04-05 21:48   ` David S. Miller
2005-04-05 22:14   ` Christoph Lameter
2005-04-06  2:19     ` Herbert Xu
2005-04-06  3:19       ` Christoph Lameter
2005-04-06  8:32         ` Herbert Xu
2005-04-06 18:17           ` David S. Miller
2005-04-06 18:48             ` Christoph Lameter
2005-04-07 11:07             ` Herbert Xu
2005-04-07 16:00               ` Christoph Lameter
2005-04-07 21:25                 ` Herbert Xu
2005-04-07 22:30                   ` Christoph Lameter
2005-04-07 23:07                     ` Herbert Xu
2005-04-08  5:45                   ` Christoph Lameter
2005-04-08  5:48                     ` Herbert Xu
2005-04-08 15:05                       ` Christoph Lameter
2005-04-08 21:45                         ` Herbert Xu
2005-04-09 15:28                           ` Christoph Lameter
     [not found]   ` <b82a8917050406002339f732ca@mail.gmail.com>
2005-04-06  8:53     ` Fwd: " pravin b shelar
2005-04-07 11:23       ` Herbert Xu
2005-04-07 12:30         ` pravin b shelar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).