[PATCH] realloc: Return unchanged if request is within usable size
Aurelien Jarno
aurelien@aurel32.net
Mon Jul 3 22:02:48 GMT 2023
Hi Siddhesh and Wilco,
On 2022-12-06 12:45, Wilco Dijkstra via Libc-alpha wrote:
> Hi Siddhesh,
>
> >> We do need to handle the case where the size is smaller than the usable size since
> >> we'd still want to free the unused portion if it is a significant fraction of the total size.
> >
> > I'll make this a function of trim_threshold so that the reuse happens
> > only if the difference between the request and usable size is less than
> > the trim_threshold.
>
> That's better, but that really only helps the mmap case, and all other reallocs will
> never release memory due to the 128KB default value of trim_threshold.
> That's something we should explicitly decide/document and remove any redundant
> code from realloc as a result.
This actually breaks the KDE Plasma Desktop, and more precisely
plasmashell when used with long configuration files [1] [2]. This commit
causes the virtual memory allocation to increase from ~2GB to ~11GB in
my testcase, while the resident memory basically stays stable. In turns
this prevent the clone syscall to work with the default kernel
overcommit configuration.
At this stage, I haven't identified the allocation pattern nor the
corresponding code in plasmashell.
Besides tweaking the configuration files, possible workarounds are
defining the glibc.malloc.trim_threshold GLIBC tunable to a low value
(for instance 128) or changing the vm.overcommit_memory kernel
configuration to 1. I guess the latter doesn't work on 32-bit
architectures though.
Regards,
Aurelien
[1] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1040140
[2] https://bbs.archlinux.org/viewtopic.php?id=283372
--
Aurelien Jarno GPG: 4096R/1DDD8C9B
aurelien@aurel32.net http://aurel32.net
More information about the Libc-alpha
mailing list