[PATCH v3] malloc: Mark pages with MADV_DONTNEED to shrink and grow rather than mremap()

Wilco Dijkstra Wilco.Dijkstra@arm.com
Wed Aug 20 13:15:34 GMT 2025


Hi Florian,

> I'm not sure if this is a good idea.  I expect some (many?) applications
> expect that realloc returns memory from shrinking large allocations to
> the operating system.

Note we currently use MADV_DONTNEED to shrink heaps. It behaves like
munmap (ie. reducing RSS), except that the virtual mapping remains valid.

If you realloc to something much smaller then it will always call mremap()
to resize the virtual mapping - we can tweak the exact conditions as to
when that is desirable (also if say less than 4 pages, do nothing).

Cheers,
Wilco


More information about the Libc-alpha mailing list