This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Malloc Internals on the Wiki...


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]