Message ID | 4A37AA0C.40507@gmail.com |
---|---|
State | Changes Requested, archived |
Delegated to: | David Miller |
Headers | show |
On Tue, 16 Jun 2009, Eric Dumazet wrote: > > Here is first patch to take into account this initial offset in sk_wmem_alloc > > (Only compiled, not tested) I think this is incredibly ugly and hacky. > @@ -162,7 +162,7 @@ static void atalk_destroy_timer(unsigned long data) > { > struct sock *sk = (struct sock *)data; > > - if (atomic_read(&sk->sk_wmem_alloc) || > + if (atomic_read(&sk->sk_wmem_alloc) > 1 || > atomic_read(&sk->sk_rmem_alloc)) { Seriously, look at that code, and tell me it makes sense. No, it does not. The code looks like totally random line noise, and that whole "> 1" test makes no conceptual sense what-so-ever. It _will_ result in random bugs later on, because code that doesn't make sense will never be good in the long run. At the very least, add a helper function for "do I actually have outstanding allocations" or something like that. IOW, do a /* * Comment here about that magical "1" */ static inline int sk_has_allocations(struct sock *sk) { return atomic_read(&sk->sk_wmem_alloc) > 1 || atomic_read(&sk->sk_rmem_alloc); } and then make the various network protocols use that, rather than open-coding some random internal implementation magic. Linus -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
From: Linus Torvalds <torvalds@linux-foundation.org> Date: Tue, 16 Jun 2009 11:59:34 -0700 (PDT) > At the very least, add a helper function for "do I actually have > outstanding allocations" or something like that. IOW, do a > > /* > * Comment here about that magical "1" > */ > static inline int sk_has_allocations(struct sock *sk) > { > return atomic_read(&sk->sk_wmem_alloc) > 1 || > atomic_read(&sk->sk_rmem_alloc); > } > > and then make the various network protocols use that, rather than > open-coding some random internal implementation magic. I agree, this should be handled with a helper function abstraction rather than putting "1" checks all over the place. -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
David Miller a écrit : > From: Linus Torvalds <torvalds@linux-foundation.org> > Date: Tue, 16 Jun 2009 11:59:34 -0700 (PDT) > >> At the very least, add a helper function for "do I actually have >> outstanding allocations" or something like that. IOW, do a >> >> /* >> * Comment here about that magical "1" >> */ >> static inline int sk_has_allocations(struct sock *sk) >> { >> return atomic_read(&sk->sk_wmem_alloc) > 1 || >> atomic_read(&sk->sk_rmem_alloc); >> } >> >> and then make the various network protocols use that, rather than >> open-coding some random internal implementation magic. > > I agree, this should be handled with a helper function > abstraction rather than putting "1" checks all over the place. Fair enough, I'll submit an updated patch in following hour. Thank you -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/net/appletalk/ddp.c b/net/appletalk/ddp.c index b603cba..048cfd0 100644 --- a/net/appletalk/ddp.c +++ b/net/appletalk/ddp.c @@ -162,7 +162,7 @@ static void atalk_destroy_timer(unsigned long data) { struct sock *sk = (struct sock *)data; - if (atomic_read(&sk->sk_wmem_alloc) || + if (atomic_read(&sk->sk_wmem_alloc) > 1 || atomic_read(&sk->sk_rmem_alloc)) { sk->sk_timer.expires = jiffies + SOCK_DESTROY_TIME; add_timer(&sk->sk_timer); @@ -175,7 +175,7 @@ static inline void atalk_destroy_socket(struct sock *sk) atalk_remove_socket(sk); skb_queue_purge(&sk->sk_receive_queue); - if (atomic_read(&sk->sk_wmem_alloc) || + if (atomic_read(&sk->sk_wmem_alloc) > 1 || atomic_read(&sk->sk_rmem_alloc)) { setup_timer(&sk->sk_timer, atalk_destroy_timer, (unsigned long)sk); diff --git a/net/ax25/af_ax25.c b/net/ax25/af_ax25.c index fd9d06f..2e81b1d 100644 --- a/net/ax25/af_ax25.c +++ b/net/ax25/af_ax25.c @@ -330,7 +330,7 @@ void ax25_destroy_socket(ax25_cb *ax25) } if (ax25->sk != NULL) { - if (atomic_read(&ax25->sk->sk_wmem_alloc) || + if (atomic_read(&ax25->sk->sk_wmem_alloc) > 1 || atomic_read(&ax25->sk->sk_rmem_alloc)) { /* Defer: outstanding buffers */ setup_timer(&ax25->dtimer, ax25_destroy_timer, diff --git a/net/econet/af_econet.c b/net/econet/af_econet.c index 8121bf0..051dcb6 100644 --- a/net/econet/af_econet.c +++ b/net/econet/af_econet.c @@ -540,7 +540,7 @@ static void econet_destroy_timer(unsigned long data) { struct sock *sk=(struct sock *)data; - if (!atomic_read(&sk->sk_wmem_alloc) && + if (atomic_read(&sk->sk_wmem_alloc) <= 1 && !atomic_read(&sk->sk_rmem_alloc)) { sk_free(sk); return; @@ -580,7 +580,7 @@ static int econet_release(struct socket *sock) skb_queue_purge(&sk->sk_receive_queue); if (atomic_read(&sk->sk_rmem_alloc) || - atomic_read(&sk->sk_wmem_alloc)) { + atomic_read(&sk->sk_wmem_alloc) > 1) { sk->sk_timer.data = (unsigned long)sk; sk->sk_timer.expires = jiffies + HZ; sk->sk_timer.function = econet_destroy_timer; diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c index 3be0e01..8126bd4 100644 --- a/net/netrom/af_netrom.c +++ b/net/netrom/af_netrom.c @@ -286,7 +286,7 @@ void nr_destroy_socket(struct sock *sk) kfree_skb(skb); } - if (atomic_read(&sk->sk_wmem_alloc) || + if (atomic_read(&sk->sk_wmem_alloc) > 1 || atomic_read(&sk->sk_rmem_alloc)) { /* Defer: outstanding buffers */ sk->sk_timer.function = nr_destroy_timer; diff --git a/net/rose/af_rose.c b/net/rose/af_rose.c index 877a7f6..0ab0f4d 100644 --- a/net/rose/af_rose.c +++ b/net/rose/af_rose.c @@ -356,7 +356,7 @@ void rose_destroy_socket(struct sock *sk) kfree_skb(skb); } - if (atomic_read(&sk->sk_wmem_alloc) || + if (atomic_read(&sk->sk_wmem_alloc) > 1 || atomic_read(&sk->sk_rmem_alloc)) { /* Defer: outstanding buffers */ setup_timer(&sk->sk_timer, rose_destroy_timer, diff --git a/net/x25/af_x25.c b/net/x25/af_x25.c index c51f309..57dd5d3 100644 --- a/net/x25/af_x25.c +++ b/net/x25/af_x25.c @@ -372,7 +372,7 @@ static void __x25_destroy_socket(struct sock *sk) kfree_skb(skb); } - if (atomic_read(&sk->sk_wmem_alloc) || + if (atomic_read(&sk->sk_wmem_alloc) > 1 || atomic_read(&sk->sk_rmem_alloc)) { /* Defer: outstanding buffers */ sk->sk_timer.expires = jiffies + 10 * HZ;