Skip to contentSkip to conversation

Slow speed of tcp connections in a network namespace

PATCH Applied Andrew Vagin 5 participants 16 messages Dec 29, 2012 – Dec 30, 2012

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

We found a few nodes, where network works slow in containers.

For testing speed of TCP connections we use wget, which downloads iso images from the internet.

wget in the new netns reports only 1.5 MB/s, but wget in the root netns reports 33MB/s.

A few facts:
* Experiments shows that window size for CT traffic does not increases up to ~900, however for host traffic window size increases up to ~14000
* packets are shuffled in the netns sometimes.
* tso/gro/gso changes on interfaces does not help
* issue was _NOT_ reproduced if kernel booted with maxcpus=1 or bnx2.disable_msi=1

I reduced steps to reproduce:
* Create a new network namespace "test" and a veth pair.

  # ip netns add test
  # ip link add name veth0 type veth peer name veth1

* Move veth1 into the netns test

  # ip link set veth1 netns test

* Set ip address on veth1 and proper routing rules are added for this ip in the root netns.

  # ip link set up dev veth0;  ip link set up dev veth0
  # ip netns exec test ip a add REMOTE dev veth1
  # ip netns exec test ip r a default via veth1
  # ip r a REMOTE/32 via dev veth0

Tcpdump for both cases are attached to this message. tcpdump.host - wget in the root netns
tcpdump.netns.host - tcpdump for the host device, wget in the new netns tcpdump.netns.veth - tcpdump for the veth1 device, wget in the new netns

3.8-rc1 is used for experiments.

Do you have any ideas where is a problem?

#1 lore raw
Quoted 30 lines · Andrew Vagin

We found a few nodes, where network works slow in containers.

For testing speed of TCP connections we use wget, which downloads iso images from the internet.

wget in the new netns reports only 1.5 MB/s, but wget in the root netns reports 33MB/s.

A few facts:
* Experiments shows that window size for CT traffic does not increases up to ~900, however for host traffic window size increases up to ~14000
* packets are shuffled in the netns sometimes.
* tso/gro/gso changes on interfaces does not help
* issue was _NOT_ reproduced if kernel booted with maxcpus=1 or bnx2.disable_msi=1

I reduced steps to reproduce:
* Create a new network namespace "test" and a veth pair.

  # ip netns add test
  # ip link add name veth0 type veth peer name veth1

* Move veth1 into the netns test

  # ip link set veth1 netns test

* Set ip address on veth1 and proper routing rules are added for this ip in the root netns.

  # ip link set up dev veth0;  ip link set up dev veth0
  # ip netns exec test ip a add REMOTE dev veth1
  # ip netns exec test ip r a default via veth1
  # ip r a REMOTE/32 via dev veth0
Quoted 8 lines

Tcpdump for both cases are attached to this message. tcpdump.host - wget in the root netns
tcpdump.netns.host - tcpdump for the host device, wget in the new netns tcpdump.netns.veth - tcpdump for the veth1 device, wget in the new netns

3.8-rc1 is used for experiments.

Do you have any ideas where is a problem?

veth has absolutely no offload features

It needs some care...

At the very miminum, let TCP coalesce do its job by allowing SG

CC Michał Mirosław <[email protected]> for insights.

Please try following patch :

drivers/net/veth.c +6 -1
index 95814d9..9fefeb3 100644
@@ -259,6 +259,10 @@ static const struct net_device_ops veth_netdev_ops = {
 	.ndo_set_mac_address = eth_mac_addr,
 };
 
