[PATCH] malloc: Fix mremap_chunk statistics [BZ #34706]

DJ Delorie dj@redhat.com
Fri Nov 6 19:10:15 GMT 2026


> -  INTERNAL_SIZE_T size = chunksize (p);

Ok.

> -  cp = (char *) __mremap ((char *) block, total_size, new_size,
> -                          MREMAP_MAYMOVE);
> +  cp = (char *) __mremap ((char *) block, total_size, new_size, MREMAP_MAYMOVE);

Not needed, plus creates over-long line.

>    INTERNAL_SIZE_T new;
> -  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." ?

LGMT without the second change.
Reviewed-by: DJ Delorie <dj@redhat.com>



More information about the Libc-alpha mailing list