Dynamically allocating the sw_flow_key reduces stack usage of
ovs_vport_receive from 544 bytes to 64 bytes at the cost of
another GFP_ATOMIC allocation in the receive path.

XXX: is this a problem with memory reserves if ovs is in a
memory reclaim path, or since we have a skb allocated, is it
okay to use some GFP_ATOMIC reserves?

Signed-off-by: Nicholas Piggin <npig...@gmail.com>
---
 net/openvswitch/vport.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/net/openvswitch/vport.c b/net/openvswitch/vport.c
index 972ae01a70f7..ddba3e00832b 100644
--- a/net/openvswitch/vport.c
+++ b/net/openvswitch/vport.c
@@ -494,9 +494,13 @@ u32 ovs_vport_find_upcall_portid(const struct vport *vport,
 int ovs_vport_receive(struct vport *vport, struct sk_buff *skb,
                      const struct ip_tunnel_info *tun_info)
 {
-       struct sw_flow_key key;
+       struct sw_flow_key *key;
        int error;
 
+       key = kmalloc(sizeof(*key), GFP_ATOMIC);
+       if (!key)
+               return -ENOMEM;
+
        OVS_CB(skb)->input_vport = vport;
        OVS_CB(skb)->mru = 0;
        OVS_CB(skb)->cutlen = 0;
@@ -510,12 +514,16 @@ int ovs_vport_receive(struct vport *vport, struct sk_buff 
*skb,
        }
 
        /* Extract flow from 'skb' into 'key'. */
-       error = ovs_flow_key_extract(tun_info, skb, &key);
+       error = ovs_flow_key_extract(tun_info, skb, key);
        if (unlikely(error)) {
                kfree_skb(skb);
+               kfree(key);
                return error;
        }
-       ovs_dp_process_packet(skb, &key);
+       ovs_dp_process_packet(skb, key);
+
+       kfree(key);
+
        return 0;
 }
 
-- 
2.40.1

_______________________________________________
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to