+#define VETH_FEATURES (NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO |	\
+		       NETIF_F_HW_CSUM | NETIF_F_HIGHDMA |		\
+		       NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX)
+
 static void veth_setup(struct net_device *dev)
 {
 	ether_setup(dev);
@@ -269,9 +273,10 @@ static void veth_setup(struct net_device *dev)
 	dev->netdev_ops = &veth_netdev_ops;
 	dev->ethtool_ops = &veth_ethtool_ops;
 	dev->features |= NETIF_F_LLTX;
+	dev->features |= VETH_FEATURES;
 	dev->destructor = veth_dev_free;
 
-	dev->hw_features = NETIF_F_HW_CSUM | NETIF_F_SG | NETIF_F_RXCSUM;
+	dev->hw_features = VETH_FEATURES;
 }
 
 /*
#2 lore raw
Quoted 6 lines · Eric Dumazet
Quoted 3 lines

3.8-rc1 is used for experiments.

Do you have any ideas where is a problem?

veth has absolutely no offload features

Quoted 7 lines

It needs some care...

At the very miminum, let TCP coalesce do its job by allowing SG

CC Michał Mirosław <[email protected]> for insights.

Please try following patch :

Hello Eric,

Thanks for your feedback.

With this patch the results is a bit better (~4MB/s), but it's much less than in the root netns.

Quoted 30 lines
drivers/net/veth.c +6 -1
index 95814d9..9fefeb3 100644
@@ -259,6 +259,10 @@ static const struct net_device_ops veth_netdev_ops = {
 	.ndo_set_mac_address = eth_mac_addr,
 };
 
+#define VETH_FEATURES (NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO |	\
+		       NETIF_F_HW_CSUM | NETIF_F_HIGHDMA |		\
+		       NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX)
+
 static void veth_setup(struct net_device *dev)
 {
 	ether_setup(dev);
@@ -269,9 +273,10 @@ static void veth_setup(struct net_device *dev)
 	dev->netdev_ops = &veth_netdev_ops;
 	dev->ethtool_ops = &veth_ethtool_ops;
 	dev->features |= NETIF_F_LLTX;
+	dev->features |= VETH_FEATURES;
 	dev->destructor = veth_dev_free;
 
-	dev->hw_features = NETIF_F_HW_CSUM | NETIF_F_SG | NETIF_F_RXCSUM;
+	dev->hw_features = VETH_FEATURES;
 }
 
 /*
#3 lore raw
Quoted 13 lines · Andrew Vagin
Quoted 12 lines · Eric Dumazet
Quoted 3 lines

3.8-rc1 is used for experiments.

Do you have any ideas where is a problem?

veth has absolutely no offload features

It needs some care...

At the very miminum, let TCP coalesce do its job by allowing SG

CC Michał Mirosław <[email protected]> for insights.

Quoted 8 lines
Quoted 1 line

Please try following patch :

Hello Eric,

Thanks for your feedback.

With this patch the results is a bit better (~4MB/s), but it's much less than in the root netns.

Please post your new tcpdump then ;)

also post "netstat -s" from root and test ns after your wgets

#4 lore raw
Quoted 16 lines · Eric Dumazet
Quoted 15 lines · Andrew Vagin
Quoted 13 lines · Eric Dumazet
Quoted 3 lines

3.8-rc1 is used for experiments.

Do you have any ideas where is a problem?

veth has absolutely no offload features

It needs some care...

At the very miminum, let TCP coalesce do its job by allowing SG

CC Michał Mirosław <[email protected]> for insights.

Please try following patch :

Quoted 8 lines
Quoted 6 lines

Hello Eric,

Thanks for your feedback.

With this patch the results is a bit better (~4MB/s), but it's much less than in the root netns.

Please post your new tcpdump then ;)

I have rebooted the host and a speed in a netns is again about 1.7MB/s. I don't know why it was 4MB/s in the previous time.

new tcpdump and netstat are attached

Quoted 5 lines

also post "netstat -s" from root and test ns after your wgets

Ip:
277536 total packets received
20 forwarded
0 incoming packets discarded
202326 incoming packets delivered
108228 requests sent out
30 dropped because of missing route
Icmp:
10 ICMP messages received
0 input ICMP message failed.
ICMP input histogram:
destination unreachable: 5
echo requests: 5
6 ICMP messages sent
0 ICMP messages failed
ICMP output histogram:
destination unreachable: 1
echo replies: 5
IcmpMsg:

        InType3: 5
        InType8: 5
        OutType0: 5
        OutType3: 1

Tcp:
1491 active connections openings
12 passive connection openings
14 failed connection attempts
72 connection resets received
2 connections established
201920 segments received
107815 segments send out
0 segments retransmited
0 bad segments received.
1338 resets sent
Udp:
387 packets received
0 packets to unknown port received.
0 packet receive errors
389 packets sent
UdpLite:
TcpExt:
3 invalid SYN cookies received
4 TCP sockets finished time wait in fast timer 63 delayed acks sent
9 delayed acks further delayed because of locked socket 236 packets directly queued to recvmsg prequeue. 38600456 packets directly received from backlog 298101 packets directly received from prequeue 163501 packets header predicted
27103 packets header predicted and directly queued to user 2578 acknowledgments not containing data received 1018 predicted acknowledgments
15 connections reset due to unexpected data
72 connections reset due to early user close
TCPRcvCoalesce: 123
TCPOFOQueue: 1187
IpExt:

    InBcastPkts: 9
    OutBcastPkts: 1
    InOctets: 296395504
    OutOctets: 6965311
    InBcastOctets: 2789
    OutBcastOctets: 165

Ip:
25483 total packets received
0 forwarded
0 incoming packets discarded
25483 incoming packets delivered
14572 requests sent out
Icmp:
4 ICMP messages received
0 input ICMP message failed.
ICMP input histogram:
echo requests: 2
echo replies: 2
4 ICMP messages sent
0 ICMP messages failed
ICMP output histogram:
echo request: 2
echo replies: 2
IcmpMsg:

        InType0: 2
        InType8: 2
        OutType0: 2
        OutType8: 2

Tcp:
1 active connections openings
0 passive connection openings
0 failed connection attempts
0 connection resets received
0 connections established
25473 segments received
14562 segments send out
0 segments retransmited
0 bad segments received.
77 resets sent
Udp:
6 packets received
0 packets to unknown port received.
0 packet receive errors
6 packets sent
UdpLite:
TcpExt:
38 delayed acks sent
Quick ack mode was activated 2 times
52 packets directly queued to recvmsg prequeue. 4916752 packets directly received from backlog 11584 packets directly received from prequeue 12538 packets header predicted
2649 packets header predicted and directly queued to user 1 acknowledgments not containing data received 2 DSACKs sent for old packets
1 connections reset due to unexpected data
TCPOFOQueue: 1580
IpExt:

    InOctets: 38201843
    OutOctets: 829966
#5 lore raw
In reply to Eric Dumazet
Quoted 4 lines · Eric Dumazet

Please post your new tcpdump then ;)

also post "netstat -s" from root and test ns after your wgets

Also try following bnx2 patch.

It should help GRO / TCP coalesce

bnx2 should be the last driver not using skb head_frag

drivers/net/ethernet/broadcom/bnx2.c +20 -5
index a1adfaf..08a2d40 100644
@@ -2726,6 +2726,14 @@ bnx2_free_rx_page(struct bnx2 *bp, struct bnx2_rx_ring_info *rxr, u16 index)
 	rx_pg->page = NULL;
 }
 
+static void bnx2_frag_free(const struct bnx2 *bp, void *data)
+{
+	if (bp->rx_frag_size)
+		put_page(virt_to_head_page(data));
+	else
+		kfree(data);
+}
+
 static inline int
 bnx2_alloc_rx_data(struct bnx2 *bp, struct bnx2_rx_ring_info *rxr, u16 index, gfp_t gfp)
 {
@@ -2735,7 +2743,10 @@ bnx2_alloc_rx_data(struct bnx2 *bp, struct bnx2_rx_ring_info *rxr, u16 index, gf
 	struct bnx2_rx_bd *rxbd =
 		&rxr->rx_desc_ring[BNX2_RX_RING(index)][BNX2_RX_IDX(index)];
 
-	data = kmalloc(bp->rx_buf_size, gfp);
+	if (bp->rx_frag_size)
+		data = netdev_alloc_frag(bp->rx_frag_size);
+	else
+		data = kmalloc(bp->rx_buf_size, gfp);
 	if (!data)
 		return -ENOMEM;
 
@@ -2744,7 +2755,7 @@ bnx2_alloc_rx_data(struct bnx2 *bp, struct bnx2_rx_ring_info *rxr, u16 index, gf
 				 bp->rx_buf_use_size,
 				 PCI_DMA_FROMDEVICE);
 	if (dma_mapping_error(&bp->pdev->dev, mapping)) {
-		kfree(data);
+		bnx2_frag_free(bp, data);
 		return -EIO;
 	}
 
@@ -3014,9 +3025,9 @@ error:
 
 	dma_unmap_single(&bp->pdev->dev, dma_addr, bp->rx_buf_use_size,
 			 PCI_DMA_FROMDEVICE);
-	skb = build_skb(data, 0);
+	skb = build_skb(data, bp->rx_frag_size);
 	if (!skb) {
-		kfree(data);
+		bnx2_frag_free(bp, data);
 		goto error;
 	}
 	skb_reserve(skb, ((u8 *)get_l2_fhdr(data) - data) + BNX2_RX_OFFSET);
@@ -5358,6 +5369,10 @@ bnx2_set_rx_ring_size(struct bnx2 *bp, u32 size)
 	/* hw alignment + build_skb() overhead*/
 	bp->rx_buf_size = SKB_DATA_ALIGN(bp->rx_buf_use_size + BNX2_RX_ALIGN) +
 		NET_SKB_PAD + SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
