This is the mail archive of the glibc-bugs@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]

[Bug malloc/20646] sysmalloc incorrectly fails with custom morecore function


https://sourceware.org/bugzilla/show_bug.cgi?id=20646

--- Comment #4 from Guillaume Morin <guillaume at morinfr dot org> ---
I hear you but I am interpreting this comment in a different manner: that a
specific morecore() implementation must return continuous addresses which my
example and libhugetlbfs' morecore do guarantee.

libhugetlbfs' morecore obviously aligns its initial mapping on a 2MB boundary
usually leaving a gap.  My example does this to simulate the issue.

There is a MORECORE_CONTIGUOUS #define in the .c which defaults to true but can
be changed to false at compile time and this state can be changed at runtime
(set_noncontinous()).  So the code has to support both cases.

Furthermore, I think the comments in the code indicate that my interpretation
is correct.  It's making a distinction between non-contiguous blocks and a
foreign sbrk (which libhugetlbfs morecore would be)


          /*
             Otherwise, make adjustments:

           * If the first time through or noncontiguous, we need to call sbrk
              just to find out where the end of memory lies.

           * We need to ensure that all returned chunks from malloc will meet
              MALLOC_ALIGNMENT

           * If there was an intervening foreign sbrk, we need to adjust sbrk
              request size to account for fact that we will not be able to
              combine new space with existing space in old_top.

           * Almost all systems internally allocate whole pages at a time, in
              which case we might as well use the whole last page of request.
              So we allocate enough more memory to hit a page boundary now,
              which in turn causes future contiguous calls to page-align.
           */

Even when the continuous bit is set, the code clearly assumes it's possible for
the block not to be continous:

      /*
         If contiguous, we can subtract out existing space that we hope to
         combine with new space. We add it back later only if
         we don't actually get contiguous space.
       */

      if (contiguous (av))
        size -= old_size;

Let me know what you think

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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