Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2249859rdb; Thu, 21 Sep 2023 12:52:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFX1NuYxhypnGF+WGYjAJyD4deustTFG2xqUx9UUQTF5+J3kC9hYHdOaVcxcitv3X8jAWHS X-Received: by 2002:a17:90a:ec18:b0:26b:9e2:1298 with SMTP id l24-20020a17090aec1800b0026b09e21298mr6310629pjy.11.1695325934429; Thu, 21 Sep 2023 12:52:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695325934; cv=none; d=google.com; s=arc-20160816; b=NpfbBO9CpOUxKD+B6usNaQt9iihAQvYMFQvYqbV7THz8QWTA5R2uegeUyN8WiSPRo7 MIteU2FqBB3lVjSi81JpuIPZAJhmn114CywMupQPulPm9hCsT1TNf7py6ksV77sGezJI 9cEzUmhIUa1tJpLNxGQykZICtcizaEqOD+brpo5VuA/i0CeI062fKgX82c9QpJDur9sG UA7OvgtScZXjkPnhVkOc3vKL+Cyu5+L5/W/1U0+dzHn1F4625SOYztD74vdf6AW9vMyK oiGO1ovx14q6TW5dhyYQN9Jax2mCefAuU73/tZStvOQWbYIsc+BTEAynjkEHQBhiZxNe m6ew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:subject :from:references:to:content-language:cc:user-agent:mime-version:date :message-id; bh=5mD5SVdopLFLf3PXk4DalZUPfVcI02Rni2MXYhSgXbY=; fh=QqF9woRep+B3FUbTm0qbO8raeQKL02OBXZBr1WiqhWA=; b=kRHqybx+9Te92oSenvAUVnp6Twmr0bRsB8s884lZz4qF6vxsA+NB78G3LHozkDdU35 z0JXxj2yGTZk9VIw/9PXg7IxQaal+sCqjNSQspshsPrcV8mCekKR4wvgUHy11Z0Xbu3e ySj7Uh1BT8Uww0t2LbVCw48vFpKSdBNq9w9UsmlqK4zyeytkLZAjOF4FXoDF2P+XxtOs Mcqpp+tuR9WrURgab2lTb73Nf3dY6oPSo2t9VRbYP17gRLr+ODjdbqDcgZIqLTCZXVX/ dUv7sd1BLFzk7Pjk/pJSsT3ANmyYKZuDIMONhDi9stMr2do6BFxWjkZ0rA90YXuW8U1R 7ERA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id kk13-20020a17090b4a0d00b002532c9b252asi2473801pjb.73.2023.09.21.12.52.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 12:52:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id AE85B8347B5F; Thu, 21 Sep 2023 12:39:27 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230101AbjIUTjN (ORCPT + 99 others); Thu, 21 Sep 2023 15:39:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230011AbjIUTi4 (ORCPT ); Thu, 21 Sep 2023 15:38:56 -0400 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E4DB19E; Thu, 21 Sep 2023 12:36:55 -0700 (PDT) Received: by mail.gandi.net (Postfix) with ESMTPSA id BBC0BFF805; Thu, 21 Sep 2023 19:36:51 +0000 (UTC) Message-ID: <8418e275-7d9a-56b7-0b3f-11f4ddcaaa7b@ovn.org> Date: Thu, 21 Sep 2023 21:37:44 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Cc: i.maximets@ovn.org, netdev@vger.kernel.org, Jakub Kicinski , "David S. Miller" , Paolo Abeni , linux-kernel@vger.kernel.org, dev@openvswitch.org, Pravin B Shelar , Eelco Chaudron Content-Language: en-US To: Eric Dumazet References: <20230921190429.1970766-1-i.maximets@ovn.org> From: Ilya Maximets Subject: Re: [PATCH net-next] openvswitch: reduce stack usage in do_execute_actions In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-GND-Sasl: i.maximets@ovn.org X-Spam-Status: No, score=-2.2 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Thu, 21 Sep 2023 12:39:27 -0700 (PDT) On 9/21/23 21:08, Eric Dumazet wrote: > On Thu, Sep 21, 2023 at 9:03 PM Ilya Maximets wrote: >> >> do_execute_actions() function can be called recursively multiple >> times while executing actions that require pipeline forking or >> recirculations. It may also be re-entered multiple times if the packet >> leaves openvswitch module and re-enters it through a different port. >> >> Currently, there is a 256-byte array allocated on stack in this >> function that is supposed to hold NSH header. Compilers tend to >> pre-allocate that space right at the beginning of the function: >> >> a88: 48 81 ec b0 01 00 00 sub $0x1b0,%rsp >> >> NSH is not a very common protocol, but the space is allocated on every >> recursive call or re-entry multiplying the wasted stack space. >> >> Move the stack allocation to push_nsh() function that is only used >> if NSH actions are actually present. push_nsh() is also a simple >> function without a possibility for re-entry, so the stack is returned >> right away. >> >> With this change the preallocated space is reduced by 256 B per call: >> >> b18: 48 81 ec b0 00 00 00 sub $0xb0,%rsp >> >> Signed-off-by: Ilya Maximets >> --- >> net/openvswitch/actions.c | 20 +++++++++----------- >> 1 file changed, 9 insertions(+), 11 deletions(-) >> >> diff --git a/net/openvswitch/actions.c b/net/openvswitch/actions.c >> index 5f8094acd056..80cc5c512d7b 100644 >> --- a/net/openvswitch/actions.c >> +++ b/net/openvswitch/actions.c >> @@ -312,10 +312,16 @@ static int push_eth(struct sk_buff *skb, struct sw_flow_key *key, >> } >> >> static int push_nsh(struct sk_buff *skb, struct sw_flow_key *key, >> - const struct nshhdr *nh) >> + const struct nlattr *a) > > Presumably this function should be inlined. (one caller only) > > I would add noinline_for_stack to make sure the compiler will not play > games with this attempt. Yeah, good point! I didn't see it being inlined in my testing, but it's better to be sure. I'll post v2 with a flag. > >> { >> + u8 buffer[NSH_HDR_MAX_LEN]; >> + struct nshhdr *nh = (struct nshhdr *)buffer; >> int err; >> >> + err = nsh_hdr_from_nlattr(a, nh, NSH_HDR_MAX_LEN); >> + if (err) >> + return err; >> + >> err = nsh_push(skb, nh); >> if (err) >> return err; >> @@ -1439,17 +1445,9 @@ static int do_execute_actions(struct datapath *dp, struct sk_buff *skb, >> err = pop_eth(skb, key); >> break; >> >> - case OVS_ACTION_ATTR_PUSH_NSH: { >> - u8 buffer[NSH_HDR_MAX_LEN]; >> - struct nshhdr *nh = (struct nshhdr *)buffer; >> - >> - err = nsh_hdr_from_nlattr(nla_data(a), nh, >> - NSH_HDR_MAX_LEN); >> - if (unlikely(err)) >> - break; >> - err = push_nsh(skb, key, nh); >> + case OVS_ACTION_ATTR_PUSH_NSH: >> + err = push_nsh(skb, key, nla_data(a)); >> break; >> - } >> >> case OVS_ACTION_ATTR_POP_NSH: >> err = pop_nsh(skb, key); >> -- >> 2.41.0 >>