+	if (bp->rx_buf_size <= PAGE_SIZE)
+		bp->rx_frag_size = bp->rx_buf_size;
+	else
+		bp->rx_frag_size = 0;
 	bp->rx_jumbo_thresh = rx_size - BNX2_RX_OFFSET;
 	bp->rx_ring_size = size;
 	bp->rx_max_ring = bnx2_find_max_ring(size, BNX2_MAX_RX_RINGS);
@@ -5436,7 +5451,7 @@ bnx2_free_rx_skbs(struct bnx2 *bp)
 
 			rx_buf->data = NULL;
 
-			kfree(data);
+			bnx2_frag_free(bp, data);
 		}
 		for (j = 0; j < bp->rx_max_pg_ring_idx; j++)
 			bnx2_free_rx_page(bp, rxr, j);
drivers/net/ethernet/broadcom/bnx2.h +1 -0
index 172efbe..11f5dee 100644
@@ -6804,6 +6804,7 @@ struct bnx2 {
 
 	u32			rx_buf_use_size;	/* useable size */
 	u32			rx_buf_size;		/* with alignment */
+	u32			rx_frag_size; /* 0 if kmalloced(), or rx_buf_size */
 	u32			rx_copy_thresh;
 	u32			rx_jumbo_thresh;
 	u32			rx_max_ring_idx;
#6 lore raw
Quoted 5 lines · Eric Dumazet
Quoted 3 lines · Eric Dumazet

Please post your new tcpdump then ;)

