[PATCH] realloc: Limit chunk reuse to only growing requests [BZ #30579]

Siddhesh Poyarekar siddhesh@sourceware.org
Wed Jul 5 10:46:06 GMT 2023


On 2023-07-05 03:08, Nicolas Dusart wrote:
> Siddhesh, if you happen to find an heuristic that is suitable and can
> save reallocations for bigger shrinks, may I suggest to avoid reusing
> an option if the new behavior of this option does not fit exactly in
> the expectation of how it worked earlier ?

FWIW, the original optimization was not for shrinks; the shrinks came in 
as a side-effect and I thought it would be clever to allow shrinking up 
to trim threshold and didn't anticipate the broad impact then.  A number 
of distributions tend to rebase early and I had expected applications 
like redis to stumble over if anything was amiss, which didn't happen. 
I reckon the plasma desktop issue didn't get caught early because the 
proactive rebasers (Fedora, Suse Tumbleweed and Ubuntu) are primarily 
Gnome based.

In any case, this patch limits the optimization to growths only, which 
is far more convenient to reason because it grows into existing unused 
padding.  There's no real benefit to keeping parts of a block around in 
case of a shrinking allocation AFAICT.  This growth-into-padding 
optimization is also useful only because it's a relatively lightweight 
check; if it gets any more complex then it's probably not worth the effort.

Sid


More information about the Libc-alpha mailing list