mirror of
https://github.com/AuxXxilium/kmod.git
synced 2024-11-23 23:10:53 +07:00
libkmod: improve realloc behavior for zstd outbuffer
The allocator in glibc has a particular quirk that successive reallocs on the same pointer are cheap, at the cost of excess memory fragmentation. Other allocators generally do not do this, so excessive reallocs become relatively expensive. Reducing the number of reallocations by using a more agressive strategy for buffer size increase makes performance better on those setups, e.g. musl libc, or generally any other allocator; on my Chimera Linux setup with Scudo allocator (LLVM) it doubles to triples the performance of running e.g. depmod. Signed-off-by: q66 <q66@chimera-linux.org> Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
This commit is contained in:
parent
a6f070b3e1
commit
8da7c1e088
@ -89,7 +89,11 @@ static int zstd_ensure_outbuffer_space(ZSTD_outBuffer *buffer, size_t min_free)
|
||||
if (buffer->size - buffer->pos >= min_free)
|
||||
return 0;
|
||||
|
||||
buffer->size += min_free;
|
||||
if (buffer->size < min_free)
|
||||
buffer->size = min_free;
|
||||
else
|
||||
buffer->size *= 2;
|
||||
|
||||
buffer->dst = realloc(buffer->dst, buffer->size);
|
||||
if (buffer->dst == NULL) {
|
||||
ret = -errno;
|
||||
|
Loading…
Reference in New Issue
Block a user