All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: Kees Cook <kees@kernel.org>
Cc: ksummit@lists.linux.dev
Subject: Re: [TECH TOPIC] Implementing malloc
Date: Thu, 9 Jul 2026 18:11:21 +0100	[thread overview]
Message-ID: <ak_WOfpcaZIuh99t@casper.infradead.org> (raw)
In-Reply-To: <202607090956.6381F35@keescook>

On Thu, Jul 09, 2026 at 09:58:37AM -0700, Kees Cook wrote:
> On Mon, Jun 29, 2026 at 03:29:42PM +0100, Matthew Wilcox wrote:
> > malloc() is a standard part of the C library.  Yet we force new Linux
> > programmers to learn the difference between vmalloc(), kmalloc() and
> > kvmalloc().  They even have to acquire an understanding of the difference
> > between GFP_KERNEL and GFP_ATOMIC.  If they are particularly unlucky,
> > they may have to understand other combinations of GFP flags.
> > 
> > This topic proposes that we should implement malloc() and calloc().
> > Various options will be discussed, their increasing implementation
> > complexity corresponding to utility in a greater range of situations.
> > This will also benefit Rust as we can use the same infrastructure to
> > implement std::alloc.
> 
> No surprise, but I strongly disagree with this. Those APIs are flawed
> and we shouldn't emulate them. This is why we just removed strncpy(),
> for example.
> 
> Allocations need to be type-based, not size-based. When we force people
> to reduce it to just byte count tons of metadata that can be used by
> both the kernel and the compiler is lost. The size is a by-product of
> "what do you need space for?" "I need X many Foo objects" or "I need
> Bar with Z many trailing Baz objects" or even "I need a plane of pixels
> X by Y". The uncommon case is "I need X many bytes from this stream".

I agree that many memory allocations benefit from providing more semantic
information to both the compiler and the runtime, as you suggest.
What I don't think we benefit from is "And you have to pass this magic
GFP_KERNEL argument too.  Unless it's GFP_ATOMIC or something".

Maybe I'm confusing / distracting by framing this around "Hey, malloc()
is a great interface and we should implement it" when what I really mean
is "GFP flags suck and we should strive to redesign the kernel so that
the vast majority of allocations don't need them".

I'm happy to rephrase the proposal in that way if it'll help.  I thought
that malloc() would be the right vehicle for getting my point across,
but it seems to be a distraction.

What I really don't want to see is a whole pile of Rust changes to
accommodate having to pass GFP flags to memory allocations.  Would that
be a better vehicle for the discussion?

  reply	other threads:[~2026-07-09 17:11 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-29 14:29 [TECH TOPIC] Implementing malloc Matthew Wilcox
2026-06-29 15:07 ` Dan Carpenter
2026-06-29 15:21   ` H. Peter Anvin
2026-06-29 15:31   ` Matthew Wilcox
2026-06-29 16:00     ` Vlastimil Babka (SUSE)
2026-06-29 16:37     ` H. Peter Anvin
2026-06-29 16:48 ` Alexey Dobriyan
2026-06-29 16:48 ` H. Peter Anvin
2026-06-29 18:19   ` Matthew Wilcox
2026-06-29 18:22     ` H. Peter Anvin
2026-06-29 18:29     ` Mark Brown
2026-06-29 18:37       ` Vlastimil Babka (SUSE)
2026-06-30 18:53     ` Steven Rostedt
2026-07-09 16:58 ` Kees Cook
2026-07-09 17:11   ` Matthew Wilcox [this message]
2026-07-09 17:30     ` H. Peter Anvin
2026-07-09 17:39       ` Greg KH
2026-07-09 17:42       ` Miguel Ojeda
2026-07-09 17:40     ` Miguel Ojeda
2026-07-09 18:18       ` H. Peter Anvin
2026-07-09 18:44         ` Miguel Ojeda
2026-07-09 18:50           ` H. Peter Anvin
2026-07-09 19:04             ` Miguel Ojeda
2026-07-09 18:42     ` Dan Carpenter
2026-07-09 18:45       ` Matthew Wilcox
2026-07-09 19:13         ` Linus Torvalds
2026-07-10 11:21       ` Geert Uytterhoeven
2026-07-10 11:44         ` Laurent Pinchart
2026-07-10 12:16         ` Joe Perches

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=ak_WOfpcaZIuh99t@casper.infradead.org \
    --to=willy@infradead.org \
    --cc=kees@kernel.org \
    --cc=ksummit@lists.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.