From acabfd7496a0a4a9c890657b9efd77063bc2ccb3 Mon Sep 17 00:00:00 2001 From: Paolo Abeni Date: Wed, 4 Apr 2018 14:30:01 +0200 Subject: [PATCH] net: avoid unneeded atomic operation in ip*_append_data() After commit a878e1bad89d ("ipv4: factorize sk_wmem_alloc updates done by __ip_append_data()") and commit be7abb1b3133 ("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: a878e1bad89d ("ipv4: factorize sk_wmem_alloc updates done by __ip_append_data()") Fixes: be7abb1b3133 ("ipv6: factorize sk_wmem_alloc updates done by __ip6_append_data()") Signed-off-by: Paolo Abeni Reviewed-by: Eric Dumazet Signed-off-by: David S. Miller --- net/ipv4/ip_output.c | 3 ++- net/ipv6/ip6_output.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c index 94cacae76aca4..4c11b810a4477 100644 --- a/net/ipv4/ip_output.c +++ b/net/ipv4/ip_output.c @@ -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: diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index 66a768b7b8fb7..b8ee50e94af38 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -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: -- 2.39.5