: Add per-connection option to set max TSO frame size
Subsystems (4)
PATCH 1/1 : Add per-connection option to set max TSO frame size
Update: Made gso_max_size container 32 bits, not 16. Moved the location of gso_max_size within netdev to be less hotpath. Made more consistent names between the sock and netdev layers, and added a define for the max GSO size.
Update: Respun for net-2.6.26 tree.
Update: changed max_gso_frame_size and sk_gso_max_size from signed to unsigned - thanks Stephen!
This patch adds the ability for device drivers to control the size of the TSO frames being sent to them, per TCP connection. By setting the netdevice's gso_max_size value, the socket layer will set the GSO frame size based on that value. This will propogate into the TCP layer, and send TSO's of that size to the hardware.
This can be desirable to help tune the bursty nature of TSO on a per-adapter basis, where one may have 1 GbE and 10 GbE devices coexisting in a system, one running multiqueue and the other not, etc.
This can also be desirable for devices that cannot support full 64 KB TSO's, but still want to benefit from some level of segmentation offloading.
---
include/linux/netdevice.h | 9 +++++++++ include/net/sock.h | 2 ++ net/core/dev.c | 1 + net/core/sock.c | 6 ++++-- net/ipv4/tcp_output.c | 4 ++-- 5 files changed, 18 insertions(+), 4 deletions(-)
include/linux/netdevice.h +9 -0
@@ -724,6 +724,10 @@ struct net_device/* rtnetlink link ops */ const struct rtnl_link_ops *rtnl_link_ops; +/* for setting kernel sock attribute on TCP connection setup */ +#define GSO_MAX_SIZE 65536 +u32 gso_max_size; +/* The TX queue control structures */ unsigned int egress_subqueue_count;struct net_device_subqueue egress_subqueue[1 ];
@@ -1475,6 +1479,11 @@ static inline int netif_needs_gso(struct net_device *dev, struct sk_buff *skb) unlikely(skb->ip_summed != CHECKSUM_PARTIAL)); } +static inline void netif_set_gso_max_size (struct net_device *dev,u16 size) +{ + dev->gso_max_size = size; +} +/* On bonding slaves other than the currently active slave, suppress * duplicates except for 802.3ad ETH_P_SLOW, alb non-mcast/bcast, and * ARP on active-backup slaves with arp_validate enabled.
include/net/sock.h +2 -0
@@ -151,6 +151,7 @@ struct sock_common {* @sk_no_check: %SO_NO_CHECK setting, wether or not checkup packets * @sk_route_caps: route capabilities (e.g. %NETIF_F_TSO) * @sk_gso_type: GSO type (e.g. %SKB_GSO_TCPV4) +* @sk_gso_max_size: Maximum GSO segment size to build * @sk_lingertime: %SO_LINGER l_linger setting * @sk_backlog: always used with the per-socket spinlock held * @sk_callback_lock: used with the callbacks in the end of this struct
@@ -236,6 +237,7 @@ struct sock {gfp_t sk_allocation;int sk_route_caps;int sk_gso_type; +__u32 sk_gso_max_size;int sk_rcvlowat;unsigned long sk_flags;unsigned long sk_lingertime;
net/core/dev.c +1 -0
@@ -4021,6 +4021,7 @@ struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name, } dev->egress_subqueue_count = queue_count; + dev->gso_max_size =GSO_MAX_SIZE ; dev->get_stats = internal_stats;netpoll_netdev_init (dev);
net/core/sock.c +4 -2
@@ -1076,10 +1076,12 @@ void sk_setup_caps(struct sock *sk, struct dst_entry *dst)if (sk->sk_route_caps &NETIF_F_GSO ) sk->sk_route_caps |=NETIF_F_GSO_SOFTWARE ;if (sk_can_gso (sk)) { -if (dst->header_len) +if (dst->header_len) { sk->sk_route_caps &= ~NETIF_F_GSO_MASK ; -else + }else { sk->sk_route_caps |=NETIF_F_SG |NETIF_F_HW_CSUM ; + sk->sk_gso_max_size = dst->dev->gso_max_size; + } } }EXPORT_SYMBOL_GPL (sk_setup_caps);
net/ipv4/tcp_output.c +2 -2
@@ -998,7 +998,7 @@ unsigned int tcp_current_mss(struct sock *sk, int large_allowed) xmit_size_goal = mss_now;if (doing_tso) { - xmit_size_goal = (65535 - + xmit_size_goal = ((sk->sk_gso_max_size -1 ) -inet_csk (sk)->icsk_af_ops->net_header_len -inet_csk (sk)->icsk_ext_hdr_len - tp->tcp_header_len);
@@ -1274,7 +1274,7 @@ static int tcp_tso_should_defer(struct sock *sk, struct sk_buff *skb) limit =min (send_win, cong_win);/* If a full-sized TSO skb can be sent, do it. */ -if (limit >=65536 ) +if (limit >= sk->sk_gso_max_size) goto send_now;if (sysctl_tcp_tso_win_divisor) {
On Thu, Feb 28, 2008 at 10:31:50AM -0800, PJ Waskiewicz wrote:
...
Looks ...almost OK to me, but:
include/linux/netdevice.h struct net_device · line 730
Quoted 12 lines
include/linux/netdevice.h +4
-0@@ -724,6 +724,10 @@ struct net_device/* rtnetlink link ops */ const struct rtnl_link_ops *rtnl_link_ops; +/* for setting kernel sock attribute on TCP connection setup */ +#define GSO_MAX_SIZE 65536 +u32 gso_max_size; +
Now probably unsigned int should "suffice" too.
include/linux/netdevice.h static inline int netif_needs_gso(struct net_device *dev, struct sk_buff *skb) · line 1482
Quoted 8 lines
include/linux/netdevice.h +1
-0/* The TX queue control structures */ unsigned int egress_subqueue_count;struct net_device_subqueue egress_subqueue[1 ];@@ -1475,6 +1479,11 @@ static inline int netif_needs_gso(struct net_device *dev, struct sk_buff *skb) unlikely(skb->ip_summed != CHECKSUM_PARTIAL)); } +static inline void netif_set_gso_max_size (struct net_device *dev,u16 size)
u16?
include/linux/netdevice.h static inline int netif_needs_gso(struct net_device *dev, struct sk_buff *skb) · line 1484
Quoted 2 lines
include/linux/netdevice.h +2
-0+{ + dev->gso_max_size = size;
^^^^^^^^^^ a tab needed here.
...
Quoted 4 lines
include/net/sock.h +0
-0
...
include/net/sock.h struct sock { · line 240
Quoted 5 lines
include/net/sock.h +1
-0@@ -236,6 +237,7 @@ struct sock {gfp_t sk_allocation;int sk_route_caps;int sk_gso_type; +__u32 sk_gso_max_size;
unsigned int? But, actually I wonder if sk_gso_type and sk_gso_max_size can't be two shorts yet?
Regards,
Jarek P.
PJ Waskiewicz wrote, On 02/28/2008 07:31 PM:
...
Quoted 7 lines
This can be desirable to help tune the bursty nature of TSO on a per-adapter basis, where one may have 1 GbE and 10 GbE devices coexisting in a system, one running multiqueue and the other not, etc.
This can also be desirable for devices that cannot support full 64 KB TSO's, but still want to benefit from some level of segmentation offloading.
...
Quoted 1 line
+++
b/include/linux/netdevice.h
...
include/linux/netdevice.h struct net_device · line 729
Quoted 3 lines
include/linux/netdevice.h +3
-0+/* for setting kernel sock attribute on TCP connection setup */ +#define GSO_MAX_SIZE 65536 +u32 gso_max_size;
One more, maybe foolish, thrifty idea: do we really need such a precision here? I don't know those devices, but maybe it would be enough (for the beginning at least?) to use a few divisors e.g.:
gso_max_size = 65536 >> GSO_MAX_SIZE_SHIFT
Then it seems 3 or 4 bits should be enough for this, and BTW, it looks like dev->features has 16 bits for various GSO flags, with "a lot" of free space yet - unless I missed something?
Jarek P.
On Fri, Feb 29, 2008 at 09:46:50PM +0100, Jarek Poplawski wrote:
...
Quoted 3 lines
gso_max_size= 65536 >>GSO_MAX_SIZE_SHIFTThen it seems 3 or 4 bits should be enough for this, and BTW, it looks
...Hm... 2 or 3 bits!
Jarek P.
RE: [PATCH] [NET 2.6.26]: Add per-connection option to set max TSOframe size
In reply to Jarek PoplawskiQuoted 11 lines
Quoted 1 line
+++
b/include/linux/netdevice.h...
include/linux/netdevice.h struct net_device · line 729
Quoted 3 lines
include/linux/netdevice.h +3
-0+/* for setting kernel sock attribute on TCP connection setup */ +#define GSO_MAX_SIZE 65536 +u32 gso_max_size;One more, maybe foolish, thrifty idea: do we really need such a precision here? I don't know those devices, but maybe it would be enough (for the beginning at least?) to use a few divisors e.g.:
Quoted 5 lines
gso_max_size= 65536 >>GSO_MAX_SIZE_SHIFTThen it seems 3 or 4 bits should be enough for this, and BTW, it looks like
dev->featureshas 16 bits for various GSO flags, with "a lot" of free space yet - unless I missed something?
This patch has two purposes, one to add an additional tunable for TSO for drivers, and two, to support buggy hardware that can do segmentation offloading, but can't handle 64 KB frames. Your suggestion here would lend well for the latter, for drivers needing to set the maximum frame size to something "smaller," and not really needing or wanting fine granularity. It just needs something smaller to chew on vs. the current 64 KB frames.
For the tuning, I see the desire for something much more granular. Looking ahead at some of the giant send offload features coming (support for TSOs bigger than 64 KB) and even for current adapters looking to fine tune TSO given a certain workload, I see the need for this granularity. For a certain type of workload, a TSO max frame size of 40 KB, or 20 KB, or even 50 KB might be something a driver would like to do.
Hopefully this clarifies my intent. I think keeping the full precision is the right thing to do moving forward. I really do appreciate the inputs though, keep them coming please. :-)
Cheers,
-PJ Waskiewicz
Re: [PATCH] [NET 2.6.26]: Add per-connection option to set max TSOframe size
On Fri, Feb 29, 2008 at 03:20:20PM -0800, Waskiewicz Jr, Peter P wrote:
...
Quoted 1 line
Hopefully this clarifies my intent. [...]
All clear!
Thanks,
Jarek P.