Skip to contentSkip to conversation

bond hashing revised

RFC In review Stephen Hemminger 3 participants 10 messages Feb 4, 2010 – Feb 8, 2010

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

cover bond hashing revised

These have not been tested yet. I need to try them with some different flows/hardware to validate.

#1 lore raw

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;
#2 lore raw

RFC 2/4 bond: add IPV6 layer3 hash policy support

In reply to Stephen Hemminger

Add 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(con
 
 		if (!(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);
 }
 
 
#3 lore raw

RFC 3/4 bond: support more Layer 4 protocols

In reply to Stephen Hemminger

There 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(con
 		const 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 ^
#4 lore raw

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?

#5 lore raw

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?

#6 lore raw

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.

#7 lore raw

RFC 4/4 bond: add new multiqueue hash policy

In reply to Stephen Hemminger

This 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;
#8 lore raw
In reply to Stephen Hemminger
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
#9 lore raw
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?