[PATCH] malloc: Cleanup libc_realloc
Wilco Dijkstra
Wilco.Dijkstra@arm.com
Mon Jun 9 12:22:36 GMT 2025
Hi DJ,
> Why is this unneeded? Growing an mmap'd chunk into the rest of its page
> seems a useful optimization here.
See mremap_chunk():
/* No need to remap if the number of pages does not change. */
if (total_size == new_size)
return p;
And if that fails, we do:
/* Note the extra SIZE_SZ overhead. */
if (oldsize - SIZE_SZ >= nb)
return oldmem;
So it's repeating the same thing 3 times in slightly different ways... We likely
want to merge these 2 checks as well. And perhaps we could use madvise if
mremap fails. And we might want to do this not for a single page in large
allocations but use some slack.
(and yes, I believe the same would be good for small blocks too - obviously
both for growing and shrinking blocks given that software often calls realloc
too frequently for no good reason).
Cheers,
Wilco
More information about the Libc-alpha
mailing list