Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1269527 > unrolled thread
| Started by | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| First post | 2015-11-14 20:10 +0100 |
| Last post | 2015-11-15 07:20 +0100 |
| Articles | 3 — 2 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH] net-ipv6: Delete unnecessary checks before the function call "kfree_skb" SF Markus Elfring <elfring@users.sourceforge.net> - 2015-11-14 20:10 +0100
Re: [PATCH] net-ipv6: Delete unnecessary checks before the function call "kfree_skb" Eric Dumazet <eric.dumazet@gmail.com> - 2015-11-15 04:40 +0100
Re: net-ipv6: Delete unnecessary checks before the function call "kfree_skb" SF Markus Elfring <elfring@users.sourceforge.net> - 2015-11-15 07:20 +0100
| From | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| Date | 2015-11-14 20:10 +0100 |
| Subject | [PATCH] net-ipv6: Delete unnecessary checks before the function call "kfree_skb" |
| Message-ID | <quOn0-7Yp-19@gated-at.bofh.it> |
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 14 Nov 2015 19:55:00 +0100
The kfree_skb() function tests whether its argument is NULL and then
returns immediately. Thus the test around the calls is not needed.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
net/ipv6/af_inet6.c | 7 ++-----
net/ipv6/netfilter/nf_conntrack_reasm.c | 3 +--
2 files changed, 3 insertions(+), 7 deletions(-)
diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
index 44bb66b..4cd9259 100644
--- a/net/ipv6/af_inet6.c
+++ b/net/ipv6/af_inet6.c
@@ -416,12 +416,9 @@ void inet6_destroy_sock(struct sock *sk)
/* Release rx options */
skb = xchg(&np->pktoptions, NULL);
- if (skb)
- kfree_skb(skb);
-
+ kfree_skb(skb);
skb = xchg(&np->rxpmtu, NULL);
- if (skb)
- kfree_skb(skb);
+ kfree_skb(skb);
/* Free flowlabels */
fl6_free_socklist(sk);
diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
index d5efeb8..dbc013b 100644
--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
@@ -172,8 +172,7 @@ static unsigned int nf_hashfn(const struct inet_frag_queue *q)
static void nf_skb_free(struct sk_buff *skb)
{
- if (NFCT_FRAG6_CB(skb)->orig)
- kfree_skb(NFCT_FRAG6_CB(skb)->orig);
+ kfree_skb(NFCT_FRAG6_CB(skb)->orig);
}
static void nf_ct_frag6_expire(unsigned long data)
--
2.6.2
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [next] | [standalone]
| From | Eric Dumazet <eric.dumazet@gmail.com> |
|---|---|
| Date | 2015-11-15 04:40 +0100 |
| Subject | Re: [PATCH] net-ipv6: Delete unnecessary checks before the function call "kfree_skb" |
| Message-ID | <quWky-4ua-9@gated-at.bofh.it> |
| In reply to | #1269527 |
On Sat, 2015-11-14 at 20:05 +0100, SF Markus Elfring wrote: > From: Markus Elfring <elfring@users.sourceforge.net> > Date: Sat, 14 Nov 2015 19:55:00 +0100 > > The kfree_skb() function tests whether its argument is NULL and then > returns immediately. Thus the test around the calls is not needed. > > This issue was detected by using the Coccinelle software. > > Signed-off-by: Markus Elfring <elfring@users.sourceforge.net> > --- > net/ipv6/af_inet6.c | 7 ++----- > net/ipv6/netfilter/nf_conntrack_reasm.c | 3 +-- > 2 files changed, 3 insertions(+), 7 deletions(-) > > diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c > index 44bb66b..4cd9259 100644 > --- a/net/ipv6/af_inet6.c > +++ b/net/ipv6/af_inet6.c > @@ -416,12 +416,9 @@ void inet6_destroy_sock(struct sock *sk) > /* Release rx options */ > > skb = xchg(&np->pktoptions, NULL); > - if (skb) > - kfree_skb(skb); > - > + kfree_skb(skb); > skb = xchg(&np->rxpmtu, NULL); > - if (skb) > - kfree_skb(skb); > + kfree_skb(skb); > There is no 'issue' here, or not this one. In most cases, these pointers are NULL, so the test can be predicted by the processor. While if the test is done in kfree_skb(), the branch predictor of the cpu wont be able to predict things. By feeding too many NULL pointers to kfree_skb(), we slow down it. Branch misses and hits were considered important years ago... But seeing this inet6_destroy_sock() is (ab)using xchg() three times, I am not sure author cared that much about performance. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | SF Markus Elfring <elfring@users.sourceforge.net> |
|---|---|
| Date | 2015-11-15 07:20 +0100 |
| Subject | Re: net-ipv6: Delete unnecessary checks before the function call "kfree_skb" |
| Message-ID | <quYPn-69L-1@gated-at.bofh.it> |
| In reply to | #1269631 |
> While if the test is done in kfree_skb(), the branch predictor of the > cpu wont be able to predict things. > > By feeding too many NULL pointers to kfree_skb(), we slow down it. Would it make sense to annotate checks before such function calls as "UNLIKELY"? Regards, Markus -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web