Quoted 7 lines
Quoted 1 line

also post "netstat -s" from root and test ns after your wgets

Also try following bnx2 patch.

It should help GRO / TCP coalesce

bnx2 should be the last driver not using skb head_frag

And of course, you should make sure all your bnx2 interrupts are handled by the same cpu.

Or else, packets might be reordered because the way dev_forward_skb() works.

(CPU X gets a bunch of packets from eth0, forward them via netif_rx() in the local CPU X queue, NAPI is ended on eth0)

CPU Y gets a bunch of packets from eth0, forward them via netif_rx() in the local CPU Y queue.

CPU X and Y process their local queue in // -> packets are delivered Out of order to TCP stack

Alternative is to setup RPS on your veth1 device, to force packets being delivered/handled by a given cpu

#7 lore raw
Quoted 6 lines · Eric Dumazet
Quoted 5 lines · Eric Dumazet
Quoted 3 lines · Eric Dumazet

Please post your new tcpdump then ;)

Quoted 7 lines
Quoted 7 lines
Quoted 1 line

also post "netstat -s" from root and test ns after your wgets

Also try following bnx2 patch.

It should help GRO / TCP coalesce

bnx2 should be the last driver not using skb head_frag

I don't have access to the host. I'm going to test your patch tomorrow. Thanks.

