This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: Malloc Internals on the Wiki...
- From: DJ Delorie <dj at redhat dot com>
- To: Rical Jasan <ricaljasan at pacific dot net>
- Cc: libc-alpha at sourceware dot org
- Date: Mon, 11 Jul 2016 16:42:33 -0400
- Subject: Re: Malloc Internals on the Wiki...
- Authentication-results: sourceware.org; auth=none
Rical Jasan <ricaljasan@pacific.net> writes:
> Few typos:
Fixed.
> In Malloc Algorithm, I know it's just an overview, but the flow seems
> strange at step 7. It says, "If we still have chunks in the fastbins,
> ...", but step 4 said, "...take everything in the fastbins...". How
> would there still be anything in the fastbins?
Step 4 only happens if the request is large. This might be a small
request, which is satisfied by splitting a large chunk. In that case,
we defer fastbin consolidation in case we don't need it.
> The rest of step 7 says, "...consolidate those and repeat the previous
> two steps." Step 6 ends with, "...search the appropriate large bin, and
> successively larger bins, until a large-enough chunk is found." If
> there are still chunks in the fastbins, and we wind up looping through 5
> and 6, are we looking for an even better candidate than before? It
> seems like we wouldn't do all that over again if we had found a suitable
> chunk.
The comment in malloc.c expands on the reason:
The outer loop here is needed because we might not realize until
near the end of malloc that we should have consolidated, so must
do so and retry. This happens at most once, and only when we would
otherwise need to expand memory to service a "small" request.