Skip to contentSkip to conversation

TSQ accounting skb->truesize degrades throughput for large packets

PATCH Applied Wei Liu 7 participants 34 messages Sep 6, 2013 – Oct 1, 2013

Subsystems (3)
lore
Share & tools
lore

Wei Liu

author
#0 lore raw

Hi Eric

I have some questions regarding TSQ and I hope you can shed some light on this.

Our observation is that with the default TSQ limit (128K), throughput for Xen network driver for large packets degrades. That's because we now only have 1 packet in queue.

I double-checked that skb->len is indeed <64K. Then I discovered that TSQ actually accounts for skb->truesize and the packets generated had skb->truesize > 64K which effectively prevented us from putting 2 packets in queue.

There seems to be no way to limit skb->truesize inside driver -- the skb is already constructed when it comes to xen-netfront.

My questions are:
1) I see the comment in tcp_output.c saying: "TSQ : sk_wmem_alloc accounts skb truesize, including skb overhead. But thats OK", I don't quite understand why it is OK.
2) presumably other drivers will suffer from this as well, is it

     possible to account for skb->len instead of skb->truesize?

3) if accounting skb->truesize is on purpose, does that mean we only need to tune that value instead of trying to fix our driver (if there is a way to)?

Thanks
Wei.

#1 lore raw
Quoted 9 lines · Wei Liu

Hi Eric

I have some questions regarding TSQ and I hope you can shed some light on this.

Our observation is that with the default TSQ limit (128K), throughput for Xen network driver for large packets degrades. That's because we now only have 1 packet in queue.

Quoted 8 lines

I double-checked that skb->len is indeed <64K. Then I discovered that TSQ actually accounts for skb->truesize and the packets generated had skb->truesize > 64K which effectively prevented us from putting 2 packets in queue.

There seems to be no way to limit skb->truesize inside driver -- the skb is already constructed when it comes to xen-netfront.

What is the skb->truesize value then ? It must be huge, and its clearly a problem, because the tcp _receiver_ will also grow its window slower, if packet is looped back.

Quoted 6 lines

My questions are:
1) I see the comment in tcp_output.c saying: "TSQ : sk_wmem_alloc accounts skb truesize, including skb overhead. But thats OK", I don't quite understand why it is OK.
2) presumably other drivers will suffer from this as well, is it

     possible to account for skb->len instead of skb->truesize?

Well, I have no problem to get line rate on 20Gb with a single flow, so other drivers have no problem.

Quoted 3 lines

3) if accounting skb->truesize is on purpose, does that mean we only need to tune that value instead of trying to fix our driver (if there is a way to)?

The check in TCP allows for two packets at least, unless a single skb truesize is 128K ?

if (atomic_read(&sk->sk_wmem_alloc) >= sysctl_tcp_limit_output_bytes) {
    set_bit(TSQ_THROTTLED, &tp->tsq_flags);
    break;
}

So if a skb->truesize is 100K, this condition allows two packets, before throttling the third packet.

Its actually hard to account for skb->len, because sk_wmem_alloc accounts for skb->truesize : I do not want to add another sk->sk_wbytes_alloc new atomic field.

#33 lore raw
In reply to Wei Liu
Quoted 9 lines · Wei Liu

Hi Eric

I have some questions regarding TSQ and I hope you can shed some light on this.

Our observation is that with the default TSQ limit (128K), throughput for Xen network driver for large packets degrades. That's because we now only have 1 packet in queue.

Quoted 8 lines

I double-checked that skb->len is indeed <64K. Then I discovered that TSQ actually accounts for skb->truesize and the packets generated had skb->truesize > 64K which effectively prevented us from putting 2 packets in queue.

There seems to be no way to limit skb->truesize inside driver -- the skb is already constructed when it comes to xen-netfront.

What is the skb->truesize value then ? It must be huge, and its clearly a problem, because the tcp _receiver_ will also grow its window slower, if packet is looped back.

Quoted 6 lines

My questions are:
1) I see the comment in tcp_output.c saying: "TSQ : sk_wmem_alloc accounts skb truesize, including skb overhead. But thats OK", I don't quite understand why it is OK.
2) presumably other drivers will suffer from this as well, is it

     possible to account for skb->len instead of skb->truesize?

Well, I have no problem to get line rate on 20Gb with a single flow, so other drivers have no problem.

Quoted 3 lines

3) if accounting skb->truesize is on purpose, does that mean we only need to tune that value instead of trying to fix our driver (if there is a way to)?

The check in TCP allows for two packets at least, unless a single skb truesize is 128K ?

if (atomic_read(&sk->sk_wmem_alloc) >= sysctl_tcp_limit_output_bytes) {
    set_bit(TSQ_THROTTLED, &tp->tsq_flags);
    break;
}

So if a skb->truesize is 100K, this condition allows two packets, before throttling the third packet.

Its actually hard to account for skb->len, because sk_wmem_alloc accounts for skb->truesize : I do not want to add another sk->sk_wbytes_alloc new atomic field.

author
#2 lore raw
In reply to Eric Dumazet
Quoted 15 lines · Eric Dumazet
Quoted 14 lines · Wei Liu

Hi Eric

I have some questions regarding TSQ and I hope you can shed some light on this.

Our observation is that with the default TSQ limit (128K), throughput for Xen network driver for large packets degrades. That's because we now only have 1 packet in queue.

