HomeFreeBSD

malloc(9): extend contigmalloc(9) by a "slab cookie"

Description

malloc(9): extend contigmalloc(9) by a "slab cookie"

Extend kern_malloc.c internals to also cover contigmalloc(9) by a
"slab cookie" and not just malloc/malloc_large. This allows us to
call free(9) even on contigmalloc(9) addresses and deprecate
contigfree(9). Update the contigmalloc(9) man page accordingly.

The way this is done (free(9) working for contigmalloc) will hide the
UMA/VM bits from a consumer which may otherwise need to know whether
the original allocation was by malloc or contigmalloc by looking at
the cookie (likely via an accessor function). This simplifies
the implementation of consumers of mixed environments a lot.

This is preliminary work to allow LinuxKPI to be adjusted to better
play by the rules Linux puts out for various allocations.
Most of this was described/explained to me by jhb.

One may observe that realloc(9) is currently unchanged (and contrary
to [contig]malloc/[contig]free an implementation may need access
the "slab cookie" information given it will likely be implementation
dependent which allocation type to use if size changes beyond the
usable size of the initial allocation).

Described by: jhb
Sponsored by: The FreeBSD Foundation
Reviewed by: markj, kib
Differential Revision: https://reviews.freebsd.org/D45812

(cherry picked from commit 9e6544dd6e02c46b805d11ab925c4f3b18ad7a4b)

Details

Provenance
bzAuthored on Jun 30 2024, 7:00 PM
Reviewer
markj
Differential Revision
D45812: malloc(9): extend contigmalloc(9) by a "slab cookie"
Parents
rG6f58191b301d: mmccam: fix mmcsd disk aliases
Branches
Unknown
Tags
Unknown