thoughs on splitting up malloc.c

DJ Delorie dj@redhat.com
Fri Aug 29 21:11:43 GMT 2025


I've already heard one request to move the stdio-dependent parts out
of malloc.c to reduce static linking size.  That and my recent
additions got me thinking about splitting it up.  It's a mess.

arena.c is already a separate file, but it's #included at a key point
in malloc.c instead of being truly independent.

malloc-internal.h is mostly empty and looks like it's only rarly used,
but is used by other modules in libc.

malloc.h is what we install.

A large chunk of malloc.c at the beginning is all structs and defines,
mixed together.  The first real function is on line 1656 but there's a
couple hundred more lines of structs and defines after that.

arena.c is a mix of structs and defines, arena support routines, and -
for some reason - tunables.  It's included on line 2081 of malloc.c.

So I propose we move all the definitions and declarations into
malloc-internal.h and split up malloc.c/arena.c into compilable
modules as such:

* minimum needed for malloc() and free() that isn't listed below

* realloc()

* calloc()

* the various memalign() clones

* tunables-related stuff, mallopt

* tcache-related routines (mostly in tcache.h for inline functions, but init/fini need .c)

* mallinfo and malloc_info get their own files

etc.

Thoughts?



More information about the Libc-alpha mailing list