netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Nicholas Piggin" <npiggin@gmail.com>
To: "Ilya Maximets" <i.maximets@ovn.org>, <netdev@vger.kernel.org>
Cc: <dev@openvswitch.org>, "Aaron Conole" <aconole@redhat.com>,
	"Eelco Chaudron" <echaudro@redhat.com>,
	"Simon Horman" <horms@ovn.org>
Subject: Re: [ovs-dev] [RFC PATCH 0/7] net: openvswitch: Reduce stack usage
Date: Wed, 04 Oct 2023 19:56:12 +1000	[thread overview]
Message-ID: <CVZKCOOZ2SF4.2DYPVWT5C2TDQ@wheely> (raw)
In-Reply-To: <21f2a427-ad07-ee73-30f5-d9a8f1ed4f85@ovn.org>

On Mon Oct 2, 2023 at 9:54 PM AEST, Ilya Maximets wrote:
> On 9/28/23 03:52, Nicholas Piggin wrote:
> > On Wed Sep 27, 2023 at 6:36 PM AEST, Ilya Maximets wrote:
> >> On 9/27/23 02:13, Nicholas Piggin wrote:
> >>> Hi,
> >>>
> >>> We've got a report of a stack overflow on ppc64le with a 16kB kernel
> >>> stack. Openvswitch is just one of many things in the stack, but it
> >>> does cause recursion and contributes to some usage.
> >>>
> >>> Here are a few patches for reducing stack overhead. I don't know the
> >>> code well so consider them just ideas. GFP_ATOMIC allocations
> >>> introduced in a couple of places might be controversial, but there
> >>> is still some savings to be had if you skip those.
> >>>
> >>> Here is one place detected where the stack reaches >14kB before
> >>> overflowing a little later. I massaged the output so it just shows
> >>> the stack frame address on the left.
> >>
> >> Hi, Nicholas.  Thanks for the patches!
> > 
> > Hey, sorry your mail didn't come through for me (though it's on the
> > list)... Anyway thanks for the feedback.
> > 
> > And the important thing I forgot to mention: this was reproduced on a
> > RHEL9 kernel and that's where the traces are from. Upstream is quite
> > similar though so the code and call chains and stack use should be
> > pretty close.
> > 
> > It's a complicated configuration we're having difficulty with testing
> > upstream kernel. People are working to test things on the RHEL kernel
> > but I wanted to bring this upstream before we get too far down that
> > road.
> > 
> > Unfortunately that means I don't have performance or exact stack
> > use savings yet. But I will let you know if/when I get results.
> > 
> >> Though it looks like OVS is not really playing a huge role in the
> >> stack trace below.  How much of the stack does the patch set save
> >> in total?  How much patches 2-7 contribute (I posted a patch similar
> >> to the first one last week, so we may not count it)?
> > 
> > ovs functions themselves are maybe 30% of stack use, so significant.  I
> > did find they are the ones with some of the biggest structures in local
> > variables though, so low hanging fruit. This series should save about
> > 2kB of stack, by eyeball. Should be enough to get us out of trouble for
> > this scenario, at least.
>
> Unfortunately, the only low handing fruit in this set is patch #1,
> the rest needs a serious performance evaluation.
>
> > 
> > I don't suggest ovs is the only problem, I'm just trying to trim things
> > where possible. I have been trying to find other savings too, e.g.,
> > https://lore.kernel.org/linux-nfs/20230927001624.750031-1-npiggin@gmail.com/
> > 
> > Recursion is a difficulty. I think we recursed 3 times in ovs, and it
> > looks like there's either 1 or 2 more recursions possible before the
> > limit (depending on how the accounting works, not sure if it stops at
> > 4 or 5), so we're a long way off. ppc64le doesn't use an unusually large
> > amount of stack, probably more than x86-64, but shouldn't be by a big
> > factor. So it could be risky for any arch with 16kB stack.
>
> The stack trace looks like a very standard trace for something like
> an ovn-kubernetes setup.  And I haven't seen such issues on x86 or
> aarch64 systems.  What architectures beside ppc64le use 16kB stack?

AFAIKS from browsing defines of defaults for 64-bit builds, all I
looked at do (riscv, s390, loongarch, mips, sparc).

They will all be different about how much stack the compiler uses,
some type sizes that could be in local variables, and details of
kernel entry and how irq stacks are implemented. Would be interesting
to compare typical stack usage of different archs, I haven't made a
good study of it.

> > 
> > I wonder if we should have an arch function that can be called by
> > significant recursion points such as this, which signals free stack is
> > low and you should bail out ASAP. I don't think it's reasonable to
> > expect ovs to know about all arch size and usage of stack. You could
> > keep your hard limit for consistency, but if that goes wrong the
> > low free stack indication could save you.
>
> Every part of the code will need to react somehow to such a signal,
> so I'm not sure how the implementations would look like.

Not every, it can be few strategic checks. The recursion test that
is already in ovs, for example.

Thanks,
Nick

  reply	other threads:[~2023-10-04  9:56 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-27  0:13 [RFC PATCH 0/7] net: openvswitch: Reduce stack usage Nicholas Piggin
2023-09-27  0:13 ` [RFC PATCH 1/7] net: openvswitch: Move NSH buffer out of do_execute_actions Nicholas Piggin
2023-09-27  8:26   ` [ovs-dev] " Ilya Maximets
2023-09-27 10:03     ` Nicholas Piggin
2023-09-27  0:13 ` [RFC PATCH 2/7] net: openvswitch: Reduce execute_push_nsh stack overhead Nicholas Piggin
2023-09-27  0:13 ` [RFC PATCH 3/7] net: openvswitch: uninline action execution Nicholas Piggin
2023-09-27  0:13 ` [RFC PATCH 4/7] net: openvswitch: ovs_vport_receive reduce stack usage Nicholas Piggin
2023-09-28 15:26   ` [ovs-dev] " Aaron Conole
2023-09-29  7:00     ` Nicholas Piggin
2023-09-29  8:38       ` Eelco Chaudron
2023-10-04  7:11         ` Nicholas Piggin
2023-10-04 15:15           ` Aaron Conole
2023-10-05  2:01         ` Nicholas Piggin
2023-10-11 13:34           ` Aaron Conole
2023-10-11 23:58             ` Nicholas Piggin
2023-10-04  7:29     ` Nicholas Piggin
2023-10-04 15:16       ` Aaron Conole
2023-09-27  0:13 ` [RFC PATCH 5/7] net: openvswitch: uninline ovs_fragment to control " Nicholas Piggin
2023-09-27  0:13 ` [RFC PATCH 6/7] net: openvswitch: Reduce ovs_fragment " Nicholas Piggin
2023-09-27  0:13 ` [RFC PATCH 7/7] net: openvswitch: Reduce stack usage in ovs_dp_process_packet Nicholas Piggin
2023-09-27  8:36 ` [ovs-dev] [RFC PATCH 0/7] net: openvswitch: Reduce stack usage Ilya Maximets
2023-09-28  1:52   ` Nicholas Piggin
2023-10-02 11:54     ` Ilya Maximets
2023-10-04  9:56       ` Nicholas Piggin [this message]
2023-09-29  7:06   ` Nicholas Piggin
2023-10-02 11:56     ` Ilya Maximets
2023-10-03 13:31       ` Aaron Conole

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CVZKCOOZ2SF4.2DYPVWT5C2TDQ@wheely \
    --to=npiggin@gmail.com \
    --cc=aconole@redhat.com \
    --cc=dev@openvswitch.org \
    --cc=echaudro@redhat.com \
    --cc=horms@ovn.org \
    --cc=i.maximets@ovn.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).