Quoted 3 lines

And of course, you should make sure all your bnx2 interrupts are handled by the same cpu.

All bnx interrupts are handled on all cpus. They are handled on the same cpu, if a kernel is booted with msi_disable=1.

Is it right, that a received window will be less, if packets are not sorted? Looks like a bug.

I want to say, that probably it works correctly, if packets are sorted. But I think if packets are not sorted, it should work with the same speed, cpu load and memory consumption may be a bit more.

Quoted 20 lines

Or else, packets might be reordered because the way dev_forward_skb() works.

(CPU X gets a bunch of packets from eth0, forward them via netif_rx() in the local CPU X queue, NAPI is ended on eth0)

CPU Y gets a bunch of packets from eth0, forward them via netif_rx() in the local CPU Y queue.

CPU X and Y process their local queue in // -> packets are delivered Out of order to TCP stack

Alternative is to setup RPS on your veth1 device, to force packets being delivered/handled by a given cpu

#8 lore raw
Quoted 24 lines · Andrew Vagin
Quoted 6 lines · Eric Dumazet
Quoted 5 lines · Eric Dumazet
Quoted 3 lines · Eric Dumazet

Please post your new tcpdump then ;)

Quoted 7 lines
Quoted 7 lines
Quoted 1 line

also post "netstat -s" from root and test ns after your wgets

Also try following bnx2 patch.

It should help GRO / TCP coalesce

bnx2 should be the last driver not using skb head_frag

I don't have access to the host. I'm going to test your patch tomorrow. Thanks.

Quoted 3 lines

And of course, you should make sure all your bnx2 interrupts are handled by the same cpu.

All bnx interrupts are handled on all cpus. They are handled on the same cpu, if a kernel is booted with msi_disable=1.

Quoted 6 lines

Is it right, that a received window will be less, if packets are not sorted? Looks like a bug.

I want to say, that probably it works correctly, if packets are sorted. But I think if packets are not sorted, it should work with the same speed, cpu load and memory consumption may be a bit more.

Without veth, it doesnt really matter that IRQ are spread on multiple cpus, because packets are handled in NAPI, and only one cpu runs the eth0 NAPI handler at one time.

But as soon as packets are queued (by netif_rx()) for 'later' processing, you can have dramatic performance decrease.

Thats why you really should make sure IRQ on your eth0 device are handled by a single cpu.

It will help to get better performance in most cases.

echo 1 >/proc/irq/*/eth0/../smp_affinity

If it doesnt work, you might try instead :

echo 1 >/proc/irq/default_smp_affinity
<you might need to reload bnx2 module, or ifdown/ifup eth0 >

#9 lore raw
Quoted 36 lines · Eric Dumazet
Quoted 24 lines · Andrew Vagin
Quoted 6 lines · Eric Dumazet
Quoted 5 lines · Eric Dumazet
Quoted 3 lines · Eric Dumazet

Please post your new tcpdump then ;)

Quoted 7 lines
Quoted 7 lines
Quoted 1 line

also post "netstat -s" from root and test ns after your wgets

Also try following bnx2 patch.

It should help GRO / TCP coalesce

bnx2 should be the last driver not using skb head_frag

I don't have access to the host. I'm going to test your patch tomorrow. Thanks.

Quoted 3 lines

And of course, you should make sure all your bnx2 interrupts are handled by the same cpu.

All bnx interrupts are handled on all cpus. They are handled on the same cpu, if a kernel is booted with msi_disable=1.

Quoted 6 lines

Is it right, that a received window will be less, if packets are not sorted? Looks like a bug.

I want to say, that probably it works correctly, if packets are sorted. But I think if packets are not sorted, it should work with the same speed, cpu load and memory consumption may be a bit more.

Without veth, it doesnt really matter that IRQ are spread on multiple cpus, because packets are handled in NAPI, and only one cpu runs the eth0 NAPI handler at one time.

Quoted 7 lines

But as soon as packets are queued (by netif_rx()) for 'later' processing, you can have dramatic performance decrease.

Thats why you really should make sure IRQ on your eth0 device are handled by a single cpu.

It will help to get better performance in most cases.

I understand this fact, but so big difference looks strange for me.

Default configuration (with the bug):

# cat /proc/interrupts  | grep eth0
  68:      10187      10188      10187      10023      10190      10185
10187      10019   PCI-MSI-edge      eth0
Quoted 2 lines

echo 1 >/proc/irq/*/eth0/../smp_affinity

