* [PATCH net-next v2] openvswitch: reduce stack usage in do_execute_actions
@ 2023-09-21 19:42 Ilya Maximets
2023-09-21 19:58 ` Eric Dumazet
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Ilya Maximets @ 2023-09-21 19:42 UTC (permalink / raw)
To: netdev
Cc: Jakub Kicinski, David S. Miller, Eric Dumazet, Paolo Abeni,
linux-kernel, dev, Pravin B Shelar, Eelco Chaudron, Ilya Maximets
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 <i.maximets@ovn.org>
---
Version 2:
- Added 'noinline_for_stack' to avoid potential inlining. [Eric]
net/openvswitch/actions.c | 23 +++++++++++------------
1 file changed, 11 insertions(+), 12 deletions(-)
diff --git a/net/openvswitch/actions.c b/net/openvswitch/actions.c
index 5f8094acd056..6fcd7e2ca81f 100644
--- a/net/openvswitch/actions.c
+++ b/net/openvswitch/actions.c
@@ -311,11 +311,18 @@ static int push_eth(struct sk_buff *skb, struct sw_flow_key *key,
return 0;
}
-static int push_nsh(struct sk_buff *skb, struct sw_flow_key *key,
- const struct nshhdr *nh)
+static noinline_for_stack int push_nsh(struct sk_buff *skb,
+ struct sw_flow_key *key,
+ const struct nlattr *a)
{
+ 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 +1446,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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net-next v2] openvswitch: reduce stack usage in do_execute_actions
2023-09-21 19:42 [PATCH net-next v2] openvswitch: reduce stack usage in do_execute_actions Ilya Maximets
@ 2023-09-21 19:58 ` Eric Dumazet
2023-09-22 6:43 ` Eelco Chaudron
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Eric Dumazet @ 2023-09-21 19:58 UTC (permalink / raw)
To: Ilya Maximets
Cc: netdev, Jakub Kicinski, David S. Miller, Paolo Abeni,
linux-kernel, dev, Pravin B Shelar, Eelco Chaudron
On Thu, Sep 21, 2023 at 9:42 PM Ilya Maximets <i.maximets@ovn.org> 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.
>
Reviewed-by: Eric Dumazet <edumazet@google.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net-next v2] openvswitch: reduce stack usage in do_execute_actions
2023-09-21 19:42 [PATCH net-next v2] openvswitch: reduce stack usage in do_execute_actions Ilya Maximets
2023-09-21 19:58 ` Eric Dumazet
@ 2023-09-22 6:43 ` Eelco Chaudron
2023-09-27 20:24 ` [ovs-dev] " Aaron Conole
2023-10-01 18:10 ` patchwork-bot+netdevbpf
3 siblings, 0 replies; 5+ messages in thread
From: Eelco Chaudron @ 2023-09-22 6:43 UTC (permalink / raw)
To: netdev
On 21 Sep 2023, at 21:42, 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 <i.maximets@ovn.org>
One more time to the list only, as for some reason I had HTML reply turned on :(
Thanks Ilya for optimizing this.
Reviewed-by: Eelco Chaudron echaudro@redhat.com
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [ovs-dev] [PATCH net-next v2] openvswitch: reduce stack usage in do_execute_actions
2023-09-21 19:42 [PATCH net-next v2] openvswitch: reduce stack usage in do_execute_actions Ilya Maximets
2023-09-21 19:58 ` Eric Dumazet
2023-09-22 6:43 ` Eelco Chaudron
@ 2023-09-27 20:24 ` Aaron Conole
2023-10-01 18:10 ` patchwork-bot+netdevbpf
3 siblings, 0 replies; 5+ messages in thread
From: Aaron Conole @ 2023-09-27 20:24 UTC (permalink / raw)
To: Ilya Maximets
Cc: netdev, dev, linux-kernel, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, David S. Miller
Ilya Maximets <i.maximets@ovn.org> writes:
> 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 <i.maximets@ovn.org>
> ---
Thanks, Ilya.
Reviewed-by: Aaron Conole <aconole@redhat.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net-next v2] openvswitch: reduce stack usage in do_execute_actions
2023-09-21 19:42 [PATCH net-next v2] openvswitch: reduce stack usage in do_execute_actions Ilya Maximets
` (2 preceding siblings ...)
2023-09-27 20:24 ` [ovs-dev] " Aaron Conole
@ 2023-10-01 18:10 ` patchwork-bot+netdevbpf
3 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-10-01 18:10 UTC (permalink / raw)
To: Ilya Maximets
Cc: netdev, kuba, davem, edumazet, pabeni, linux-kernel, dev, pshelar,
echaudro
Hello:
This patch was applied to netdev/net-next.git (main)
by David S. Miller <davem@davemloft.net>:
On Thu, 21 Sep 2023 21:42:35 +0200 you 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:
>
> [...]
Here is the summary with links:
- [net-next,v2] openvswitch: reduce stack usage in do_execute_actions
https://git.kernel.org/netdev/net-next/c/06bc3668cc2a
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-10-01 18:10 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-21 19:42 [PATCH net-next v2] openvswitch: reduce stack usage in do_execute_actions Ilya Maximets
2023-09-21 19:58 ` Eric Dumazet
2023-09-22 6:43 ` Eelco Chaudron
2023-09-27 20:24 ` [ovs-dev] " Aaron Conole
2023-10-01 18:10 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).