linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Mike Rapoport <rppt@kernel.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Guo Weikang <guoweikang.kernel@gmail.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v8] mm/memblock: Add memblock_alloc_or_panic interface
Date: Fri, 10 Jan 2025 12:15:31 +0200	[thread overview]
Message-ID: <Z4DzQ60u0iNEwdjZ@kernel.org> (raw)
In-Reply-To: <20250102150835.776fe72f565cc3232d83e6a7@linux-foundation.org>

Hi Andrew,

On Thu, Jan 02, 2025 at 03:08:35PM -0800, Andrew Morton wrote:
> On Thu,  2 Jan 2025 15:25:28 +0800 Guo Weikang <guoweikang.kernel@gmail.com> wrote:
> 
> > Before SLUB initialization, various subsystems used memblock_alloc to
> > allocate memory. In most cases, when memory allocation fails, an immediate
> > panic is required. To simplify this behavior and reduce repetitive checks,
> > introduce `memblock_alloc_or_panic`. This function ensures that memory
> > allocation failures result in a panic automatically, improving code
> > readability and consistency across subsystems that require this behavior.
> 
> Just to be annoying...
> 
> We now have many more calls to memblock_alloc_or_panic() than to
> memblock_alloc().  So perhaps memblock_alloc() should default to
> panicing and we add a new memblock_alloc_no_panic() for the exceptional
> cases.

I'd prefer the API to be explicit about what it does.
memblock_alloc_or_panic() is indeed longer, but it emphasizes what it does,
while memblock_alloc() that panics does not.

I also wouldn't want to duplicate all memblock_alloc* with _panic or
_nopanic versions.
 
> And from looking around a bit, I think many of the remaining calls to
> memblock_alloc() could be made to panic on failure anyway.  If the
> kernel cannot successfully execute memblock_alloc(small amount) at
> __init time then the kernel is hopelessly broken and there's no point
> in proceeding?
> 
> In fact I wonder if there is really any legitimate use of
> memblock_alloc_no_panic()?

At the very least the caller has more context and can print something more
descriptive than "failed to allocate X bytes". And I think sometimes the
boot can continue with reduced functionality. I don't have examples with
memblock_alloc() from the top of my head, but e.g. failure to reserve crash
kernel is really not a fatal error.

-- 
Sincerely yours,
Mike.


      parent reply	other threads:[~2025-01-10 10:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-02  7:25 [PATCH v8] mm/memblock: Add memblock_alloc_or_panic interface Guo Weikang
2025-01-02  9:12 ` Geert Uytterhoeven
2025-01-02 23:08 ` Andrew Morton
2025-01-03  0:29   ` Weikang Guo
2025-01-10 10:15   ` Mike Rapoport [this message]

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=Z4DzQ60u0iNEwdjZ@kernel.org \
    --to=rppt@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=guoweikang.kernel@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.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).