This doesn't help.

I tryed echo 0 > /proc/irq/68/smp_affinity_list. This doesn't help too.

Quoted 5 lines

If it doesnt work, you might try instead :

echo 1 >/proc/irq/default_smp_affinity
<you might need to reload bnx2 module, or ifdown/ifup eth0 >

This helps, and the bug are not reproduced in this case.

# cat /proc/interrupts  | grep eth0
  68:      60777          0          0          0          0          0
0          0   PCI-MSI-edge      eth0

Thanks.

#10 lore raw
In reply to Andrew Vagin
Quoted 2 lines · Andrew Vagin

Is it right, that a received window will be less, if packets are not sorted? Looks like a bug.

Not really a bug.

TCP is very sensitive to packet reorders. I wont elaborate here as its a bit off topic.

Try to reorders credits/debits on your bank account, I am pretty sure you'll lose some money or even get serious troubles.

Of course, enabling GRO on eth0 would definitely help a bit...

(once/iff veth driver features are fixed to allow GSO packets being forwarded without being segmented again)

#11 lore raw
Quoted 10 lines · Eric Dumazet
Quoted 2 lines · Andrew Vagin

Is it right, that a received window will be less, if packets are not sorted? Looks like a bug.

Not really a bug.

TCP is very sensitive to packet reorders. I wont elaborate here as its a bit off topic.

Quoted 8 lines

Try to reorders credits/debits on your bank account, I am pretty sure you'll lose some money or even get serious troubles.

Of course, enabling GRO on eth0 would definitely help a bit...

(once/iff veth driver features are fixed to allow GSO packets being forwarded without being segmented again)

Eric, thank you for the help.
I need time for thinking. I will ask you, if new questions will appear.

Quoted 2 lines
#12 lore raw
In reply to Eric Dumazet
Quoted 5 lines · Eric Dumazet
Quoted 3 lines · Eric Dumazet

Please post your new tcpdump then ;)

Quoted 8 lines
Quoted 1 line

also post "netstat -s" from root and test ns after your wgets

Also try following bnx2 patch.

It should help GRO / TCP coalesce

bnx2 should be the last driver not using skb head_frag

This patch breaks nothing. I don't know what kind of profit I should get with it:).

FYI:
I forgot to say, that I disable gro before collecting tcpdump, because in this case tcpdump from veth and from eth0 can be compared easier.

Quoted 87 lines
drivers/net/ethernet/broadcom/bnx2.c +20 -5
index a1adfaf..08a2d40 100644
@@ -2726,6 +2726,14 @@ bnx2_free_rx_page(struct bnx2 *bp, struct bnx2_rx_ring_info *rxr, u16 index)
 	rx_pg->page = NULL;
 }
 
