Skip to content

Commit 93f154b

Browse files
Eric Dumazetdavem330
authored andcommitted
net: release dst entry in dev_hard_start_xmit()
One point of contention in high network loads is the dst_release() performed when a transmited skb is freed. This is because NIC tx completion calls dev_kree_skb() long after original call to dev_queue_xmit(skb). CPU cache is cold and the atomic op in dst_release() stalls. On SMP, this is quite visible if one CPU is 100% handling softirqs for a network device, since dst_clone() is done by other cpus, involving cache line ping pongs. It seems right place to release dst is in dev_hard_start_xmit(), for most devices but ones that are virtual, and some exceptions. David Miller suggested to define a new device flag, set in alloc_netdev_mq() (so that most devices set it at init time), and carefuly unset in devices which dont want a NULL skb->dst in their ndo_start_xmit(). List of devices that must clear this flag is : - loopback device, because it calls netif_rx() and quoting Patrick : "ip_route_input() doesn't accept loopback addresses, so loopback packets already need to have a dst_entry attached." - appletalk/ipddp.c : needs skb->dst in its xmit function - And all devices that call again dev_queue_xmit() from their xmit function (as some classifiers need skb->dst) : bonding, vlan, macvlan, eql, ifb, hdlc_fr Signed-off-by: Eric Dumazet <dada1@cosmosbay.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 496a60c commit 93f154b

10 files changed

Lines changed: 20 additions & 0 deletions

File tree

‎drivers/net/appletalk/ipddp.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ static struct net_device * __init ipddp_init(void)
7171
if (!dev)
7272
return ERR_PTR(-ENOMEM);
7373

74+
dev->priv_flags &= ~IFF_XMIT_DST_RELEASE;
7475
strcpy(dev->name, "ipddp%d");
7576

7677
if (version_printed++ == 0)

‎drivers/net/bonding/bond_main.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5148,6 +5148,7 @@ int bond_create(char *name, struct bond_params *params)
51485148
goto out_rtnl;
51495149
}
51505150

5151+
bond_dev->priv_flags &= ~IFF_XMIT_DST_RELEASE;
51515152
if (!name) {
51525153
res = dev_alloc_name(bond_dev, "bond%d");
51535154
if (res < 0)

‎drivers/net/eql.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ static void __init eql_setup(struct net_device *dev)
194194

195195
dev->type = ARPHRD_SLIP;
196196
dev->tx_queue_len = 5; /* Hands them off fast */
197+
dev->priv_flags &= ~IFF_XMIT_DST_RELEASE;
197198
}
198199

199200
static int eql_open(struct net_device *dev)

‎drivers/net/ifb.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ static void ifb_setup(struct net_device *dev)
156156

157157
dev->flags |= IFF_NOARP;
158158
dev->flags &= ~IFF_MULTICAST;
159+
dev->priv_flags &= ~IFF_XMIT_DST_RELEASE;
159160
random_ether_addr(dev->dev_addr);
160161
}
161162

‎drivers/net/loopback.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ static void loopback_setup(struct net_device *dev)
170170
dev->tx_queue_len = 0;
171171
dev->type = ARPHRD_LOOPBACK; /* 0x0001*/
172172
dev->flags = IFF_LOOPBACK;
173+
dev->priv_flags &= ~IFF_XMIT_DST_RELEASE;
173174
dev->features = NETIF_F_SG | NETIF_F_FRAGLIST
174175
| NETIF_F_TSO
175176
| NETIF_F_NO_CSUM

‎drivers/net/macvlan.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ static void macvlan_setup(struct net_device *dev)
414414
{
415415
ether_setup(dev);
416416

417+
dev->priv_flags &= ~IFF_XMIT_DST_RELEASE;
417418
dev->netdev_ops = &macvlan_netdev_ops;
418419
dev->destructor = free_netdev;
419420
dev->header_ops = &macvlan_hard_header_ops,

‎drivers/net/wan/hdlc_fr.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,7 @@ static void pvc_setup(struct net_device *dev)
10541054
dev->flags = IFF_POINTOPOINT;
10551055
dev->hard_header_len = 10;
10561056
dev->addr_len = 2;
1057+
dev->priv_flags &= ~IFF_XMIT_DST_RELEASE;
10571058
}
10581059

10591060
static const struct net_device_ops pvc_ops = {

‎include/linux/if.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@
6767
#define IFF_ISATAP 0x80 /* ISATAP interface (RFC4214) */
6868
#define IFF_MASTER_ARPMON 0x100 /* bonding master, ARP mon in use */
6969
#define IFF_WAN_HDLC 0x200 /* WAN HDLC device */
70+
#define IFF_XMIT_DST_RELEASE 0x400 /* dev_hard_start_xmit() is allowed to
71+
* release skb->dst
72+
*/
7073

7174
#define IF_GET_IFACE 0x0001 /* for querying only */
7275
#define IF_GET_PROTO 0x0002

‎net/8021q/vlan_dev.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,7 @@ void vlan_setup(struct net_device *dev)
739739
ether_setup(dev);
740740

741741
dev->priv_flags |= IFF_802_1Q_VLAN;
742+
dev->priv_flags &= ~IFF_XMIT_DST_RELEASE;
742743
dev->tx_queue_len = 0;
743744

744745
dev->netdev_ops = &vlan_netdev_ops;

‎net/core/dev.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,6 +1688,14 @@ int dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev,
16881688
goto gso;
16891689
}
16901690

1691+
/*
1692+
* If device doesnt need skb->dst, release it right now while
1693+
* its hot in this cpu cache
1694+
*/
1695+
if ((dev->priv_flags & IFF_XMIT_DST_RELEASE) && skb->dst) {
1696+
dst_release(skb->dst);
1697+
skb->dst = NULL;
1698+
}
16911699
rc = ops->ndo_start_xmit(skb, dev);
16921700
/*
16931701
* TODO: if skb_orphan() was called by
@@ -5045,6 +5053,7 @@ struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name,
50455053
netdev_init_queues(dev);
50465054

50475055
INIT_LIST_HEAD(&dev->napi_list);
5056+
dev->priv_flags = IFF_XMIT_DST_RELEASE;
50485057
setup(dev);
50495058
strcpy(dev->name, name);
50505059
return dev;

0 commit comments

Comments
 (0)