I double-checked that skb->len is indeed <64K. Then I discovered that TSQ actually accounts for skb->truesize and the packets generated had skb->truesize > 64K which effectively prevented us from putting 2 packets in queue.

Quoted 8 lines
Quoted 3 lines

There seems to be no way to limit skb->truesize inside driver -- the skb is already constructed when it comes to xen-netfront.

What is the skb->truesize value then ? It must be huge, and its clearly a problem, because the tcp _receiver_ will also grow its window slower, if packet is looped back.

It's ~66KB.

Quoted 10 lines
Quoted 6 lines

My questions are:
1) I see the comment in tcp_output.c saying: "TSQ : sk_wmem_alloc accounts skb truesize, including skb overhead. But thats OK", I don't quite understand why it is OK.
2) presumably other drivers will suffer from this as well, is it

     possible to account for skb->len instead of skb->truesize?

Well, I have no problem to get line rate on 20Gb with a single flow, so other drivers have no problem.

OK, good to know this.

Quoted 8 lines
Quoted 3 lines

3) if accounting skb->truesize is on purpose, does that mean we only need to tune that value instead of trying to fix our driver (if there is a way to)?

The check in TCP allows for two packets at least, unless a single skb truesize is 128K ?

Quoted 8 lines
if (atomic_read(&sk->sk_wmem_alloc) >= sysctl_tcp_limit_output_bytes) {
    set_bit(TSQ_THROTTLED, &tp->tsq_flags);
    break;
}

So if a skb->truesize is 100K, this condition allows two packets, before throttling the third packet.

OK. I need to check why we're getting only 1 then.

Thanks for your reply.

Wei.

Quoted 5 lines

Its actually hard to account for skb->len, because sk_wmem_alloc accounts for skb->truesize : I do not want to add another sk->sk_wbytes_alloc new atomic field.

author
#3 lore raw
In reply to Eric Dumazet
Quoted 15 lines · Eric Dumazet
Quoted 14 lines · Wei Liu

Hi Eric

I have some questions regarding TSQ and I hope you can shed some light on this.

Our observation is that with the default TSQ limit (128K), throughput for Xen network driver for large packets degrades. That's because we now only have 1 packet in queue.

I double-checked that skb->len is indeed <64K. Then I discovered that TSQ actually accounts for skb->truesize and the packets generated had skb->truesize > 64K which effectively prevented us from putting 2 packets in queue.

Quoted 8 lines
Quoted 3 lines

There seems to be no way to limit skb->truesize inside driver -- the skb is already constructed when it comes to xen-netfront.

What is the skb->truesize value then ? It must be huge, and its clearly a problem, because the tcp _receiver_ will also grow its window slower, if packet is looped back.

It's ~66KB.

Quoted 10 lines
Quoted 6 lines

My questions are:
1) I see the comment in tcp_output.c saying: "TSQ : sk_wmem_alloc accounts skb truesize, including skb overhead. But thats OK", I don't quite understand why it is OK.
2) presumably other drivers will suffer from this as well, is it

     possible to account for skb->len instead of skb->truesize?

Well, I have no problem to get line rate on 20Gb with a single flow, so other drivers have no problem.

OK, good to know this.

Quoted 8 lines
Quoted 3 lines

3) if accounting skb->truesize is on purpose, does that mean we only need to tune that value instead of trying to fix our driver (if there is a way to)?

The check in TCP allows for two packets at least, unless a single skb truesize is 128K ?

Quoted 8 lines
if (atomic_read(&sk->sk_wmem_alloc) >= sysctl_tcp_limit_output_bytes) {
    set_bit(TSQ_THROTTLED, &tp->tsq_flags);
    break;
}

So if a skb->truesize is 100K, this condition allows two packets, before throttling the third packet.

OK. I need to check why we're getting only 1 then.

Thanks for your reply.

Wei.

Quoted 5 lines

Its actually hard to account for skb->len, because sk_wmem_alloc accounts for skb->truesize : I do not want to add another sk->sk_wbytes_alloc new atomic field.

#4 lore raw
In reply to Eric Dumazet
Quoted 2 lines · Eric Dumazet

Well, I have no problem to get line rate on 20Gb with a single flow, so other drivers have no problem.

I've made some tests on bare metal:
Dell PE R815, Intel 82599EB 10Gb, 3.11-rc4 32 bit kernel with 3.17.3 ixgbe (TSO, GSO on), iperf 2.0.5
Transmitting packets toward the remote end (so running iperf -c on this host) can make 8.3 Gbps with the default 128k tcp_limit_output_bytes. When I increased this to 131.506 (128k + 434 bytes) suddenly it jumped to 9.4 Gbps. Iperf CPU usage also jumped a few percent from ~36 to ~40% (softint percentage in top also increased from ~3 to ~5%) So I guess it would be good to revisit the default value of this setting. What hw you used Eric for your 20Gb results?

Regards,

Zoli

#32 lore raw
In reply to Eric Dumazet
Quoted 2 lines · Eric Dumazet

Well, I have no problem to get line rate on 20Gb with a single flow, so other drivers have no problem.

