Skip to content

Commit d45276e

Browse files
herbertxdavem330
authored andcommitted
macvlan: Skip broadcast queue if multicast with single receiver
As it stands all broadcast and multicast packets are queued and processed in a work queue. This is so that we don't overwhelm the receive softirq path by generating thousands of packets or more (see commit 412ca15 "macvlan: Move broadcasts into a work queue"). As such all multicast packets will be delayed, even if they will be received by a single macvlan device. As using a workqueue is not free in terms of latency, we should avoid this where possible. This patch adds a new filter to determine which addresses should be delayed and which ones won't. This is done using a crude counter of how many times an address has been added to the macvlan port (ha->synced). For now if an address has been added more than once, then it will be considered to be broadcast. This could be tuned further by making this threshold configurable. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 6fc5f5b commit d45276e

File tree

1 file changed

+46
-28
lines changed

1 file changed

+46
-28
lines changed

drivers/net/macvlan.c

Lines changed: 46 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ struct macvlan_port {
5050
u32 flags;
5151
int count;
5252
struct hlist_head vlan_source_hash[MACVLAN_HASH_SIZE];
53+
DECLARE_BITMAP(bc_filter, MACVLAN_MC_FILTER_SZ);
5354
DECLARE_BITMAP(mc_filter, MACVLAN_MC_FILTER_SZ);
5455
unsigned char perm_addr[ETH_ALEN];
5556
};
@@ -291,6 +292,31 @@ static void macvlan_broadcast(struct sk_buff *skb,
291292
}
292293
}
293294

295+
static void macvlan_multicast_rx(const struct macvlan_port *port,
296+
const struct macvlan_dev *src,
297+
struct sk_buff *skb)
298+
{
299+
if (!src)
300+
/* frame comes from an external address */
301+
macvlan_broadcast(skb, port, NULL,
302+
MACVLAN_MODE_PRIVATE |
303+
MACVLAN_MODE_VEPA |
304+
MACVLAN_MODE_PASSTHRU|
305+
MACVLAN_MODE_BRIDGE);
306+
else if (src->mode == MACVLAN_MODE_VEPA)
307+
/* flood to everyone except source */
308+
macvlan_broadcast(skb, port, src->dev,
309+
MACVLAN_MODE_VEPA |
310+
MACVLAN_MODE_BRIDGE);
311+
else
312+
/*
313+
* flood only to VEPA ports, bridge ports
314+
* already saw the frame on the way out.
315+
*/
316+
macvlan_broadcast(skb, port, src->dev,
317+
MACVLAN_MODE_VEPA);
318+
}
319+
294320
static void macvlan_process_broadcast(struct work_struct *w)
295321
{
296322
struct macvlan_port *port = container_of(w, struct macvlan_port,
@@ -308,27 +334,7 @@ static void macvlan_process_broadcast(struct work_struct *w)
308334
const struct macvlan_dev *src = MACVLAN_SKB_CB(skb)->src;
309335

310336
rcu_read_lock();
311-
312-
if (!src)
313-
/* frame comes from an external address */
314-
macvlan_broadcast(skb, port, NULL,
315-
MACVLAN_MODE_PRIVATE |
316-
MACVLAN_MODE_VEPA |
317-
MACVLAN_MODE_PASSTHRU|
318-
MACVLAN_MODE_BRIDGE);
319-
else if (src->mode == MACVLAN_MODE_VEPA)
320-
/* flood to everyone except source */
321-
macvlan_broadcast(skb, port, src->dev,
322-
MACVLAN_MODE_VEPA |
323-
MACVLAN_MODE_BRIDGE);
324-
else
325-
/*
326-
* flood only to VEPA ports, bridge ports
327-
* already saw the frame on the way out.
328-
*/
329-
macvlan_broadcast(skb, port, src->dev,
330-
MACVLAN_MODE_VEPA);
331-
337+
macvlan_multicast_rx(port, src, skb);
332338
rcu_read_unlock();
333339

334340
if (src)
@@ -476,8 +482,10 @@ static rx_handler_result_t macvlan_handle_frame(struct sk_buff **pskb)
476482
}
477483

478484
hash = mc_hash(NULL, eth->h_dest);
479-
if (test_bit(hash, port->mc_filter))
485+
if (test_bit(hash, port->bc_filter))
480486
macvlan_broadcast_enqueue(port, src, skb);
487+
else if (test_bit(hash, port->mc_filter))
488+
macvlan_multicast_rx(port, src, skb);
481489

482490
return RX_HANDLER_PASS;
483491
}
@@ -780,20 +788,27 @@ static void macvlan_change_rx_flags(struct net_device *dev, int change)
780788

781789
static void macvlan_compute_filter(unsigned long *mc_filter,
782790
struct net_device *dev,
783-
struct macvlan_dev *vlan)
791+
struct macvlan_dev *vlan, int cutoff)
784792
{
785793
if (dev->flags & (IFF_PROMISC | IFF_ALLMULTI)) {
786-
bitmap_fill(mc_filter, MACVLAN_MC_FILTER_SZ);
794+
if (cutoff >= 0)
795+
bitmap_fill(mc_filter, MACVLAN_MC_FILTER_SZ);
796+
else
797+
bitmap_zero(mc_filter, MACVLAN_MC_FILTER_SZ);
787798
} else {
788-
struct netdev_hw_addr *ha;
789799
DECLARE_BITMAP(filter, MACVLAN_MC_FILTER_SZ);
800+
struct netdev_hw_addr *ha;
790801

791802
bitmap_zero(filter, MACVLAN_MC_FILTER_SZ);
792803
netdev_for_each_mc_addr(ha, dev) {
804+
if (cutoff >= 0 && ha->synced <= cutoff)
805+
continue;
806+
793807
__set_bit(mc_hash(vlan, ha->addr), filter);
794808
}
795809

796-
__set_bit(mc_hash(vlan, dev->broadcast), filter);
810+
if (cutoff >= 0)
811+
__set_bit(mc_hash(vlan, dev->broadcast), filter);
797812

798813
bitmap_copy(mc_filter, filter, MACVLAN_MC_FILTER_SZ);
799814
}
@@ -803,7 +818,7 @@ static void macvlan_set_mac_lists(struct net_device *dev)
803818
{
804819
struct macvlan_dev *vlan = netdev_priv(dev);
805820

806-
macvlan_compute_filter(vlan->mc_filter, dev, vlan);
821+
macvlan_compute_filter(vlan->mc_filter, dev, vlan, 0);
807822

808823
dev_uc_sync(vlan->lowerdev, dev);
809824
dev_mc_sync(vlan->lowerdev, dev);
@@ -821,7 +836,10 @@ static void macvlan_set_mac_lists(struct net_device *dev)
821836
* The solution is to maintain a list of broadcast addresses like
822837
* we do for uc/mc, if you care.
823838
*/
824-
macvlan_compute_filter(vlan->port->mc_filter, vlan->lowerdev, NULL);
839+
macvlan_compute_filter(vlan->port->mc_filter, vlan->lowerdev, NULL,
840+
0);
841+
macvlan_compute_filter(vlan->port->bc_filter, vlan->lowerdev, NULL,
842+
1);
825843
}
826844

827845
static int macvlan_change_mtu(struct net_device *dev, int new_mtu)

0 commit comments

Comments
 (0)