From: Patrisious Haddad <phaddad@nvidia.com>
To: Arnd Bergmann <arnd@arndb.de>, Arnd Bergmann <arnd@kernel.org>,
Leon Romanovsky <leon@kernel.org>, Jason Gunthorpe <jgg@ziepe.ca>
Cc: "Christian Göttsche" <cgzones@googlemail.com>,
"Serge E. Hallyn" <serge@hallyn.com>,
"Chiara Meiohas" <cmeiohas@nvidia.com>,
"Alexander Viro" <viro@zeniv.linux.org.uk>,
linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] RDMA/mlx5: reduce stack usage in mlx5_ib_ufile_hw_cleanup
Date: Tue, 10 Jun 2025 17:51:37 +0300 [thread overview]
Message-ID: <53621985-23fc-49e3-a402-4b6e2335a970@nvidia.com> (raw)
In-Reply-To: <a5c62d13-a8de-4efa-aa87-dfdf8a4e56bb@app.fastmail.com>
On 6/10/2025 1:31 PM, Arnd Bergmann wrote:
> External email: Use caution opening links or attachments
>
>
> On Tue, Jun 10, 2025, at 11:50, Patrisious Haddad wrote:
>> On 6/10/2025 12:28 PM, Arnd Bergmann wrote:
>>> void mlx5_ib_ufile_hw_cleanup(struct ib_uverbs_file *ufile)
>>> {
>>> - struct mlx5_async_cmd async_cmd[MAX_ASYNC_CMDS];
>>> + struct mlx5_async_cmd *async_cmd;
>> Please preserve reverse Christmas tree deceleration.
>>> struct ib_ucontext *ucontext = ufile->ucontext;
>>> struct ib_device *device = ucontext->device;
>>> struct mlx5_ib_dev *dev = to_mdev(device);
>>> @@ -2678,6 +2678,10 @@ void mlx5_ib_ufile_hw_cleanup(struct ib_uverbs_file *ufile)
>>> int head = 0;
>>> int tail = 0;
>>>
>>> + async_cmd = kcalloc(MAX_ASYNC_CMDS, sizeof(*async_cmd), GFP_KERNEL);
>>> + if (WARN_ON(!async_cmd))
>>> + return;
>> But honestly I'm not sure I like this, the whole point of this patch was
>> performance optimization for teardown flow, and this function is called
>> in a loop not even one time.
>>
>> So I'm really not sure about how much kcalloc can slow it down here, and
>> it failing is whole other issue.
> Generally speaking, kcalloc is fairly quick and won't fail here,
> but it can take some time under memory pressure if it ends up
> in memory reclaim.
>
>> I'm thinking out-loud here, but theoretically we know stack size and
>> this struct size at compile time , so can we should be able to add some
>> kind of ifdef check "if (stack_frame_size < struct_size)" skip this
>> function and maybe print some warning.
>> (since it is purely optimization function and logically the code will
>> continue correctly without it - but if it needs to be executed then let
>> it stay like this and needs a big enough stack - which is most of today
>> systems anyway) ?
> The thing I'm most interested here is the compile-time warning:
> we currently have some configurations that have a very high warning
> limit of 2048 bytes or even unlimited, which means that a number
> of functions that accidentally use too much stack space (either from
> a compiler misoptimization or a programmer error) are missed and
> can end up causing problems later. I posted this patch as part of
> a larger work to eventually reduce the default warning limit
> for those corner cases.
>
> The risk in this particular function to actually overflow is fairly
> low since it gets called from sys_close() or __fput(), which
> are not nested deeply. I can think of a couple of other ways to
> keep your fast path and also build cleanly with a lower warning
> limit.
>
> - check which exact configurations actually trigger the high stack
> usage and then skip the optimization in those cases. The most
> likely causes are CONFIG_KASAN_STACK and CONFIG_KMSAN, both
> of which already make the kernel a lot slower.
Personally I prefer this option the most.
But If I were you I would wait to hear if the maintainers got a problem
with that approach ...
>
> - reduce MAX_ASYNC_CMDS to always stay under the warning limit, either
> picking a lower value unconditionally, or based on the Kconfig
> options that trigger it
No the number 8 wasn't chosen arbitrarily it also due to performance
reasons, whereas note that it is also the number
of commands that can be sent in parallel for destruction so reducing it
isn't ideal.
>
> - preallocate the array as part of an existing structure, whichever
> makes sense here (mlx5_ib_dev maybe?).
Can work but not ideal.
>
> - reorganize the code in some other form to have the stack not
> blow the warning limit. As far as I can tell, I only see this
> particular one with clang but not gcc, and that often means
> it happens because of some particular inlining decisions that
> clang takes, and we can force them by adding strategic
> __always_inline or noinline annotations that make both compilers
> do the same thing.
Sounds like the hardest option to implement but I have no quarrel with it.
>
> Arnd
next prev parent reply other threads:[~2025-06-10 14:51 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-10 9:28 [PATCH] RDMA/mlx5: reduce stack usage in mlx5_ib_ufile_hw_cleanup Arnd Bergmann
2025-06-10 9:50 ` Patrisious Haddad
2025-06-10 10:31 ` Arnd Bergmann
2025-06-10 14:51 ` Patrisious Haddad [this message]
2025-06-12 9:05 ` Leon Romanovsky
2025-06-12 9:05 ` Leon Romanovsky
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=53621985-23fc-49e3-a402-4b6e2335a970@nvidia.com \
--to=phaddad@nvidia.com \
--cc=arnd@arndb.de \
--cc=arnd@kernel.org \
--cc=cgzones@googlemail.com \
--cc=cmeiohas@nvidia.com \
--cc=jgg@ziepe.ca \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=serge@hallyn.com \
--cc=viro@zeniv.linux.org.uk \
/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