netfilter: remove redundant skb check in nf_conntrack_put_reasm
Subsystems (2)
PATCH 1/1 netfilter: remove redundant skb check in nf_conntrack_put_reasm
kfree_skb already checks for skb existence - remove redundant check from nf_conntrack_put_reasm.
Phil
include/linux/skbuff.h +1 -2
@@ -2604,8 +2604,7 @@ static inline void nf_conntrack_get_reasm(struct sk_buff *skb) }static inline void nf_conntrack_put_reasm (struct sk_buff *skb) { -if (skb) -kfree_skb (skb); +kfree_skb (skb); }#endif #ifdef CONFIG_BRIDGE_NETFILTER
Florian Westphal
maintainerQuoted 2 lines · Phil Oester
kfree_skbalready checks for skb existence - remove redundant check fromnf_conntrack_put_reasm.
This is called for every free'd skb, in almost all cases the condition will be false.
So I think its ok to keep this check.
Pablo Neira Ayuso
maintainerQuoted 8 lines · Florian Westphal
Quoted 2 lines · Phil Oester
kfree_skbalready checks for skb existence - remove redundant check fromnf_conntrack_put_reasm.This is called for every free'd skb, in almost all cases the condition will be false.
So I think its ok to keep this check.
I see, we'll hit branch mispredictions most of the time. I have kept this back. Thanks Florian.
Quoted 5 lines · Pablo Neira Ayuso
Quoted 4 lines · Florian Westphal
Quoted 2 lines · Phil Oester
kfree_skbalready checks for skb existence - remove redundant check fromnf_conntrack_put_reasm.
Quoted 7 lines
Quoted 4 lines
This is called for every free'd skb, in almost all cases the condition will be false.
So I think its ok to keep this check.
I see, we'll hit branch mispredictions most of the time. I have kept this back. Thanks Florian.
If we're concerned about branch mispredictions, we should change the check to match the one at the top of kfree_skb:
if (unlikely(!skb))
return;However nf_conntrack_put_reasm is only used in 3 places in the entire tree. Unclear why we don't just call kfree_skb directly in these 3 places.
Phil
Florian Westphal
maintainerQuoted 11 lines · Phil Oester
Quoted 10 lines · Pablo Neira Ayuso
Quoted 8 lines · Florian Westphal
Quoted 2 lines · Phil Oester
kfree_skbalready checks for skb existence - remove redundant check fromnf_conntrack_put_reasm.This is called for every free'd skb, in almost all cases the condition will be false.
So I think its ok to keep this check.
Quoted 7 lines
Quoted 2 lines
I see, we'll hit branch mispredictions most of the time. I have kept this back. Thanks Florian.
If we're concerned about branch mispredictions, we should change the check to match the one at the top of
kfree_skb:if (unlikely(!skb)) return;
Its the opposite. For kfree_skb skb is (virtually) never NULL.
Quoted 2 lines
However
nf_conntrack_put_reasmis only used in 3 places in the entire tree. Unclear why we don't just callkfree_skbdirectly in these 3 places.
I guess what you could do is s/nf_conntrack_put_reasm/kfree_skb/g and also change skb_release_head_state() to use
#ifdef NET_SKBUFF_NF_DEFRAG_NEEDED
if (skb->nfct) /* usually NULL */
kfree_skb(skb->nfct);#endif
[ or show that there is no performance degradation for workloads where
we end up calling kfree_skb(NULL) in hot path ]
Pablo Neira Ayuso
maintainerQuoted 2 lines · Phil Oester
kfree_skbalready checks for skb existence - remove redundant check fromnf_conntrack_put_reasm.
Applied with changes. I have added this chunk to this patch.
net/ipv6/netfilter/nf_conntrack_reasm.c +0 -0
@@ -154,8 +154,7 @@ static unsigned int nf_hashfn(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)
Thanks.