I've made some tests on bare metal:
Dell PE R815, Intel 82599EB 10Gb, 3.11-rc4 32 bit kernel with 3.17.3 ixgbe (TSO, GSO on), iperf 2.0.5
Transmitting packets toward the remote end (so running iperf -c on this host) can make 8.3 Gbps with the default 128k tcp_limit_output_bytes. When I increased this to 131.506 (128k + 434 bytes) suddenly it jumped to 9.4 Gbps. Iperf CPU usage also jumped a few percent from ~36 to ~40% (softint percentage in top also increased from ~3 to ~5%) So I guess it would be good to revisit the default value of this setting. What hw you used Eric for your 20Gb results?

Regards,

Zoli

Acked-by Amir Vadai
#5 lore raw
In reply to Zoltan Kiss
Quoted 11 lines · Zoltan Kiss
Quoted 2 lines · Eric Dumazet

Well, I have no problem to get line rate on 20Gb with a single flow, so other drivers have no problem.

I've made some tests on bare metal:
Dell PE R815, Intel 82599EB 10Gb, 3.11-rc4 32 bit kernel with 3.17.3 ixgbe (TSO, GSO on), iperf 2.0.5
Transmitting packets toward the remote end (so running iperf -c on this host) can make 8.3 Gbps with the default 128k tcp_limit_output_bytes. When I increased this to 131.506 (128k + 434 bytes) suddenly it jumped to 9.4 Gbps. Iperf CPU usage also jumped a few percent from ~36 to ~40% (softint percentage in top also increased from ~3 to ~5%)

Typical tradeoff between latency and throughput

If you favor throughput, then you can increase tcp_limit_output_bytes

The default is quite reasonable IMHO.

Quoted 2 lines

So I guess it would be good to revisit the default value of this setting. What hw you used Eric for your 20Gb results?

Mellanox CX-3

Make sure your NIC doesn't hold TX packets in TX ring too long before signaling an interrupt for TX completion.

For example I had to patch mellanox :

commit ecfd2ce1a9d5e6376ff5c00b366345160abdbbb7

Author: Eric Dumazet <[email protected]>
Date:   Mon Nov 5 16:20:42 2012 +0000

mlx4: change TX coalescing defaults

mlx4 currently uses a too high tx coalescing setting, deferring TX completion interrupts by up to 128 us.

With the recent skb_orphan() removal in commit 8112ec3b872, performance of a single TCP flow is capped to ~4 Gbps, unless we increase tcp_limit_output_bytes.

I suggest using 16 us instead of 128 us, allowing a finer control.

Performance of a single TCP flow is restored to previous levels, while keeping TCP small queues fully enabled with default sysctl.

This patch is also a BQL prereq.

Acked-by Amir Vadai
#14 lore raw
In reply to Zoltan Kiss
Quoted 11 lines · Zoltan Kiss
Quoted 2 lines · Eric Dumazet

Well, I have no problem to get line rate on 20Gb with a single flow, so other drivers have no problem.

I've made some tests on bare metal:
Dell PE R815, Intel 82599EB 10Gb, 3.11-rc4 32 bit kernel with 3.17.3 ixgbe (TSO, GSO on), iperf 2.0.5
Transmitting packets toward the remote end (so running iperf -c on this host) can make 8.3 Gbps with the default 128k tcp_limit_output_bytes. When I increased this to 131.506 (128k + 434 bytes) suddenly it jumped to 9.4 Gbps. Iperf CPU usage also jumped a few percent from ~36 to ~40% (softint percentage in top also increased from ~3 to ~5%)

Typical tradeoff between latency and throughput

If you favor throughput, then you can increase tcp_limit_output_bytes

The default is quite reasonable IMHO.

Quoted 2 lines

So I guess it would be good to revisit the default value of this setting. What hw you used Eric for your 20Gb results?

Mellanox CX-3

Make sure your NIC doesn't hold TX packets in TX ring too long before signaling an interrupt for TX completion.

For example I had to patch mellanox :

commit ecfd2ce1a9d5e6376ff5c00b366345160abdbbb7

Author: Eric Dumazet <[email protected]>
Date:   Mon Nov 5 16:20:42 2012 +0000

mlx4: change TX coalescing defaults

mlx4 currently uses a too high tx coalescing setting, deferring TX completion interrupts by up to 128 us.

With the recent skb_orphan() removal in commit 8112ec3b872, performance of a single TCP flow is capped to ~4 Gbps, unless we increase tcp_limit_output_bytes.

I suggest using 16 us instead of 128 us, allowing a finer control.

Performance of a single TCP flow is restored to previous levels, while keeping TCP small queues fully enabled with default sysctl.

This patch is also a BQL prereq.

#15 lore raw
In reply to Zoltan Kiss
Quoted 2 lines · Zoltan Kiss

So I guess it would be good to revisit the default value of this setting.

If ixgbe requires 3 TSO packets in TX ring to get line rate, you also can tweak dev->gso_max_size from 65535 to 64000.

#31 lore raw
In reply to Zoltan Kiss
Quoted 2 lines · Zoltan Kiss

So I guess it would be good to revisit the default value of this setting.

If ixgbe requires 3 TSO packets in TX ring to get line rate, you also can tweak dev->gso_max_size from 65535 to 64000.

#16 lore raw
In reply to Eric Dumazet
Quoted 7 lines · Eric Dumazet
Quoted 2 lines · Zoltan Kiss

So I guess it would be good to revisit the default value of this setting.

If ixgbe requires 3 TSO packets in TX ring to get line rate, you also can tweak dev->gso_max_size from 65535 to 64000.

