[PATCH 3/9] malloc: remove allocation from fastbin, and trim_fastbins
DJ Delorie
dj@redhat.com
Wed Nov 12 03:35:00 GMT 2025
Dev Jain <dev.jain@arm.com> writes:
> - TRIM_FASTBINS 0
Ok. We disabled this feature anyway.
> -/*
> - TRIM_FASTBINS controls whether free() of a very small chunk can
> - immediately lead to trimming. Setting to true (1) can reduce memory
> - footprint, but will almost always slow down programs that use a lot
> - of small chunks.
> -
> - Define this only if you are willing to give up some speed to more
> - aggressively reduce system-level memory footprint when releasing
> - memory in programs that use many small chunks. You can get
> - essentially the same effect by setting MXFAST to 0, but this can
> - lead to even greater slowdowns in programs using many small chunks.
> - TRIM_FASTBINS is an in-between compile-time option, that disables
> - only those chunks bordering topmost memory from being placed in
> - fastbins.
> -*/
> -
> -#ifndef TRIM_FASTBINS
> -#define TRIM_FASTBINS 0
> -#endif
> -
Ok.
> - Trim settings interact with fastbin (MXFAST) settings: Unless
> - TRIM_FASTBINS is defined, automatic trimming never takes place upon
> - freeing a chunk with size less than or equal to MXFAST. Trimming is
> - instead delayed until subsequent freeing of larger chunks. However,
> - you can still force an attempted trim by calling malloc_trim.
> + you can force an attempted trim by calling malloc_trim.
"you" needs to be capitalized in this case.
> - /*
> - If the size qualifies as a fastbin, first check corresponding bin.
> - This code is safe to execute even if av is not yet initialized, so we
> - can try it without checking, which saves some time on this fast path.
> - */
> -
> -#define REMOVE_FB(fb, victim, pp) \
> - do \
> - { \
> - victim = pp; \
> - if (victim == NULL) \
> - break; \
> - pp = REVEAL_PTR (victim->fd); \
> - if (__glibc_unlikely (pp != NULL && misaligned_chunk (pp))) \
> - malloc_printerr ("malloc(): unaligned fastbin chunk detected"); \
> - } \
> - while ((pp = atomic_compare_and_exchange_val_acq (fb, pp, victim)) \
> - != victim); \
Ok.
> - if ((unsigned long) (nb) <= (unsigned long) (get_max_fast ()))
> - {
> - idx = fastbin_index (nb);
> - . . .
> - }
> -
Ok.
> static void
> _int_free_chunk (mstate av, mchunkptr p, INTERNAL_SIZE_T size, int have_lock)
> {
> - mfastbinptr *fb; /* associated fastbin */
> -
> - /*
> - If eligible, place chunk on a fastbin so it can be found
> - and used quickly in malloc.
> - */
> -
> - if ((unsigned long)(size) <= (unsigned long)(get_max_fast ())
> -
> - . . .
> - }
> -
Ok.
> /*
> Consolidate other non-mmapped chunks as they arrive.
> */
>
> - else if (!chunk_is_mmapped(p)) {
> + if (!chunk_is_mmapped(p)) {
Ok.
LGTM other than the one capitalization fix.
Reviewed-by: DJ Delorie <dj@redhat.com>
More information about the Libc-alpha
mailing list