[PATCH] malloc: Fix mremap_chunk statistics [BZ #34706]
Wilco Dijkstra
Wilco.Dijkstra@arm.com
Wed Nov 11 17:17:07 GMT 2026
Hi DJ,
>> - new = atomic_fetch_add_relaxed (&mp_.mmapped_mem, new_size - size - offset)
>> - + new_size - size - offset;
>> + new = atomic_fetch_add_relaxed (&mp_.mmapped_mem, new_size - total_size)
>> + + new_size - total_size;
>> atomic_max (&mp_.max_mmapped_mem, new);
>
> I think this is right, but if we really want to monitor the change in
> the size of the chunk, we need to be careful we don't make this
> shortcut elsewhere where the mmapped size is not the chunk size. In
> this case, whatever we mmap gets added to the chunk, so OK, but in
> other cases it may not. A comment might be useful here too, like "All
> the new memory goes to the chunk, so we can simplify the math here." ?
We always counted the total mmap size, not the chunk size (which can be smaller
due to memalign). This code was making the old assumption that the offset plus
chunk size = total mmap size rather than using the new macros that give the correct
size. It's only off by a small amount, not wildly wrong.
Cheers,
Wilco
More information about the Libc-alpha
mailing list