Another idea would be to no longer use tcp_limit_output_bytes but

max(sk_pacing_rate / 1000, 2*MSS)

This means that number of packets in FQ would be limited to the equivalent of 1ms, so TCP could have faster response to packet losses :

Retransmitted packets would not have to wait for prior packets being drained from FQ

For a 8Gbps flow, 1Gbyte/s, sk_pacing_rate would be 2Gbyte, this would translate to ~2 Mbytes in Qdisc/TX ring.

sk_pacing_rate was introduced in linux-3.12, but could be backported easily.

#29 lore raw
In reply to Eric Dumazet
Quoted 7 lines · Eric Dumazet
Quoted 2 lines · Zoltan Kiss

So I guess it would be good to revisit the default value of this setting.

If ixgbe requires 3 TSO packets in TX ring to get line rate, you also can tweak dev->gso_max_size from 65535 to 64000.

Another idea would be to no longer use tcp_limit_output_bytes but

max(sk_pacing_rate / 1000, 2*MSS)

This means that number of packets in FQ would be limited to the equivalent of 1ms, so TCP could have faster response to packet losses :

Retransmitted packets would not have to wait for prior packets being drained from FQ

For a 8Gbps flow, 1Gbyte/s, sk_pacing_rate would be 2Gbyte, this would translate to ~2 Mbytes in Qdisc/TX ring.

sk_pacing_rate was introduced in linux-3.12, but could be backported easily.

#30 lore raw
In reply to Eric Dumazet
Quoted 8 lines · Eric Dumazet
Quoted 2 lines · Zoltan Kiss

So I guess it would be good to revisit the default value of this setting.

If ixgbe requires 3 TSO packets in TX ring to get line rate, you also can tweak dev->gso_max_size from 65535 to 64000.

We observe similar regression on ixgbe driver, also virtio_net driver.

#6 lore raw
In reply to Eric Dumazet
Quoted 16 lines · Eric Dumazet
Quoted 11 lines · Zoltan Kiss
Quoted 2 lines · Eric Dumazet

Well, I have no problem to get line rate on 20Gb with a single flow, so other drivers have no problem.

I've made some tests on bare metal:
Dell PE R815, Intel 82599EB 10Gb, 3.11-rc4 32 bit kernel with 3.17.3 ixgbe (TSO, GSO on), iperf 2.0.5
Transmitting packets toward the remote end (so running iperf -c on this host) can make 8.3 Gbps with the default 128k tcp_limit_output_bytes. When I increased this to 131.506 (128k + 434 bytes) suddenly it jumped to 9.4 Gbps. Iperf CPU usage also jumped a few percent from ~36 to ~40% (softint percentage in top also increased from ~3 to ~5%)

Typical tradeoff between latency and throughput

If you favor throughput, then you can increase tcp_limit_output_bytes

Quoted 8 lines

The default is quite reasonable IMHO.

Quoted 2 lines

So I guess it would be good to revisit the default value of this setting. What hw you used Eric for your 20Gb results?

Mellanox CX-3

Make sure your NIC doesn't hold TX packets in TX ring too long before signaling an interrupt for TX completion.

Virtio-net orphan the skb in .ndo_start_xmit() so TSQ can not throttle packets in device accurately, and it also can't do BQL. Does this means TSQ should be disabled for virtio-net?

#13 lore raw
In reply to Eric Dumazet
Quoted 16 lines · Eric Dumazet
Quoted 11 lines · Zoltan Kiss
Quoted 2 lines · Eric Dumazet

Well, I have no problem to get line rate on 20Gb with a single flow, so other drivers have no problem.

I've made some tests on bare metal:
Dell PE R815, Intel 82599EB 10Gb, 3.11-rc4 32 bit kernel with 3.17.3 ixgbe (TSO, GSO on), iperf 2.0.5
Transmitting packets toward the remote end (so running iperf -c on this host) can make 8.3 Gbps with the default 128k tcp_limit_output_bytes. When I increased this to 131.506 (128k + 434 bytes) suddenly it jumped to 9.4 Gbps. Iperf CPU usage also jumped a few percent from ~36 to ~40% (softint percentage in top also increased from ~3 to ~5%)

Typical tradeoff between latency and throughput

If you favor throughput, then you can increase tcp_limit_output_bytes

Quoted 8 lines

The default is quite reasonable IMHO.

Quoted 2 lines

So I guess it would be good to revisit the default value of this setting. What hw you used Eric for your 20Gb results?

Mellanox CX-3

Make sure your NIC doesn't hold TX packets in TX ring too long before signaling an interrupt for TX completion.

Virtio-net orphan the skb in .ndo_start_xmit() so TSQ can not throttle packets in device accurately, and it also can't do BQL. Does this means TSQ should be disabled for virtio-net?

#7 lore raw
In reply to Jason Wang
Quoted 4 lines · Jason Wang

Virtio-net orphan the skb in .ndo_start_xmit() so TSQ can not throttle packets in device accurately, and it also can't do BQL. Does this means TSQ should be disabled for virtio-net?

If skb are orphaned, there is no way TSQ can work at all.

It is already disabled, so why do you want to disable it ?

#12 lore raw
In reply to Jason Wang
Quoted 4 lines · Jason Wang

