]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
net: avoid unneeded atomic operation in ip*_append_data()
authorPaolo Abeni <pabeni@redhat.com>
Wed, 4 Apr 2018 12:30:01 +0000 (14:30 +0200)
committerDavid S. Miller <davem@davemloft.net>
Wed, 4 Apr 2018 15:53:08 +0000 (11:53 -0400)
After commit 694aba690de0 ("ipv4: factorize sk_wmem_alloc updates
done by __ip_append_data()") and commit 1f4c6eb24029 ("ipv6:
factorize sk_wmem_alloc updates done by __ip6_append_data()"),
when transmitting sub MTU datagram, an addtional, unneeded atomic
operation is performed in ip*_append_data() to update wmem_alloc:
in the above condition the delta is 0.

The above cause small but measurable performance regression in UDP
xmit tput test with packet size below MTU.

This change avoids such overhead updating wmem_alloc only if
wmem_alloc_delta is non zero.

The error path is left intentionally unmodified: it's a slow path
and simplicity is preferred to performances.

Fixes: 694aba690de0 ("ipv4: factorize sk_wmem_alloc updates done by __ip_append_data()")
Fixes: 1f4c6eb24029 ("ipv6: factorize sk_wmem_alloc updates done by __ip6_append_data()")
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/ipv4/ip_output.c
net/ipv6/ip6_output.c

index 94cacae76aca41e6e7feb7575c7999a414145c49..4c11b810a4477c2f657ba6a58cec47809547eee0 100644 (file)
@@ -1090,7 +1090,8 @@ alloc_new_skb:
                length -= copy;
        }
 
-       refcount_add(wmem_alloc_delta, &sk->sk_wmem_alloc);
+       if (wmem_alloc_delta)
+               refcount_add(wmem_alloc_delta, &sk->sk_wmem_alloc);
        return 0;
 
 error_efault:
index 66a768b7b8fb796670bf69fc451264a72d153228..b8ee50e94af384b1a9b404845291e6967517bf88 100644 (file)
@@ -1545,7 +1545,8 @@ alloc_new_skb:
                length -= copy;
        }
 
-       refcount_add(wmem_alloc_delta, &sk->sk_wmem_alloc);
+       if (wmem_alloc_delta)
+               refcount_add(wmem_alloc_delta, &sk->sk_wmem_alloc);
        return 0;
 
 error_efault: