bond hashing revised
Subsystems (3)
cover bond hashing revised
These have not been tested yet. I need to try them with some different flows/hardware to validate.
RFC 1/4 bond: cleanup transmit hash policy interface
Some minor cleanups of hash policy with no change in resulting interface.
1. Do modulus operation in caller rather than policy
2. Pass skb as constant pointer
3. Use common code for layer 2 policy hash
drivers/net/bonding/bond_3ad.c +1 -1
@@ -2413,7 +2413,7 @@ int bond_3ad_xmit_xor(struct sk_buff *sk goto out; } - slave_agg_no = bond->xmit_hash_policy (skb, slaves_in_agg); + slave_agg_no = bond->xmit_hash_policy (skb) % slaves_in_agg;bond_for_each_slave (bond, slave, i) {struct aggregator *agg =SLAVE_AD_INFO (slave).port.aggregator;
drivers/net/bonding/bond_main.c +26 -24
89 lines not on this page · raw message
drivers/net/bonding/bonding.h +1 -1
@@ -203,7 +203,7 @@ struct bonding {#endif /* CONFIG_PROC_FS */ struct list_head bond_list;struct dev_mc_list *mc_list; -int (*xmit_hash_policy)(struct sk_buff *,int ); +u16 (*xmit_hash_policy)(const struct sk_buff *);__be32 master_ip;u16 flags;u16 rr_tx_counter;
RFC 2/4 bond: add IPV6 layer3 hash policy support
In reply to Stephen HemmingerAdd IPV6 support to Layer 3 and Layer 3+4 hash policies. Code take fron SFQ.
drivers/net/bonding/bond_main.c +33 -8
@@ -3601,13 +3601,24 @@ static u16 bond_xmit_hash_policy_l23(con {const struct ethhdr *data =eth_hdr (skb); -if (skb->protocol ==htons (ETH_P_IP )) { +switch (skb->protocol) { +case htons (ETH_P_IP ): + {const struct iphdr *iph =ip_hdr (skb);return ntohl (iph->saddr ^ iph->daddr) ^ (data->h_dest[5 ] ^ data->h_source[5 ]); } +case htons (ETH_P_IPV6 ): + { +const struct ipv6hdr *iph =ipv6_hdr (skb); +return ntohl (iph->saddr.s6_addr32[3 ] ^ + iph->daddr.s6_addr32[3 ]) ^ + (data->h_dest[5 ] ^ data->h_source[5 ]); -return bond_xmit_hash_policy_l2 (skb); + } +default : +return bond_xmit_hash_policy_l2 (skb); + } }/*
@@ -3617,9 +3628,9 @@ static u16 bond_xmit_hash_policy_l23(con*/ static u16 bond_xmit_hash_policy_l34 (const struct sk_buff *skb) { -const struct ethhdr *data =eth_hdr (skb); - -if (skb->protocol ==htons (ETH_P_IP )) { +switch (skb->protocol) { +case htons (ETH_P_IP ): + {const struct iphdr *iph =ip_hdr (skb);const __be16 *layer4hdr = ((const void *)iph + iph->ihl);
@@ -3627,14 +3638,28 @@ static u16 bond_xmit_hash_policy_l34(conif (!(iph->frag_off &htons (IP_MF |IP_OFFSET )) && (iph->protocol ==IPPROTO_TCP || - iph->protocol ==IPPROTO_UDP )) { + iph->protocol ==IPPROTO_UDP )) layer4_xor =ntohs ((*layer4hdr ^ *(layer4hdr +1 ))); - } +return layer4_xor ^ntohl (iph->saddr ^ iph->daddr); + } +case htons (ETH_P_IPV6 ): + { +const struct ipv6hdr *iph =ipv6_hdr (skb); +const __be16 *layer4hdr = (const __be16 *) (iph +1 ); +u32 layer4_xor =0 ; +if (iph->nexthdr ==IPPROTO_TCP || + iph->nexthdr ==IPPROTO_UDP ) + layer4_xor =ntohs ((*layer4hdr ^ *(layer4hdr +1 ))); + +return layer4_xor ^ +ntohl (iph->saddr.s6_addr32[3 ] ^ iph->daddr.s6_addr32[3 ]); + } +default : +return bond_xmit_hash_policy_l2 (skb); } -return bond_xmit_hash_policy_l2 (skb); }
RFC 3/4 bond: support more Layer 4 protocols
In reply to Stephen HemmingerThere are several protocols similar to TCP and UDP which share common L4 header format. Since proto is only one byte, use a map rather than big conditonal.
drivers/net/bonding/bond_main.c +14 -6
@@ -3621,6 +3621,16 @@ static u16 bond_xmit_hash_policy_l23(con } } +/* Map of protocols with standard ports available to include in hash */ +static const bool has_layer4[256 ] = { + [IPPROTO_TCP ] =1 , + [IPPROTO_UDP ] =1 , + [IPPROTO_UDPLITE ] =1 , + [IPPROTO_SCTP ] =1 , + [IPPROTO_DCCP ] =1 , + [IPPROTO_ESP ] =1 , +}; +/* * Hash for the output device based upon layer 3 and layer 4 data. If * the packet is a frag or not TCP or UDP, just use layer 3 data. If it is
@@ -3634,11 +3644,10 @@ static u16 bond_xmit_hash_policy_l34(conconst struct iphdr *iph =ip_hdr (skb);const __be16 *layer4hdr = ((const void *)iph + iph->ihl); -u32 layer4_xor =0 ; +u16 layer4_xor =0 ;if (!(iph->frag_off &htons (IP_MF |IP_OFFSET )) && - (iph->protocol ==IPPROTO_TCP || - iph->protocol ==IPPROTO_UDP )) + has_layer4[iph->protocol]) layer4_xor =ntohs ((*layer4hdr ^ *(layer4hdr +1 )));return layer4_xor ^ntohl (iph->saddr ^ iph->daddr);
@@ -3647,10 +3656,9 @@ static u16 bond_xmit_hash_policy_l34(con {const struct ipv6hdr *iph =ipv6_hdr (skb);const __be16 *layer4hdr = (const __be16 *) (iph +1 ); -u32 layer4_xor =0 ; +u16 layer4_xor =0 ; -if (iph->nexthdr ==IPPROTO_TCP || - iph->nexthdr ==IPPROTO_UDP ) +if (has_layer4[iph->nexthdr]) layer4_xor =ntohs ((*layer4hdr ^ *(layer4hdr +1 ))); return layer4_xor ^
Re: [RFC 3/4] bond: support more Layer 4 protocols
drivers/net/bonding/bond_main.c static u16 bond_xmit_hash_policy_l23(con · line 3633
Quoted 10 lines · Stephen Hemminger
drivers/net/bonding/bond_main.c +10
-0+/* Map of protocols with standard ports available to include in hash */ +static const bool has_layer4[256 ] = { + [IPPROTO_TCP ] =1 , + [IPPROTO_UDP ] =1 , + [IPPROTO_UDPLITE ] =1 , + [IPPROTO_SCTP ] =1 , + [IPPROTO_DCCP ] =1 , + [IPPROTO_ESP ] =1 , +}; +
How about using a bitmap or u8s to keep this more compact?
Re: [RFC 3/4] bond: support more Layer 4 protocols
Quoted 13 lines · On Fri, 05 Feb 2010 11:38:05 +0100 Patrick McHardy <[email protected]> wrote:
drivers/net/bonding/bond_main.c static u16 bond_xmit_hash_policy_l23(con · line 3633
Quoted 10 lines · Stephen Hemminger
drivers/net/bonding/bond_main.c +10
-0+/* Map of protocols with standard ports available to include in hash */ +static const bool has_layer4[256 ] = { + [IPPROTO_TCP ] =1 , + [IPPROTO_UDP ] =1 , + [IPPROTO_UDPLITE ] =1 , + [IPPROTO_SCTP ] =1 , + [IPPROTO_DCCP ] =1 , + [IPPROTO_ESP ] =1 , +}; +How about using a bitmap or u8s to keep this more compact?
I thought about that, but couldn't find a clever way to initialize at compile time other than hardcoding constants?
Re: [RFC 3/4] bond: support more Layer 4 protocols
Quoted 16 lines · Stephen Hemminger
Quoted 12 lines · On Fri, 05 Feb 2010 11:38:05 +0100 Patrick McHardy <[email protected]> wrote:
drivers/net/bonding/bond_main.c static u16 bond_xmit_hash_policy_l23(con · line 3633
Quoted 10 lines · Stephen Hemminger
drivers/net/bonding/bond_main.c +10
-0+/* Map of protocols with standard ports available to include in hash */ +static const bool has_layer4[256 ] = { + [IPPROTO_TCP ] =1 , + [IPPROTO_UDP ] =1 , + [IPPROTO_UDPLITE ] =1 , + [IPPROTO_SCTP ] =1 , + [IPPROTO_DCCP ] =1 , + [IPPROTO_ESP ] =1 , +}; +How about using a bitmap or u8s to keep this more compact?
Quoted 2 lines
I thought about that, but couldn't find a clever way to initialize at compile time other than hardcoding constants?
Maybe an __init function with a couple of set_bit() calls? Otherwise I'd suggest to simply use u8.
RFC 4/4 bond: add new multiqueue hash policy
In reply to Stephen HemmingerThis hash policy just uses existing transmit hash used for mulitiqueue.
drivers/net/bonding/bond_main.c +11 -0
@@ -190,6 +190,7 @@ const struct bond_parm_tbl xmit_hashtype { "layer2", BOND_XMIT_POLICY_LAYER2}, { "layer3+4", BOND_XMIT_POLICY_LAYER34}, { "layer2+3", BOND_XMIT_POLICY_LAYER23}, +{ "multiqueue", BOND_XMIT_POLICY_MQ}, { NULL, -1}, };
@@ -3670,6 +3671,13 @@ static u16 bond_xmit_hash_policy_l34(con } +/* +* Hash for the output device based on multiqueue transmit hash policy +*/ +static u16 bond_xmit_hash_policy_mq (const struct sk_buff *skb) +{ +return skb_tx_hash (skb->dev, skb); +}/*-------------------------- Device entry points ----------------------------*/
@@ -4350,6 +4358,9 @@ out:static void bond_set_xmit_hash_policy (struct bonding *bond) {switch (bond->params.xmit_policy) { +case BOND_XMIT_POLICY_MQ : + bond->xmit_hash_policy = bond_xmit_hash_policy_mq; +break ;case BOND_XMIT_POLICY_LAYER23 : bond->xmit_hash_policy = bond_xmit_hash_policy_l23;break ;
include/linux/if_bonding.h +1 -0
@@ -87,6 +87,7 @@#define BOND_XMIT_POLICY_LAYER2 0/* layer 2 (MAC only), default */ #define BOND_XMIT_POLICY_LAYER34 1/* layer 3+4 (IP ^ (TCP || UDP)) */ #define BOND_XMIT_POLICY_LAYER23 2/* layer 2+3 (IP ^ MAC) */ +#define BOND_XMIT_POLICY_MQ 3/* transmit hash (multiqueue) */ typedef struct ifbond { __s32 bond_mode;
Quoted 3 lines · Stephen Hemminger
These have not been tested yet. I need to try them with some different flows/hardware to validate.
Glancing over these patches, all four of them look fine to me.
The only thing missing is some documentation in Documentation/networking/bonding.txt (I have no idea what multiqueue is supposed to do, but if you tell me I'll volunteer).
Cheers,
Jasper
Signature · 4 lines
Ir. Jasper Spaans Fox-IT Experts in IT Security! T: +31 (0) 15 284 79 99 KvK Haaglanden 27301624
Quoted 10 lines · On Fri, 5 Feb 2010 09:40:17 +0000 Jasper Spaans <[email protected]> wrote:
Quoted 3 lines · Stephen Hemminger
These have not been tested yet. I need to try them with some different flows/hardware to validate.
Glancing over these patches, all four of them look fine to me.
The only thing missing is some documentation in
Documentation/networking/bonding.txt(I have no idea what multiqueue is supposed to do, but if you tell me I'll volunteer).
Did you look at kernel Documentation/networking/multiqueue.txt?