All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: "H. Peter Anvin" <hpa@zytor.com>
Cc: ksummit@lists.linux.dev
Subject: Re: [TECH TOPIC] Implementing malloc
Date: Mon, 29 Jun 2026 19:19:20 +0100	[thread overview]
Message-ID: <akK3KACxE9gIFZSH@casper.infradead.org> (raw)
In-Reply-To: <c48a77db-98a3-4860-ab30-bcbbe0884baa@zytor.com>

On Mon, Jun 29, 2026 at 09:48:25AM -0700, H. Peter Anvin wrote:
> On 2026-06-29 07:29, 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.
> 
> You *NEED* to understand that if you are going to program kernel code. There
> probably isn't anything more important, *really*.

There's a lot of kernel code where that's true.  malloc() is not The One
True Interface to allocate memory, and at this point I'm not advocating
for removing any of the existing ones.

But we do have code which just needs to allocate "some memory", doesn't
have any particularly weird restrictions, and where usability is more
important than "pedal to the metal".  An example might be something
like zlib.  It needs to allocate some temporary memory, and why have to

#ifdef __KERNEL__
#define malloc(x)	kvmalloc(x, GFP_KERNEL)
#endif

> The kernel is a memory manager first, a scheduler second, all else is commentary.

Some filesystem people might have things to say about that.  But
increasingly the kernel is just the runtime for eBPF programs ;-)

  reply	other threads:[~2026-06-29 18:19 UTC|newest]

Thread overview: 13+ 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 [this message]
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

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=akK3KACxE9gIFZSH@casper.infradead.org \
    --to=willy@infradead.org \
    --cc=hpa@zytor.com \
    --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.