Skip to content

Commit 3807ff5

Browse files
edumazetdavem330
authored andcommitted
macvlan: add a salt to mc_hash()
Some multicast addresses are common to all macvlans, so if a multicast message has a hash value collision, we have to deliver a copy to all macvlans, adding significant latency and possible packet drops if netdev_max_backlog limit is hit. Having a per macvlan hash function permits to reduce the impact of hash collisions. Suggested-by: Maciej Żenczykowski <[email protected]> Signed-off-by: Eric Dumazet <[email protected]> Signed-off-by: Maciej Żenczykowski <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent d527043 commit 3807ff5

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

drivers/net/macvlan.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,18 @@ static int macvlan_broadcast_one(struct sk_buff *skb,
127127
return vlan->receive(skb);
128128
}
129129

130-
static unsigned int mc_hash(const unsigned char *addr)
130+
static u32 macvlan_hash_mix(const struct macvlan_dev *vlan)
131+
{
132+
return (u32)(((unsigned long)vlan) >> L1_CACHE_SHIFT);
133+
}
134+
135+
136+
static unsigned int mc_hash(const struct macvlan_dev *vlan,
137+
const unsigned char *addr)
131138
{
132139
u32 val = __get_unaligned_cpu32(addr + 2);
133140

141+
val ^= macvlan_hash_mix(vlan);
134142
return hash_32(val, MACVLAN_MC_FILTER_BITS);
135143
}
136144

@@ -145,7 +153,7 @@ static void macvlan_broadcast(struct sk_buff *skb,
145153
struct sk_buff *nskb;
146154
unsigned int i;
147155
int err;
148-
unsigned int hash = mc_hash(eth->h_dest);
156+
unsigned int hash;
149157

150158
if (skb->protocol == htons(ETH_P_PAUSE))
151159
return;
@@ -155,6 +163,7 @@ static void macvlan_broadcast(struct sk_buff *skb,
155163
if (vlan->dev == src || !(vlan->mode & mode))
156164
continue;
157165

166+
hash = mc_hash(vlan, eth->h_dest);
158167
if (!test_bit(hash, vlan->mc_filter))
159168
continue;
160169
nskb = skb_clone(skb, GFP_ATOMIC);
@@ -424,10 +433,10 @@ static void macvlan_set_mac_lists(struct net_device *dev)
424433

425434
bitmap_zero(filter, MACVLAN_MC_FILTER_SZ);
426435
netdev_for_each_mc_addr(ha, dev) {
427-
__set_bit(mc_hash(ha->addr), filter);
436+
__set_bit(mc_hash(vlan, ha->addr), filter);
428437
}
429438

430-
__set_bit(mc_hash(dev->broadcast), filter);
439+
__set_bit(mc_hash(vlan, dev->broadcast), filter);
431440

432441
bitmap_copy(vlan->mc_filter, filter, MACVLAN_MC_FILTER_SZ);
433442
}

0 commit comments

Comments
 (0)