From patchwork Thu Feb 23 12:21:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?57yYIOmZtg==?= X-Patchwork-Id: 13150217 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 60404C636D6 for ; Thu, 23 Feb 2023 12:22:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233183AbjBWMWA (ORCPT ); Thu, 23 Feb 2023 07:22:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229448AbjBWMV7 (ORCPT ); Thu, 23 Feb 2023 07:21:59 -0500 Received: from JPN01-TYC-obe.outbound.protection.outlook.com (mail-tycjpn01olkn2025.outbound.protection.outlook.com [40.92.99.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A58C216ADD; Thu, 23 Feb 2023 04:21:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZulHtvecCiWPuoUIa4UOenLnzn1YBZ0iHOB3cNYaOMdn9y+jrXBLpdIjhvVKtnpOO0hNSGhQuAMxGL1OiVoJ645uAthWmSA+Sq0RarRn39CfKIERAIb5R+qZ0hQoabrdZ7Tk3kWbIE+S4WmvCyty2xQWfJtBw7mnwPdQlj0FRRvVVGOYpRSjyjrr8m6+5yoFNBvBLXV62WbxUYnlZJA0pQcfkfglsU3ds/pk9nIoOXIpLGXUMKKzzsG9QQBneMH35EM7TOMDiSOFhXWPdvqG8fIR+BjZ0LiTNhsDKzPUkklbGmLmpZgNl8G2RGX/D28QwE3/mGeOAoAO5qulV8SeKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=zfqIsdLUPcNrhfCnr5z9SOneA6iMpD1o72aa9LR7pjo=; b=W0nvsTprEe/0SO97XdJfyCg2cLRKO2g1JNv7oK8oSC9uoyB6AXFGPvXaxaJtW3wEguxgRYlnxGX55kXgy3fBiz22v/7Vwb7RueF2jk6Sa3ipCyVht7V7iiBwUG+SbwwuwiaE8NO/u1vAx3JXM+NbLk+jneg3G6l0Woi6Hv2VFqBVAMJdYJ2kbKFLhYZUrHEI891KNPAJB8DwZR0kpZZKi2+BCUCP5QOW1zNxEuwOkE2VEyLiVBiPFZAPi8Lz8sT6hW1dzymjJvyx7E8kiZCYKO0vkXANEEogojXqmcyHTf77In7kiggIRFROBlrn69R3oqCVTwe8IuVBUn5v09SBDQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zfqIsdLUPcNrhfCnr5z9SOneA6iMpD1o72aa9LR7pjo=; b=Q/pY0JvvyAOk6AGM6r9/vrRMDhNCuTiv4kXLiLqN8a02MKsQZab7LQlJ7S6kPNcaBsHCOXNsgr1+776SNrgzlnFVrHjkpdjGVu6zJW8v8u6V+6AY18zFNih5Ym1/DmeyHP7eGsib5l7w9DaRyZVhjUYjwSoFMx0nCyJ7n8AxxaMNYrPXb/JW70RPaIelj5EaJ7dq57aKUwIAT5yu0tGGjQpCx0hEK0Ot8ApQ40XOuFP/o3C9F1DQTp6K9QlSE/XKHxJdLi79a1HMWHJnSSoELfVkfyYhJEn7di8jOW4hdzYXF2H3jv/AjHrrOrRXDqVOMAYdQ4A1ftgb5NJ9lle6OQ== Received: from OS3P286MB2295.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:19b::11) by TYCP286MB3487.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:3a3::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6134.21; Thu, 23 Feb 2023 12:21:51 +0000 Received: from OS3P286MB2295.JPNP286.PROD.OUTLOOK.COM ([fe80::9a1d:12f5:126c:9068]) by OS3P286MB2295.JPNP286.PROD.OUTLOOK.COM ([fe80::9a1d:12f5:126c:9068%3]) with mapi id 15.20.6111.018; Thu, 23 Feb 2023 12:21:51 +0000 From: Eddy Tao To: netdev@vger.kernel.org Cc: Eddy Tao , Pravin B Shelar , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , dev@openvswitch.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v2 1/1] net: openvswitch: Use on stack sw_flow_key in ovs_packet_cmd_execute Date: Thu, 23 Feb 2023 20:21:31 +0800 Message-ID: X-Mailer: git-send-email 2.27.0 X-TMN: [JVVSBEExtTqqZDbQBD2hKR0AekIwGIC8] X-ClientProxiedBy: SG2PR06CA0198.apcprd06.prod.outlook.com (2603:1096:4:1::30) To OS3P286MB2295.JPNP286.PROD.OUTLOOK.COM (2603:1096:604:19b::11) X-Microsoft-Original-Message-ID: <20230223122133.495666-1-taoyuan_eddy@hotmail.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: OS3P286MB2295:EE_|TYCP286MB3487:EE_ X-MS-Office365-Filtering-Correlation-Id: f17065d9-440a-414b-9928-08db15988ab0 X-MS-Exchange-SLBlob-MailProps: C/ir7cSdGlt58y46nZpUh6gN7novD8TGFdRbwVdZjGSq0BZLdQKhz8qMPD6uHsEvcbfZv5Vq0I0mGmYo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Ve9HxJlbF9OQiRXak4grPpw8TXJVYsTkxKeUE1ESqzS5BA/aCdIHvnvSiJHVoPb9VU1D4wc5iYGlfSq2yLdDhensdQgHtQTpcntDLWylg31uciDdXBurYsMmyBtqHqiNdUrtubuDh7tVH7TOnbQFQJwrwjjpvom2a3FyTVGFaTwlc/4KfJZtamxbfGv08baWzk7VPnQ8JN81SysZuydX5uCaqKLPdfYn3PT/NuC+CPugcE8qZgip8HFfUrtoXIFqnjjFyrixPwDGLSoqOiNnUXQHN7DW0hqsm4eC/3TxlAomWI9s0Em4cIaP+kg5g+X9GIvmO2H/PU/MPQ/buqzCZS960s9stLBLjFJtzpO8YmDe9JP3GjYdd+8sRS3FLdP9iQIPfhNOtObiSAAVTdYlD8Z6xAz2ny5NVhMjI86zJnjI8Elhp01vs4dJMDHAD+/cNMuIqnK92TAOM/VVv5/6yFOWnL0EQZJ4P3kBmfDhPUlJQadC595a87gJM2k5lTGxALY0rNodDMkzqME8eZt/iU4GbTPs3PFq3l9nDiFFPfspkQWZXN9TC8g6vp5vVuXTeXHjBJ0le3d+fmOXUy9LHxs5JCamRA== X-OriginatorOrg: sct-15-20-4755-11-msonline-outlook-05f45.templateTenant X-MS-Exchange-CrossTenant-Network-Message-Id: f17065d9-440a-414b-9928-08db15988ab0 X-MS-Exchange-CrossTenant-AuthSource: OS3P286MB2295.JPNP286.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Feb 2023 12:21:51.3172 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYCP286MB3487 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Use on stack sw_flow_key in ovs_packet_cmd_execute Reason: As key function in slow-path, ovs_packet_cmd_execute and ovs_flow_cmd_new allocate transient memory for sw_flow and frees it at the end of function. The procedure is not efficient in 2 aspects 1. actuall sw_flow_key is what the function need 2. free/alloc involves kmem_cache operations when system under frequent slow path operation Existing code in ovs_flow_cmd_new/set/get use stack to store sw_flow_mask and sw_flow_key deliberately Performance benefit: ovs_packet_cmd_execute efficiency improved Avoid 2 calls to kmem_cache alloc Avoid memzero of 200 bytes 6% less instructions Testing topology +-----+ nic1--| |--nic1 nic2--| |--nic2 VM1(16cpus) | ovs | VM2(16 cpus) nic3--|4cpus|--nic3 nic4--| |--nic4 +-----+ 2 threads on each vnic with affinity set on client side netperf -H $peer -p $((port+$i)) -t UDP_RR -l 60 -- -R 1 -r 8K,8K netperf -H $peer -p $((port+$i)) -t TCP_RR -l 60 -- -R 1 -r 120,240 netperf -H $peer -p $((port+$i)) -t TCP_CRR -l 60 -- -R 1 -r 120,240 Before the fix Mode Iterations Variance Average UDP_RR 10 %1.31 46724 TCP_RR 10 %6.26 77188 TCP_CRR 10 %0.10 20505 UDP_STREAM 10 %4.55 19907 TCP_STREAM 10 %9.93 28942 After the fix Mode Iterations Variance Average UDP_RR 10 %1.51 49097 TCP_RR 10 %5.58 78540 TCP_CRR 10 %0.14 20542 UDP_STREAM 10 %11.17 22532 TCP_STREAM 10 %11.14 28579 Signed-off-by: Eddy Tao --- V1 -> V2: Further reduce memory usage by using sw_flow_key instead of sw_flow, revise description of change and provide data net/openvswitch/datapath.c | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c index fcee6012293b..ae3146d51079 100644 --- a/net/openvswitch/datapath.c +++ b/net/openvswitch/datapath.c @@ -596,8 +596,7 @@ static int ovs_packet_cmd_execute(struct sk_buff *skb, struct genl_info *info) struct nlattr **a = info->attrs; struct sw_flow_actions *acts; struct sk_buff *packet; - struct sw_flow *flow; - struct sw_flow_actions *sf_acts; + struct sw_flow_key key; struct datapath *dp; struct vport *input_vport; u16 mru = 0; @@ -636,24 +635,20 @@ static int ovs_packet_cmd_execute(struct sk_buff *skb, struct genl_info *info) } /* Build an sw_flow for sending this packet. */ - flow = ovs_flow_alloc(); - err = PTR_ERR(flow); - if (IS_ERR(flow)) - goto err_kfree_skb; + memset(&key, 0, sizeof(key)); err = ovs_flow_key_extract_userspace(net, a[OVS_PACKET_ATTR_KEY], - packet, &flow->key, log); + packet, &key, log); if (err) - goto err_flow_free; + goto err_kfree_skb; err = ovs_nla_copy_actions(net, a[OVS_PACKET_ATTR_ACTIONS], - &flow->key, &acts, log); + &key, &acts, log); if (err) - goto err_flow_free; + goto err_kfree_skb; - rcu_assign_pointer(flow->sf_acts, acts); - packet->priority = flow->key.phy.priority; - packet->mark = flow->key.phy.skb_mark; + packet->priority = key.phy.priority; + packet->mark = key.phy.skb_mark; rcu_read_lock(); dp = get_dp_rcu(net, ovs_header->dp_ifindex); @@ -661,7 +656,7 @@ static int ovs_packet_cmd_execute(struct sk_buff *skb, struct genl_info *info) if (!dp) goto err_unlock; - input_vport = ovs_vport_rcu(dp, flow->key.phy.in_port); + input_vport = ovs_vport_rcu(dp, key.phy.in_port); if (!input_vport) input_vport = ovs_vport_rcu(dp, OVSP_LOCAL); @@ -670,20 +665,17 @@ static int ovs_packet_cmd_execute(struct sk_buff *skb, struct genl_info *info) packet->dev = input_vport->dev; OVS_CB(packet)->input_vport = input_vport; - sf_acts = rcu_dereference(flow->sf_acts); local_bh_disable(); - err = ovs_execute_actions(dp, packet, sf_acts, &flow->key); + err = ovs_execute_actions(dp, packet, acts, &key); local_bh_enable(); rcu_read_unlock(); - ovs_flow_free(flow, false); + ovs_nla_free_flow_actions(acts); return err; err_unlock: rcu_read_unlock(); -err_flow_free: - ovs_flow_free(flow, false); err_kfree_skb: kfree_skb(packet); err: