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

Wilco Dijkstra Wilco.Dijkstra@arm.com
Fri Sep 5 16:46:20 GMT 2025


Hi Florian,

>>> I'm not too familiar with the Linux MM code.  How does MADV_DONTNEED
>>> affect the commit charge?
>>
>> It doesn't affect the VAS (and thus commit charge) - it just reduces RSS by
>> releasing the physical pages.
>
> Okay, then I think we need the check_may_shrink_heap there asa well.

That should be easy to add.

It may also be possible to munmap the tail when shrinking if mremap doesn't
exist or returns an error.

> This doesn't produce an unmapped region:
>
>      if ((char *) MMAP ((char *) h + new_size, diff, PROT_NONE,
>                         MAP_FIXED) == (char *) MAP_FAILED)

Wait, it's actually using mmap? How is that legal on a region that is already mmapped?
Shouldn't it use mprotect instead?

Cheers,
Wilco


More information about the Libc-alpha mailing list