Skip to content

Commit 163e529

Browse files
Paolo Abenidavem330
authored andcommitted
veth: implement ndo_set_rx_headroom
The rx headroom for veth dev is the peer device needed_headroom. Avoid ping-pong updates setting the private flag IFF_PHONY_HEADROOM. This avoids skb head reallocation when forwarding from a veth dev towards a device adding some kind of encapsulation. When transmitting frames below the MTU size towards a vxlan device, this gives about 10% performance speed-up when OVS is used to connect the veth and the vxlan device and a little more when using a plain Linux bridge. Signed-off-by: Paolo Abeni <pabeni@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent eaea34b commit 163e529

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

drivers/net/veth.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ struct pcpu_vstats {
3535
struct veth_priv {
3636
struct net_device __rcu *peer;
3737
atomic64_t dropped;
38+
unsigned requested_headroom;
3839
};
3940

4041
/*
@@ -271,6 +272,29 @@ static int veth_get_iflink(const struct net_device *dev)
271272
return iflink;
272273
}
273274

275+
static void veth_set_rx_headroom(struct net_device *dev, int new_hr)
276+
{
277+
struct veth_priv *peer_priv, *priv = netdev_priv(dev);
278+
struct net_device *peer;
279+
280+
if (new_hr < 0)
281+
new_hr = 0;
282+
283+
rcu_read_lock();
284+
peer = rcu_dereference(priv->peer);
285+
if (unlikely(!peer))
286+
goto out;
287+
288+
peer_priv = netdev_priv(peer);
289+
priv->requested_headroom = new_hr;
290+
new_hr = max(priv->requested_headroom, peer_priv->requested_headroom);
291+
dev->needed_headroom = new_hr;
292+
peer->needed_headroom = new_hr;
293+
294+
out:
295+
rcu_read_unlock();
296+
}
297+
274298
static const struct net_device_ops veth_netdev_ops = {
275299
.ndo_init = veth_dev_init,
276300
.ndo_open = veth_open,
@@ -285,6 +309,7 @@ static const struct net_device_ops veth_netdev_ops = {
285309
#endif
286310
.ndo_get_iflink = veth_get_iflink,
287311
.ndo_features_check = passthru_features_check,
312+
.ndo_set_rx_headroom = veth_set_rx_headroom,
288313
};
289314

290315
#define VETH_FEATURES (NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_ALL_TSO | \
@@ -301,6 +326,7 @@ static void veth_setup(struct net_device *dev)
301326
dev->priv_flags &= ~IFF_TX_SKB_SHARING;
302327
dev->priv_flags |= IFF_LIVE_ADDR_CHANGE;
303328
dev->priv_flags |= IFF_NO_QUEUE;
329+
dev->priv_flags |= IFF_PHONY_HEADROOM;
304330

305331
dev->netdev_ops = &veth_netdev_ops;
306332
dev->ethtool_ops = &veth_ethtool_ops;

0 commit comments

Comments
 (0)