Skip to contentSkip to conversation

macvlan: optimizing the receive path?

PATCH Jason Baron 5 participants 9 messages Oct 2, 2014 – Oct 7, 2014

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

Hi,

I was just wondering why the netif_rx(skb) call in macvlan_handle_frame() was necessary? IE:

macvlan_handle_frame()

{
       ........

        skb->dev = dev;
        skb->pkt_type = PACKET_HOST;

****>ret = netif_rx(skb);

out:

        macvlan_count_rx(vlan, len, ret == NET_RX_SUCCESS, 0);
        return RX_HANDLER_CONSUMED;
}

I think the point of going through netif_rx() is to ensure that we throttle incoming packets, but hasn't that already been accomplished in this path? That is if the packets are arriving from the physical NIC, we've already throttled them by this point. Otherwise, if they are coming via macvlan_queue_xmit(), it calls either 'dev_forward_skb()', which ends up calling netif_rx_internal(), or else in broadcast mode there is to be throttling via macvlan_broadcast_enqueue().

So I suspect there is a code path that I am missing but the netif_rx() call in question essentially re-queues packets coming from off the box. I've tried the simple patch below to optimize this path, and obviously performs a lot better in my limited testing.

Thanks,

-Jason

drivers/net/macvlan.c +2 -2
@@ -321,8 +321,8 @@ static rx_handler_result_t macvlan_handle_frame(struct sk_buff **pskb)
        skb->dev = dev;
        skb->pkt_type = PACKET_HOST;
 
-       ret = netif_rx(skb);
-
+      macvlan_count_rx(vlan, len, true, 0);
+      return RX_HANDLER_ANOTHER;
 out:
        macvlan_count_rx(vlan, len, ret == NET_RX_SUCCESS, 0);
        return RX_HANDLER_CONSUMED;
#1 lore raw
Quoted 4 lines · On Thu, 02 Oct 2014 16:28:13 -0400 Jason Baron <[email protected]> wrote:

Hi,

I was just wondering why the netif_rx(skb) call in macvlan_handle_frame() was necessary? IE:

It is to prevent too deep a call stack of
netif_receive_skb
macvlan_receive
netif_receive_skb ...

#2 lore raw
Quoted 5 lines · Stephen Hemminger
Quoted 2 lines · On Thu, 02 Oct 2014 16:28:13 -0400 Jason Baron <[email protected]> wrote:

Hi,

Quoted 9 lines
Quoted 2 lines

I was just wondering why the netif_rx(skb) call in macvlan_handle_frame() was necessary? IE:

It is to prevent too deep a call stack of
netif_receive_skb
macvlan_receive
netif_receive_skb ...

So the concern is a stack overflow? The above nesting would really look like:

netif_receive_skb
macvlan_receive
netif_receive_skb

b/c the macvlan_receive call would return. So its not clear to me that the macvlan code would be adding to the stack depth here.

Thanks,

-Jason

#3 lore raw
In reply to Jason Baron
Quoted 28 lines · Jason Baron

Hi,

I was just wondering why the netif_rx(skb) call in macvlan_handle_frame() was necessary? IE:

macvlan_handle_frame()

{
       ........

        skb->dev = dev;
        skb->pkt_type = PACKET_HOST;

****>ret = netif_rx(skb);

out:

        macvlan_count_rx(vlan, len, ret == NET_RX_SUCCESS, 0);
        return RX_HANDLER_CONSUMED;
}

I think the point of going through netif_rx() is to ensure that we throttle incoming packets, but hasn't that already been accomplished in this path? That is if the packets are arriving from the physical NIC, we've already throttled them by this point. Otherwise, if they are coming via macvlan_queue_xmit(), it calls either 'dev_forward_skb()', which ends up calling netif_rx_internal(), or else in broadcast mode there is to be throttling via macvlan_broadcast_enqueue().

Quoted 4 lines

So I suspect there is a code path that I am missing but the netif_rx() call in question essentially re-queues packets coming from off the box. I've tried the simple patch below to optimize this path, and obviously performs a lot better in my limited testing.

Hi Jason

I think the patch below is fine and in this particular case, it's OK to do this.

-vlad

Quoted 28 lines

Thanks,

(quoted diff) +0 -1
-Jason
drivers/net/macvlan.c +2 -3
@@ -321,8 +321,8 @@ static rx_handler_result_t macvlan_handle_frame(struct sk_buff **pskb)
        skb->dev = dev;
        skb->pkt_type = PACKET_HOST;
 
-       ret = netif_rx(skb);
-
+      macvlan_count_rx(vlan, len, true, 0);
+      return RX_HANDLER_ANOTHER;
 out:
        macvlan_count_rx(vlan, len, ret == NET_RX_SUCCESS, 0);
        return RX_HANDLER_CONSUMED;
 
 
 
 
 
--

To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#4 lore raw
In reply to Jason Baron

From: Jason Baron <[email protected]>
Date: Thu, 02 Oct 2014 16:28:13 -0400

drivers/net/macvlan.c static rx_handler_result_t macvlan_handle_frame(struct sk_buff **pskb) · line 328

