Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
From: "Arnd Bergmann" <arnd@arndb.de>
To: "Zhu Yanjun" <yanjun.zhu@linux.dev>,
	"Arnd Bergmann" <arnd@kernel.org>,
	"Bernard Metzler" <bmt@zurich.ibm.com>,
	"Jason Gunthorpe" <jgg@ziepe.ca>,
	"Leon Romanovsky" <leon@kernel.org>,
	"Nathan Chancellor" <nathan@kernel.org>
Cc: "Nick Desaulniers" <nick.desaulniers+lkml@gmail.com>,
	"Bill Wendling" <morbo@google.com>,
	"Justin Stitt" <justinstitt@google.com>,
	"Potnuri Bharat Teja" <bharat@chelsio.com>,
	"Showrya M N" <showrya@chelsio.com>,
	"Eric Biggers" <ebiggers@google.com>,
	linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org,
	llvm@lists.linux.dev
Subject: Re: [PATCH] RDMA/siw: work around clang stack size warning
Date: Sat, 21 Jun 2025 10:43:03 +0200	[thread overview]
Message-ID: <ca2eaa50-c3ed-491d-ab38-65a7c1dc2820@app.fastmail.com> (raw)
In-Reply-To: <2d04fee6-5d95-4c50-b2b1-ee67f42932e2@linux.dev>

On Sat, Jun 21, 2025, at 06:12, Zhu Yanjun wrote:
> 在 2025/6/20 4:43, Arnd Bergmann 写道:
>
> Because the array of kvec structures in siw_tx_hdt consumes the majority 
> of the stack space, would it be possible to use kmalloc or a similar 
> dynamic memory allocation function instead of allocating this memory on 
> the stack?
>
> Would using kmalloc (or an equivalent) also effectively resolve the 
> stack usage issue?

Yes, moving the allocation somewhere else (kmalloc, static variable,
per siw_sge, per siw_wqe) would avoid the high stack usage effectively,
it's a tradeoff and I picked the solution that made the most sense
to me, but there is a good chance another alternative is better here.

The main differences are:

- kmalloc() adds runtime overhead that may be expensive in a
  fast path

- kmalloc() can fail, which adds complexity from error handling.
  Note that small allocations with GFP_KERNEL do not fail but instead
  wait for memory to become available

- If kmalloc() runs into a low-memory situation, it can go through
  writeback, which in turn can use more stack space than the
  on-stack allocation it was replacing

- static allocations bloat the kernel image and require locking that
  may be expensive

- per-object preallocations can be wasteful if a lot of objects
  are created, and can still require locking if the object is used
  from multiple threads

As I wrote, I mainly picked the 'noinline_for_stack' approach
here since that is how the code is known to work with gcc, so
there is little risk of my patch causing problems.

Moving the both the kvec array and the page array into
the siw_wqe is likely better here, I'm not familiar enough
with the driver to tell whether that is an overall improvement.

A related change I would like to see is to remove the
kmap_local_page() in this driver and instead make it
depend on 64BIT or !CONFIG_HIGHMEM, to slowly chip away
at the code that is highmem aware throughout the kernel.
I'm not sure if that that would also help drop the array
here.

     Arnd

  reply	other threads:[~2025-06-21  8:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-20 11:43 [PATCH] RDMA/siw: work around clang stack size warning Arnd Bergmann
2025-06-21  4:12 ` Zhu Yanjun
2025-06-21  8:43   ` Arnd Bergmann [this message]
2025-06-21 16:09     ` Zhu Yanjun
2025-06-22 13:29     ` Bernard Metzler
2025-06-24 10:47 ` Bernard Metzler
2025-06-25 11:14 ` 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=ca2eaa50-c3ed-491d-ab38-65a7c1dc2820@app.fastmail.com \
    --to=arnd@arndb.de \
    --cc=arnd@kernel.org \
    --cc=bharat@chelsio.com \
    --cc=bmt@zurich.ibm.com \
    --cc=ebiggers@google.com \
    --cc=jgg@ziepe.ca \
    --cc=justinstitt@google.com \
    --cc=leon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=morbo@google.com \
    --cc=nathan@kernel.org \
    --cc=nick.desaulniers+lkml@gmail.com \
    --cc=showrya@chelsio.com \
    --cc=yanjun.zhu@linux.dev \
    /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