]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: fix heap coalescing bug introduced in cl/9802043
authorDmitriy Vyukov <dvyukov@google.com>
Fri, 31 May 2013 06:58:50 +0000 (10:58 +0400)
committerDmitriy Vyukov <dvyukov@google.com>
Fri, 31 May 2013 06:58:50 +0000 (10:58 +0400)
mheap.map become a pointer, so nelem(h->map) returns 1 rather than the map size.
As the result coalescing with subsequent spans does not happen.

R=golang-dev, khr
CC=golang-dev
https://golang.org/cl/9649046

src/pkg/runtime/mheap.c

index 354031ad031907bbfda3b816d0c9036e292d5a3d..11d78203de258d92f0d5733567af91c588b65758 100644 (file)
@@ -74,8 +74,7 @@ runtime·MHeap_MapSpans(MHeap *h)
        n = (uintptr)h->arena_used;
        if(sizeof(void*) == 8)
                n -= (uintptr)h->arena_start;
-       // Coalescing code reads spans past the end of mapped arena, thus +1.
-       n = (n / PageSize + 1) * sizeof(h->spans[0]);
+       n = n / PageSize * sizeof(h->spans[0]);
        n = ROUND(n, PageSize);
        if(h->spans_mapped >= n)
                return;
@@ -366,7 +365,7 @@ MHeap_FreeLocked(MHeap *h, MSpan *s)
                mstats.mspan_inuse = h->spanalloc.inuse;
                mstats.mspan_sys = h->spanalloc.sys;
        }
-       if(p+s->npages < nelem(h->spans) && (t = h->spans[p+s->npages]) != nil && t->state != MSpanInUse) {
+       if((p+s->npages)*sizeof(h->spans[0]) < h->spans_mapped && (t = h->spans[p+s->npages]) != nil && t->state != MSpanInUse) {
                tp = (uintptr*)(t->start<<PageShift);
                *sp |= *tp;     // propagate "needs zeroing" mark
                s->npages += t->npages;