Skip to content

Commit

Permalink
Merge branch 'inet-factorize-sk_wmem_alloc-updates'
Browse files Browse the repository at this point in the history
Eric Dumazet says:

====================
inet: factorize sk_wmem_alloc updates

While testing my inet defrag changes, I found that senders
could spend ~20% of cpu cycles in skb_set_owner_w() updating
sk->sk_wmem_alloc for every fragment they cook, competing
with TX completion of prior skbs possibly happening on another cpus.

One solution to this problem is to use alloc_skb() instead
of sock_wmalloc() and manually perform a single sk_wmem_alloc change.

This greatly increases speed for applications sending big UDP datagrams.
====================

Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
davem330 committed Apr 1, 2018
2 parents c072550 + 1f4c6eb commit 16c3c91
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
17 changes: 12 additions & 5 deletions net/ipv4/ip_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,7 @@ static int __ip_append_data(struct sock *sk,
unsigned int maxfraglen, fragheaderlen, maxnonfragsize;
int csummode = CHECKSUM_NONE;
struct rtable *rt = (struct rtable *)cork->dst;
unsigned int wmem_alloc_delta = 0;
u32 tskey = 0;

skb = skb_peek_tail(queue);
Expand Down Expand Up @@ -971,11 +972,10 @@ static int __ip_append_data(struct sock *sk,
(flags & MSG_DONTWAIT), &err);
} else {
skb = NULL;
if (refcount_read(&sk->sk_wmem_alloc) <=
if (refcount_read(&sk->sk_wmem_alloc) + wmem_alloc_delta <=
2 * sk->sk_sndbuf)
skb = sock_wmalloc(sk,
alloclen + hh_len + 15, 1,
sk->sk_allocation);
skb = alloc_skb(alloclen + hh_len + 15,
sk->sk_allocation);
if (unlikely(!skb))
err = -ENOBUFS;
}
Expand Down Expand Up @@ -1033,6 +1033,11 @@ static int __ip_append_data(struct sock *sk,
/*
* Put the packet on the pending queue.
*/
if (!skb->destructor) {
skb->destructor = sock_wfree;
skb->sk = sk;
wmem_alloc_delta += skb->truesize;
}
__skb_queue_tail(queue, skb);
continue;
}
Expand Down Expand Up @@ -1079,19 +1084,21 @@ static int __ip_append_data(struct sock *sk,
skb->len += copy;
skb->data_len += copy;
skb->truesize += copy;
refcount_add(copy, &sk->sk_wmem_alloc);
wmem_alloc_delta += copy;
}
offset += copy;
length -= copy;
}

refcount_add(wmem_alloc_delta, &sk->sk_wmem_alloc);
return 0;

error_efault:
err = -EFAULT;
error:
cork->length -= length;
IP_INC_STATS(sock_net(sk), IPSTATS_MIB_OUTDISCARDS);
refcount_add(wmem_alloc_delta, &sk->sk_wmem_alloc);
return err;
}

Expand Down
17 changes: 12 additions & 5 deletions net/ipv6/ip6_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,7 @@ static int __ip6_append_data(struct sock *sk,
struct ipv6_txoptions *opt = v6_cork->opt;
int csummode = CHECKSUM_NONE;
unsigned int maxnonfragsize, headersize;
unsigned int wmem_alloc_delta = 0;

skb = skb_peek_tail(queue);
if (!skb) {
Expand Down Expand Up @@ -1411,11 +1412,10 @@ static int __ip6_append_data(struct sock *sk,
(flags & MSG_DONTWAIT), &err);
} else {
skb = NULL;
if (refcount_read(&sk->sk_wmem_alloc) <=
if (refcount_read(&sk->sk_wmem_alloc) + wmem_alloc_delta <=
2 * sk->sk_sndbuf)
skb = sock_wmalloc(sk,
alloclen + hh_len, 1,
sk->sk_allocation);
skb = alloc_skb(alloclen + hh_len,
sk->sk_allocation);
if (unlikely(!skb))
err = -ENOBUFS;
}
Expand Down Expand Up @@ -1474,6 +1474,11 @@ static int __ip6_append_data(struct sock *sk,
/*
* Put the packet on the pending queue
*/
if (!skb->destructor) {
skb->destructor = sock_wfree;
skb->sk = sk;
wmem_alloc_delta += skb->truesize;
}
__skb_queue_tail(queue, skb);
continue;
}
Expand Down Expand Up @@ -1520,19 +1525,21 @@ static int __ip6_append_data(struct sock *sk,
skb->len += copy;
skb->data_len += copy;
skb->truesize += copy;
refcount_add(copy, &sk->sk_wmem_alloc);
wmem_alloc_delta += copy;
}
offset += copy;
length -= copy;
}

refcount_add(wmem_alloc_delta, &sk->sk_wmem_alloc);
return 0;

error_efault:
err = -EFAULT;
error:
cork->length -= length;
IP6_INC_STATS(sock_net(sk), rt->rt6i_idev, IPSTATS_MIB_OUTDISCARDS);
refcount_add(wmem_alloc_delta, &sk->sk_wmem_alloc);
return err;
}

Expand Down

0 comments on commit 16c3c91

Please sign in to comment.