Re: [PATCH v2 1/2] tools/nolibc: stop rounding malloc() sizes up to 4096 bytes

From: Willy Tarreau

Date: Sat Sep 26 2026 - 13:23:47 EST


On Sat, Sep 26, 2026 at 05:50:28PM +0200, Thomas Weißschuh wrote:
> On 2026-09-26 10:24:13-0500, Danish Khateeb wrote:
> > malloc() rounds the size of each mapping up to a multiple of 4096,
> > presumably to align it to a page boundary. But the page size is not 4096
> > on all architectures, and mmap() and munmap() round the length up to the
> > page size themselves.
> >
> > Drop the rounding. As heap->len is no longer rounded up, growing a block
> > with realloc() now always creates a new mapping.
>
> The series looks good to me, but I want to hear from Willy before
> applying it.

Fine by me as well. I remembered there was something for mmap() that had
to be rounded to PAGE_SIZE but it's not len, it's the offset, so we're
fine here.

Also I've checked when __builtin_add_overflow() was added, and it's gcc 5
so we're fine here as well.

> > Assisted-by: LLM
> > Signed-off-by: Danish Khateeb <danishkhateeb03@xxxxxxxxx>
>
> I'll add a Suggested-by here when applying.

For the series:
Reviewed-by: Willy Tarreau <w@xxxxxx>

Thanks!
Willy