+static void bnx2_frag_free(const struct bnx2 *bp, void *data)
+{
+	if (bp->rx_frag_size)
+		put_page(virt_to_head_page(data));
+	else
+		kfree(data);
+}
+
 static inline int
 bnx2_alloc_rx_data(struct bnx2 *bp, struct bnx2_rx_ring_info *rxr, u16 index, gfp_t gfp)
 {
@@ -2735,7 +2743,10 @@ bnx2_alloc_rx_data(struct bnx2 *bp, struct bnx2_rx_ring_info *rxr, u16 index, gf
 	struct bnx2_rx_bd *rxbd =
 		&rxr->rx_desc_ring[BNX2_RX_RING(index)][BNX2_RX_IDX(index)];
 
-	data = kmalloc(bp->rx_buf_size, gfp);
+	if (bp->rx_frag_size)
+		data = netdev_alloc_frag(bp->rx_frag_size);
+	else
+		data = kmalloc(bp->rx_buf_size, gfp);
 	if (!data)
 		return -ENOMEM;
 
@@ -2744,7 +2755,7 @@ bnx2_alloc_rx_data(struct bnx2 *bp, struct bnx2_rx_ring_info *rxr, u16 index, gf
 				 bp->rx_buf_use_size,
 				 PCI_DMA_FROMDEVICE);
 	if (dma_mapping_error(&bp->pdev->dev, mapping)) {
-		kfree(data);
+		bnx2_frag_free(bp, data);
 		return -EIO;
 	}
 
@@ -3014,9 +3025,9 @@ error:
 
 	dma_unmap_single(&bp->pdev->dev, dma_addr, bp->rx_buf_use_size,
 			 PCI_DMA_FROMDEVICE);
-	skb = build_skb(data, 0);
+	skb = build_skb(data, bp->rx_frag_size);
 	if (!skb) {
-		kfree(data);
+		bnx2_frag_free(bp, data);
 		goto error;
 	}
 	skb_reserve(skb, ((u8 *)get_l2_fhdr(data) - data) + BNX2_RX_OFFSET);
@@ -5358,6 +5369,10 @@ bnx2_set_rx_ring_size(struct bnx2 *bp, u32 size)
 	/* hw alignment + build_skb() overhead*/
 	bp->rx_buf_size = SKB_DATA_ALIGN(bp->rx_buf_use_size + BNX2_RX_ALIGN) +
 		NET_SKB_PAD + SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
+	if (bp->rx_buf_size <= PAGE_SIZE)
+		bp->rx_frag_size = bp->rx_buf_size;
+	else
+		bp->rx_frag_size = 0;
 	bp->rx_jumbo_thresh = rx_size - BNX2_RX_OFFSET;
 	bp->rx_ring_size = size;
 	bp->rx_max_ring = bnx2_find_max_ring(size, BNX2_MAX_RX_RINGS);
@@ -5436,7 +5451,7 @@ bnx2_free_rx_skbs(struct bnx2 *bp)
 
 			rx_buf->data = NULL;
 
-			kfree(data);
+			bnx2_frag_free(bp, data);
 		}
 		for (j = 0; j < bp->rx_max_pg_ring_idx; j++)
 			bnx2_free_rx_page(bp, rxr, j);
drivers/net/ethernet/broadcom/bnx2.h +1 -0
index 172efbe..11f5dee 100644
@@ -6804,6 +6804,7 @@ struct bnx2 {
 
 	u32			rx_buf_use_size;	/* useable size */
 	u32			rx_buf_size;		/* with alignment */
+	u32			rx_frag_size; /* 0 if kmalloced(), or rx_buf_size */
 	u32			rx_copy_thresh;
 	u32			rx_jumbo_thresh;
 	u32			rx_max_ring_idx;
#13 lore raw
In reply to Eric Dumazet

2012/12/29 Eric Dumazet <[email protected]>:

Quoted 40 lines · Andrew Vagin
Quoted 30 lines

We found a few nodes, where network works slow in containers.

For testing speed of TCP connections we use wget, which downloads iso images from the internet.

wget in the new netns reports only 1.5 MB/s, but wget in the root netns reports 33MB/s.

A few facts:
* Experiments shows that window size for CT traffic does not increases up to ~900, however for host traffic window size increases up to ~14000
* packets are shuffled in the netns sometimes.
* tso/gro/gso changes on interfaces does not help
* issue was _NOT_ reproduced if kernel booted with maxcpus=1 or bnx2.disable_msi=1

I reduced steps to reproduce:
* Create a new network namespace "test" and a veth pair.

  # ip netns add test
  # ip link add name veth0 type veth peer name veth1

* Move veth1 into the netns test

  # ip link set veth1 netns test

* Set ip address on veth1 and proper routing rules are added for this ip in the root netns.

  # ip link set up dev veth0;  ip link set up dev veth0
  # ip netns exec test ip a add REMOTE dev veth1
  # ip netns exec test ip r a default via veth1
  # ip r a REMOTE/32 via dev veth0
Quoted 8 lines

Tcpdump for both cases are attached to this message. tcpdump.host - wget in the root netns
tcpdump.netns.host - tcpdump for the host device, wget in the new netns tcpdump.netns.veth - tcpdump for the veth1 device, wget in the new netns

3.8-rc1 is used for experiments.

Do you have any ideas where is a problem?

Quoted 7 lines

veth has absolutely no offload features

It needs some care...

At the very miminum, let TCP coalesce do its job by allowing SG

CC Michał Mirosław <[email protected]> for insights.

veth is just like a tunnel device. In terms of offloads, it can do anything we have software fallbacks for (in case packets get forwarded to real hardware).

Quoted 18 lines

Please try following patch :

drivers/net/veth.c +4 -0
index 95814d9..9fefeb3 100644
@@ -259,6 +259,10 @@ static const struct net_device_ops veth_netdev_ops = {
        .ndo_set_mac_address = eth_mac_addr,
 };
 
+#define VETH_FEATURES (NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_TSO |   \
+                      NETIF_F_HW_CSUM | NETIF_F_HIGHDMA |              \
+                      NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX)
+
 static void veth_setup(struct net_device *dev)
 {
        ether_setup(dev);

drivers/net/veth.c static void veth_setup(struct net_device *dev) · line 280

Quoted 9 lines
drivers/net/veth.c +2 -1
@@ -269,9 +273,10 @@ static void veth_setup(struct net_device *dev)
        dev->netdev_ops = &veth_netdev_ops;
        dev->ethtool_ops = &veth_ethtool_ops;
        dev->features |= NETIF_F_LLTX;
+       dev->features |= VETH_FEATURES;
        dev->destructor = veth_dev_free;
 
-       dev->hw_features = NETIF_F_HW_CSUM | NETIF_F_SG | NETIF_F_RXCSUM;
+       dev->hw_features = VETH_FEATURES;
 }

You missed NETIF_F_RXCSUM in VETH_FEATURES. We might support NETIF_F_ALL_TSO, not just the IPv4 version.

Best Regards,
Michał Mirosław

#14 lore raw

PATCH 1/1 veth: extend device features

From: Eric Dumazet <[email protected]>

veth is lacking most modern facilities, like SG, checksums, TSO.

It makes sense to extend dev->features to get them, or GRO aggregation is defeated by a forced segmentation.

---
 drivers/net/veth.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/net/veth.c +6 -1
index 95814d9..ccf211f 100644
@@ -259,6 +259,10 @@ static const struct net_device_ops veth_netdev_ops = {
 	.ndo_set_mac_address = eth_mac_addr,
 };
 
+#define VETH_FEATURES (NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_ALL_TSO |    \
+		       NETIF_F_HW_CSUM | NETIF_F_RXCSUM | NETIF_F_HIGHDMA | \
+		       NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX)
+
 static void veth_setup(struct net_device *dev)
 {
 	ether_setup(dev);
@@ -269,9 +273,10 @@ static void veth_setup(struct net_device *dev)
 	dev->netdev_ops = &veth_netdev_ops;
 	dev->ethtool_ops = &veth_ethtool_ops;
 	dev->features |= NETIF_F_LLTX;
+	dev->features |= VETH_FEATURES;
 	dev->destructor = veth_dev_free;
 
-	dev->hw_features = NETIF_F_HW_CSUM | NETIF_F_SG | NETIF_F_RXCSUM;
+	dev->hw_features = VETH_FEATURES;
 }
 
 /*
maintainer Applied
#15 lore raw

Re: [PATCH] veth: extend device features

From: Eric Dumazet <[email protected]>
Date: Sat, 29 Dec 2012 18:26:10 -0800

Quoted 10 lines

From: Eric Dumazet <[email protected]>

veth is lacking most modern facilities, like SG, checksums, TSO.

It makes sense to extend dev->features to get them, or GRO aggregation is defeated by a forced segmentation.

Applied.