Quoted 13 lines
drivers/net/macvlan.c +2 -2
@@ -321,8 +321,8 @@ static rx_handler_result_t macvlan_handle_frame(struct sk_buff **pskb)
        skb->dev = dev;
        skb->pkt_type = PACKET_HOST;
 
-       ret = netif_rx(skb);
-
+      macvlan_count_rx(vlan, len, true, 0);
+      return RX_HANDLER_ANOTHER;
 out:
        macvlan_count_rx(vlan, len, ret == NET_RX_SUCCESS, 0);
        return RX_HANDLER_CONSUMED;

That last argument to macvlan_count_rx() is a bool and thus should be specified as "false". Yes I know other areas of this file get it wrong too.

Also, what about GRO? Won't we get GRO processing if we do this via netif_rx() but not via the RX_HANDLER_ANOTHER route? Just curious...

#5 lore raw
Quoted 21 lines · David Miller

From: Jason Baron <[email protected]>
Date: Thu, 02 Oct 2014 16:28:13 -0400

drivers/net/macvlan.c static rx_handler_result_t macvlan_handle_frame(struct sk_buff **pskb) · line 328

Quoted 13 lines
drivers/net/macvlan.c +2 -2
@@ -321,8 +321,8 @@ static rx_handler_result_t macvlan_handle_frame(struct sk_buff **pskb)
        skb->dev = dev;
        skb->pkt_type = PACKET_HOST;
 
-       ret = netif_rx(skb);
-
+      macvlan_count_rx(vlan, len, true, 0);
+      return RX_HANDLER_ANOTHER;
 out:
        macvlan_count_rx(vlan, len, ret == NET_RX_SUCCESS, 0);
        return RX_HANDLER_CONSUMED;

That last argument to macvlan_count_rx() is a bool and thus should be specified as "false". Yes I know other areas of this file get it wrong too.

Quoted 2 lines

Also, what about GRO? Won't we get GRO processing if we do this via netif_rx() but not via the RX_HANDLER_ANOTHER route? Just curious...

Wouldn't GRO already happen at the lower level? For macvlan-to-macvlan, you'd typically have large packets so no need for GRO.

-vlad

#6 lore raw
Quoted 10 lines · Vlad Yasevich
Quoted 9 lines · David Miller

From: Jason Baron <[email protected]>
Date: Thu, 02 Oct 2014 16:28:13 -0400

Quoted 6 lines
drivers/net/macvlan.c +0 -0
@@ -321,8 +321,8 @@ static rx_handler_result_t macvlan_handle_frame(struct sk_buff **pskb)
        skb->dev = dev;
        skb->pkt_type = PACKET_HOST;
 
Quoted 12 lines
Quoted 8 lines

drivers/net/macvlan.c static rx_handler_result_t macvlan_handle_frame(struct sk_buff **pskb) · line 328

Quoted 7 lines
drivers/net/macvlan.c +2 -2
-       ret = netif_rx(skb);
-
+      macvlan_count_rx(vlan, len, true, 0);
+      return RX_HANDLER_ANOTHER;
 out:
        macvlan_count_rx(vlan, len, ret == NET_RX_SUCCESS, 0);
        return RX_HANDLER_CONSUMED;
Quoted 4 lines

That last argument to macvlan_count_rx() is a bool and thus should be specified as "false". Yes I know other areas of this file get it wrong too.

ok. I can fix those up too while here.

Quoted 6 lines
Quoted 2 lines

Also, what about GRO? Won't we get GRO processing if we do this via netif_rx() but not via the RX_HANDLER_ANOTHER route? Just curious...

Wouldn't GRO already happen at the lower level? For macvlan-to-macvlan, you'd typically have large packets so no need for GRO.

Yes, afaict gro is happening a layer below __netif_receive_skb_core().

Here are some results of this optimization on 3.17 using macvlan with lxc. Test case is (average of 3 runs):

for i in {35,50,65,80,95,110,125,140,155};
do super_netperf $i netperf -H $ip -t TCP_RR;
done

trans./sec (3.17)

494016
612806
673100
696982
710494
716830
714729
713478
711056

trans./sec (3.17 + macvlan patch)

517159  +(4.684733558%)
628382  +(2.541860742%)
669688  -(0.5069080835%)
706181  +(1.319833855%)
716660  +(0.8677995555%)
719581  +(0.3838661811%)
718738  +(0.5609585358%)
718904  +(0.7605470482%)
718344  +(1.02509555%)

On the host I can see that the idle time goes to 0, so this would appear to be an improvement. I also observed that enqueue_to_backlog() and process_backlog() are no longer in the 'perf' profiles as expected.

So if there are no objections, I will post as a formal patch.

Thanks,

-Jason

#7 lore raw
Quoted 1 line · Jason Baron

So if there are no objections, I will post as a formal patch.

I think the code used netif_rx() as a precaution because of multicast/broadcasts.

Now these are taken care (if multicast filter + work queue for broadcasts), it seems ok to have a fast path.