OSDN Git Service

udp: elide zerocopy operation in hot path
authorWillem de Bruijn <willemb@google.com>
Fri, 30 Nov 2018 20:32:40 +0000 (15:32 -0500)
committerDavid S. Miller <davem@davemloft.net>
Mon, 3 Dec 2018 23:58:32 +0000 (15:58 -0800)
commit52900d22288e7d45846037e1db277c665bbc40db
tree8e69a5639d94cd4774bfc4645f5f0397abfb8cb8
parentb5947e5d1e710c35ea281247bd27e6975250285c
udp: elide zerocopy operation in hot path

With MSG_ZEROCOPY, each skb holds a reference to a struct ubuf_info.
Release of its last reference triggers a completion notification.

The TCP stack in tcp_sendmsg_locked holds an extra ref independent of
the skbs, because it can build, send and free skbs within its loop,
possibly reaching refcount zero and freeing the ubuf_info too soon.

The UDP stack currently also takes this extra ref, but does not need
it as all skbs are sent after return from __ip(6)_append_data.

Avoid the extra refcount_inc and refcount_dec_and_test, and generally
the sock_zerocopy_put in the common path, by passing the initial
reference to the first skb.

This approach is taken instead of initializing the refcount to 0, as
that would generate error "refcount_t: increment on 0" on the
next skb_zcopy_set.

Changes
  v3 -> v4
    - Move skb_zcopy_set below the only kfree_skb that might cause
      a premature uarg destroy before skb_zerocopy_put_abort
      - Move the entire skb_shinfo assignment block, to keep that
        cacheline access in one place

Signed-off-by: Willem de Bruijn <willemb@google.com>
Acked-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/skbuff.h
net/core/skbuff.c
net/ipv4/ip_output.c
net/ipv4/tcp.c
net/ipv6/ip6_output.c