Virtio-net orphan the skb in .ndo_start_xmit() so TSQ can not throttle packets in device accurately, and it also can't do BQL. Does this means TSQ should be disabled for virtio-net?

If skb are orphaned, there is no way TSQ can work at all.

It is already disabled, so why do you want to disable it ?

#17 lore raw
In reply to Eric Dumazet
Quoted 6 lines · Eric Dumazet
Quoted 5 lines · Eric Dumazet
Quoted 2 lines · Zoltan Kiss

So I guess it would be good to revisit the default value of this setting.

Quoted 6 lines
Quoted 2 lines

If ixgbe requires 3 TSO packets in TX ring to get line rate, you also can tweak dev->gso_max_size from 65535 to 64000.

Another idea would be to no longer use tcp_limit_output_bytes but

max(sk_pacing_rate / 1000, 2*MSS)

I've tried this on a freshly updated upstream, and it solved my problem on ixgbe:

- if (atomic_read(&sk->sk_wmem_alloc) >= sysctl_tcp_limit_output_bytes) {
+ if (atomic_read(&sk->sk_wmem_alloc) >= max(sk->sk_pacing_rate / 1000, 2 * mss_now) ){

Now I can get proper line rate. Btw. I've tried to decrease dev->gso_max_size to 60K or 32K, both was ineffective.

Regards,

Zoli

#28 lore raw
In reply to Eric Dumazet
Quoted 6 lines · Eric Dumazet
Quoted 5 lines · Eric Dumazet
Quoted 2 lines · Zoltan Kiss

So I guess it would be good to revisit the default value of this setting.

Quoted 6 lines
Quoted 2 lines

If ixgbe requires 3 TSO packets in TX ring to get line rate, you also can tweak dev->gso_max_size from 65535 to 64000.

Another idea would be to no longer use tcp_limit_output_bytes but

max(sk_pacing_rate / 1000, 2*MSS)

I've tried this on a freshly updated upstream, and it solved my problem on ixgbe:

- if (atomic_read(&sk->sk_wmem_alloc) >= sysctl_tcp_limit_output_bytes) {
+ if (atomic_read(&sk->sk_wmem_alloc) >= max(sk->sk_pacing_rate / 1000, 2 * mss_now) ){

Now I can get proper line rate. Btw. I've tried to decrease dev->gso_max_size to 60K or 32K, both was ineffective.

Regards,

Zoli

#18 lore raw
In reply to Zoltan Kiss
Quoted 17 lines · Zoltan Kiss
Quoted 6 lines · Eric Dumazet
Quoted 5 lines · Eric Dumazet
Quoted 2 lines · Zoltan Kiss

So I guess it would be good to revisit the default value of this setting.

Quoted 6 lines
Quoted 2 lines

If ixgbe requires 3 TSO packets in TX ring to get line rate, you also can tweak dev->gso_max_size from 65535 to 64000.

Another idea would be to no longer use tcp_limit_output_bytes but

max(sk_pacing_rate / 1000, 2*MSS)

I've tried this on a freshly updated upstream, and it solved my problem on ixgbe:

Quoted 7 lines

- if (atomic_read(&sk->sk_wmem_alloc) >=
sysctl_tcp_limit_output_bytes) {
+ if (atomic_read(&sk->sk_wmem_alloc) >=
max(sk->sk_pacing_rate / 1000, 2 * mss_now) ){

Now I can get proper line rate. Btw. I've tried to decrease dev->gso_max_size to 60K or 32K, both was ineffective.

Yeah, my own test was more like the following

net/ipv4/tcp_output.c +2 -1
index 7c83cb8..07dc77a 100644
@@ -1872,7 +1872,8 @@ static bool tcp_write_xmit(struct sock *sk, unsigned int mss_now, int nonagle,
 		/* TSQ : sk_wmem_alloc accounts skb truesize,
 		 * including skb overhead. But thats OK.
 		 */
-		if (atomic_read(&sk->sk_wmem_alloc) >= sysctl_tcp_limit_output_bytes) {
+		if (atomic_read(&sk->sk_wmem_alloc) >= max(2 * mss_now,
+							   sk->sk_pacing_rate >> 8)) {
 			set_bit(TSQ_THROTTLED, &tp->tsq_flags);
 			break;
 		}

Note that it also seems to make Hystart happier.

I will send patches when all tests are green.

#27 lore raw
In reply to Zoltan Kiss
Quoted 17 lines · Zoltan Kiss
Quoted 6 lines · Eric Dumazet
Quoted 5 lines · Eric Dumazet
Quoted 2 lines · Zoltan Kiss

So I guess it would be good to revisit the default value of this setting.

Quoted 6 lines
Quoted 2 lines

If ixgbe requires 3 TSO packets in TX ring to get line rate, you also can tweak dev->gso_max_size from 65535 to 64000.

Another idea would be to no longer use tcp_limit_output_bytes but

max(sk_pacing_rate / 1000, 2*MSS)

I've tried this on a freshly updated upstream, and it solved my problem on ixgbe:

Quoted 7 lines

- if (atomic_read(&sk->sk_wmem_alloc) >=
sysctl_tcp_limit_output_bytes) {
+ if (atomic_read(&sk->sk_wmem_alloc) >=
max(sk->sk_pacing_rate / 1000, 2 * mss_now) ){

Now I can get proper line rate. Btw. I've tried to decrease dev->gso_max_size to 60K or 32K, both was ineffective.

Yeah, my own test was more like the following

net/ipv4/tcp_output.c +2 -1
index 7c83cb8..07dc77a 100644
@@ -1872,7 +1872,8 @@ static bool tcp_write_xmit(struct sock *sk, unsigned int mss_now, int nonagle,
 		/* TSQ : sk_wmem_alloc accounts skb truesize,
 		 * including skb overhead. But thats OK.
 		 */
-		if (atomic_read(&sk->sk_wmem_alloc) >= sysctl_tcp_limit_output_bytes) {
+		if (atomic_read(&sk->sk_wmem_alloc) >= max(2 * mss_now,
+							   sk->sk_pacing_rate >> 8)) {
 			set_bit(TSQ_THROTTLED, &tp->tsq_flags);
 			break;
 		}

Note that it also seems to make Hystart happier.

I will send patches when all tests are green.

#8 lore raw
In reply to Eric Dumazet
Quoted 7 lines · Eric Dumazet
Quoted 4 lines · Jason Wang

Virtio-net orphan the skb in .ndo_start_xmit() so TSQ can not throttle packets in device accurately, and it also can't do BQL. Does this means TSQ should be disabled for virtio-net?

If skb are orphaned, there is no way TSQ can work at all.

For example, virtio-net will stop the tx queue when it finds the tx queue may full and enable the queue when some packets were sent. In this case, tsq works and throttles the total bytes queued in qdisc. This usually happen during heavy network load such as two sessions of netperf.

Quoted 4 lines

It is already disabled, so why do you want to disable it ?

We notice a regression, and bisect shows it was introduced by TSQ.

#11 lore raw
In reply to Eric Dumazet
Quoted 7 lines · Eric Dumazet
Quoted 4 lines · Jason Wang

Virtio-net orphan the skb in .ndo_start_xmit() so TSQ can not throttle packets in device accurately, and it also can't do BQL. Does this means TSQ should be disabled for virtio-net?

If skb are orphaned, there is no way TSQ can work at all.

For example, virtio-net will stop the tx queue when it finds the tx queue may full and enable the queue when some packets were sent. In this case, tsq works and throttles the total bytes queued in qdisc. This usually happen during heavy network load such as two sessions of netperf.

Quoted 4 lines

It is already disabled, so why do you want to disable it ?

We notice a regression, and bisect shows it was introduced by TSQ.

#9 lore raw
In reply to Jason Wang
Quoted 4 lines · Jason Wang

For example, virtio-net will stop the tx queue when it finds the tx queue may full and enable the queue when some packets were sent. In this case, tsq works and throttles the total bytes queued in qdisc. This usually happen during heavy network load such as two sessions of netperf.

You told me skb were _orphaned_.

This automatically _disables_ TSQ, after packets leave Qdisc.

So you have a problem because your skb orphaning is only working when packets leave Qdisc.

If you cant afford sockets being throttled, make sure you have no Qdisc !

Quoted 1 line

We notice a regression, and bisect shows it was introduced by TSQ.

You do realize TSQ is a balance between throughput and latencies ?

In case of TSQ, it was very clear that limiting amount of outstanding bytes in queues could have an impact on bandwidth.

Pushing Megabytes of TCP packets with identical TCP timestamps is bad, because it prevents us doing delay based congestion control and a single flow could fill the Qdisc with a thousand of packets. (Self induced delays, see BufferBloat discussions)

One known problem in TCP stack is that sendmsg() locks the socket for the duration of the call. sendpage() do not have this problem.

tcp_tsq_handler() is deferred if tcp_tasklet_func() finds a locked socket. The owner of socket will call tcp_tsq_handler() when socket is released.

So if you use sendmsg() with large buffers or if copyin data from user land involves page faults, it may explain why you need larger number of in-flight bytes to sustain a given throughput.

You could take a look at commit c9bee3b7fdecb0c1d070c
("tcp: TCP_NOTSENT_LOWAT socket option"), and play
with /proc/sys/net/ipv4/tcp_notsent_lowat, to force sendmsg() to release the socket lock every hundreds of kbytes.

#10 lore raw
In reply to Jason Wang
Quoted 4 lines · Jason Wang

For example, virtio-net will stop the tx queue when it finds the tx queue may full and enable the queue when some packets were sent. In this case, tsq works and throttles the total bytes queued in qdisc. This usually happen during heavy network load such as two sessions of netperf.

You told me skb were _orphaned_.

This automatically _disables_ TSQ, after packets leave Qdisc.

So you have a problem because your skb orphaning is only working when packets leave Qdisc.

If you cant afford sockets being throttled, make sure you have no Qdisc !

Quoted 1 line

We notice a regression, and bisect shows it was introduced by TSQ.

You do realize TSQ is a balance between throughput and latencies ?

In case of TSQ, it was very clear that limiting amount of outstanding bytes in queues could have an impact on bandwidth.

Pushing Megabytes of TCP packets with identical TCP timestamps is bad, because it prevents us doing delay based congestion control and a single flow could fill the Qdisc with a thousand of packets. (Self induced delays, see BufferBloat discussions)

One known problem in TCP stack is that sendmsg() locks the socket for the duration of the call. sendpage() do not have this problem.

tcp_tsq_handler() is deferred if tcp_tasklet_func() finds a locked socket. The owner of socket will call tcp_tsq_handler() when socket is released.

So if you use sendmsg() with large buffers or if copyin data from user land involves page faults, it may explain why you need larger number of in-flight bytes to sustain a given throughput.

You could take a look at commit c9bee3b7fdecb0c1d070c
("tcp: TCP_NOTSENT_LOWAT socket option"), and play
with /proc/sys/net/ipv4/tcp_notsent_lowat, to force sendmsg() to release the socket lock every hundreds of kbytes.

#19 lore raw
In reply to Eric Dumazet
Quoted 3 lines · Eric Dumazet <eric.dumazet <at> gmail.com> writes:

Yeah, my own test was more like the following

...

Quoted 5 lines

Note that it also seems to make Hystart happier.

I will send patches when all tests are green.

How is this going? I don't see any patch posted to netdev.

Thanks!

author
#20 lore raw
Quoted 5 lines · Cong Wang
Quoted 3 lines · Eric Dumazet <eric.dumazet <at> gmail.com> writes:

Yeah, my own test was more like the following

Quoted 9 lines

...

Quoted 5 lines

Note that it also seems to make Hystart happier.

I will send patches when all tests are green.

How is this going? I don't see any patch posted to netdev.

I'm afraid you forgot to CC any relevant people in thie email. :-)

Wei.

Quoted 8 lines

Thanks!

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#21 lore raw
Quoted 10 lines · Wei Liu
Quoted 9 lines · Cong Wang
Quoted 3 lines · Eric Dumazet <eric.dumazet <at> gmail.com> writes:

Yeah, my own test was more like the following

...

Quoted 3 lines

Note that it also seems to make Hystart happier.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

I will send patches when all tests are green.

How is this going? I don't see any patch posted to netdev.

I'm afraid you forgot to CC any relevant people in thie email. :-)

I was replying via newsgroup, not mailing list. :)

Anyway, adding Eric and netdev now.

#22 lore raw
Quoted 4 lines · Cong Wang

I was replying via newsgroup, not mailing list. :)

Anyway, adding Eric and netdev now.

Yes, dont worry, this will be done on Monday or Tuesday.

I am still in New Orleans after LPC 2013.

#23 lore raw

PATCH 1/1 tcp: TSQ can use a dynamic limit

From: Eric Dumazet <[email protected]>

When TCP Small Queues was added, we used a sysctl to limit amount of packets queues on Qdisc/device queues for a given TCP flow.

Problem is this limit is either too big for low rates, or too small for high rates.

Now TCP stack has rate estimation in sk->sk_pacing_rate, and TSO auto sizing, it can better control number of packets in Qdisc/device queues.

New limit is two packets or at least 1 to 2 ms worth of packets.

Low rates flows benefit from this patch by having even smaller number of packets in queues, allowing for faster recovery, better RTT estimations.

High rates flows benefit from this patch by allowing more than 2 packets in flight as we had reports this was a limiting factor to reach line rate. [ In particular if TX completion is delayed because of coalescing parameters ]

Example for a single flow on 10Gbp link controlled by FQ/pacing

14 packets in flight instead of 2

$ tc -s -d qd
qdisc fq 8001: dev eth0 root refcnt 32 limit 10000p flow_limit 100p
buckets 1024 quantum 3028 initial_quantum 15140 
 Sent 1168459366606 bytes 771822841 pkt (dropped 0, overlimits 0
requeues 6822476) 
 rate 9346Mbit 771713pps backlog 953820b 14p requeues 6822476 
  2047 flow, 2046 inactive, 1 throttled, delay 15673 ns
  2372 gc, 0 highprio, 0 retrans, 9739249 throttled, 0 flows_plimit

Note that sk_pacing_rate is currently set to twice the actual rate, but this might be refined in the future when a flow is in congestion avoidance.

Additional change : skb->destructor should be set to tcp_wfree().

A future patch (for linux 3.13+) might remove tcp_limit_output_bytes

Cc Wei Liu <[email protected]>
Cc Cong Wang <[email protected]>
Cc Yuchung Cheng <[email protected]>
Cc Neal Cardwell <[email protected]>
---
 net/ipv4/tcp_output.c |   17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
net/ipv4/tcp_output.c +11 -6
index 7c83cb8..c20e406 100644
@@ -895,8 +895,7 @@ static int tcp_transmit_skb(struct sock *sk, struct sk_buff *skb, int clone_it,
 
 	skb_orphan(skb);
 	skb->sk = sk;
-	skb->destructor = (sysctl_tcp_limit_output_bytes > 0) ?
-			  tcp_wfree : sock_wfree;
+	skb->destructor = tcp_wfree;
 	atomic_add(skb->truesize, &sk->sk_wmem_alloc);
 
 	/* Build TCP header and checksum it. */
@@ -1840,7 +1839,6 @@ static bool tcp_write_xmit(struct sock *sk, unsigned int mss_now, int nonagle,
 	while ((skb = tcp_send_head(sk))) {
 		unsigned int limit;
 
-
 		tso_segs = tcp_init_tso_segs(sk, skb, mss_now);
 		BUG_ON(!tso_segs);
 
@@ -1869,13 +1867,20 @@ static bool tcp_write_xmit(struct sock *sk, unsigned int mss_now, int nonagle,
 				break;
 		}
 
-		/* TSQ : sk_wmem_alloc accounts skb truesize,
-		 * including skb overhead. But thats OK.
+		/* TCP Small Queues :
+		 * Control number of packets in qdisc/devices to two packets / or ~1 ms.
+		 * This allows for :
+		 *  - better RTT estimation and ACK scheduling
+		 *  - faster recovery
+		 *  - high rates
 		 */
-		if (atomic_read(&sk->sk_wmem_alloc) >= sysctl_tcp_limit_output_bytes) {
+		limit = max(skb->truesize, sk->sk_pacing_rate >> 10);
+
+		if (atomic_read(&sk->sk_wmem_alloc) > limit) {
 			set_bit(TSQ_THROTTLED, &tp->tsq_flags);
 			break;
 		}
+
 		limit = mss_now;
 		if (tso_segs > 1 && !tcp_urg_mode(tp))
 			limit = tcp_mss_split_point(sk, skb, mss_now,
maintainer Acked-by on v1 1/1
#24 lore raw

Re: [PATCH] tcp: TSQ can use a dynamic limit

Quoted 42 lines · Eric Dumazet

From: Eric Dumazet <[email protected]>

When TCP Small Queues was added, we used a sysctl to limit amount of packets queues on Qdisc/device queues for a given TCP flow.

Problem is this limit is either too big for low rates, or too small for high rates.

Now TCP stack has rate estimation in sk->sk_pacing_rate, and TSO auto sizing, it can better control number of packets in Qdisc/device queues.

New limit is two packets or at least 1 to 2 ms worth of packets.

Low rates flows benefit from this patch by having even smaller number of packets in queues, allowing for faster recovery, better RTT estimations.

High rates flows benefit from this patch by allowing more than 2 packets in flight as we had reports this was a limiting factor to reach line rate. [ In particular if TX completion is delayed because of coalescing parameters ]

Example for a single flow on 10Gbp link controlled by FQ/pacing

14 packets in flight instead of 2

$ tc -s -d qd
qdisc fq 8001: dev eth0 root refcnt 32 limit 10000p flow_limit 100p
buckets 1024 quantum 3028 initial_quantum 15140
 Sent 1168459366606 bytes 771822841 pkt (dropped 0, overlimits 0
requeues 6822476)
 rate 9346Mbit 771713pps backlog 953820b 14p requeues 6822476
  2047 flow, 2046 inactive, 1 throttled, delay 15673 ns
  2372 gc, 0 highprio, 0 retrans, 9739249 throttled, 0 flows_plimit

Note that sk_pacing_rate is currently set to twice the actual rate, but this might be refined in the future when a flow is in congestion avoidance.

Additional change : skb->destructor should be set to tcp_wfree().

Quoted 8 lines

A future patch (for linux 3.13+) might remove tcp_limit_output_bytes

Cc Wei Liu <[email protected]>
Cc Cong Wang <[email protected]>
Cc Yuchung Cheng <[email protected]>
Cc Neal Cardwell <[email protected]>

---

neal

#25 lore raw

Re: [PATCH] tcp: TSQ can use a dynamic limit

In reply to Eric Dumazet
Quoted 4 lines · Eric Dumazet

Additional change : skb->destructor should be set to tcp_wfree().

A future patch (for linux 3.13+) might remove tcp_limit_output_bytes

Yeah, now it is only used in tcp_xmit_size_goal()...

maintainer Applied
#26 lore raw

Re: [PATCH] tcp: TSQ can use a dynamic limit

In reply to Eric Dumazet

From: Eric Dumazet <[email protected]>
Date: Fri, 27 Sep 2013 03:28:54 -0700

Quoted 40 lines

From: Eric Dumazet <[email protected]>

When TCP Small Queues was added, we used a sysctl to limit amount of packets queues on Qdisc/device queues for a given TCP flow.

Problem is this limit is either too big for low rates, or too small for high rates.

Now TCP stack has rate estimation in sk->sk_pacing_rate, and TSO auto sizing, it can better control number of packets in Qdisc/device queues.

New limit is two packets or at least 1 to 2 ms worth of packets.

Low rates flows benefit from this patch by having even smaller number of packets in queues, allowing for faster recovery, better RTT estimations.

High rates flows benefit from this patch by allowing more than 2 packets in flight as we had reports this was a limiting factor to reach line rate. [ In particular if TX completion is delayed because of coalescing parameters ]

Example for a single flow on 10Gbp link controlled by FQ/pacing

14 packets in flight instead of 2

$ tc -s -d qd
qdisc fq 8001: dev eth0 root refcnt 32 limit 10000p flow_limit 100p
buckets 1024 quantum 3028 initial_quantum 15140 
 Sent 1168459366606 bytes 771822841 pkt (dropped 0, overlimits 0
requeues 6822476) 
 rate 9346Mbit 771713pps backlog 953820b 14p requeues 6822476 
  2047 flow, 2046 inactive, 1 throttled, delay 15673 ns
  2372 gc, 0 highprio, 0 retrans, 9739249 throttled, 0 flows_plimit

Note that sk_pacing_rate is currently set to twice the actual rate, but this might be refined in the future when a flow is in congestion avoidance.

Quoted 5 lines

Additional change : skb->destructor should be set to tcp_wfree().

A future patch (for linux 3.13+) might remove tcp_limit_output_bytes

Applied, thanks Eric.