]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: round spans_size up to page boundary
authorShenghou Ma <minux.ma@gmail.com>
Tue, 11 Jun 2013 21:22:49 +0000 (05:22 +0800)
committerShenghou Ma <minux.ma@gmail.com>
Tue, 11 Jun 2013 21:22:49 +0000 (05:22 +0800)
in case we have weird (not page aligned) memory limit.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/10199043

src/pkg/runtime/malloc.goc

index 4d900d63b95c3660990423108789f3b365d89b5c..a1db66e1ad0d61b85787e7911f46dd020ff3fb1c 100644 (file)
@@ -351,6 +351,8 @@ runtime·mallocinit(void)
                arena_size = MaxMem;
                bitmap_size = arena_size / (sizeof(void*)*8/4);
                spans_size = arena_size / PageSize * sizeof(runtime·mheap.spans[0]);
+               // round spans_size to pages
+               spans_size = (spans_size + ((1<<PageShift) - 1)) & ~((1<<PageShift) - 1);
                p = runtime·SysReserve((void*)(0x00c0ULL<<32), bitmap_size + spans_size + arena_size);
        }
        if (p == nil) {
@@ -379,6 +381,8 @@ runtime·mallocinit(void)
                        arena_size = bitmap_size * 8;
                        spans_size = arena_size / PageSize * sizeof(runtime·mheap.spans[0]);
                }
+               // round spans_size to pages
+               spans_size = (spans_size + ((1<<PageShift) - 1)) & ~((1<<PageShift) - 1);
 
                // SysReserve treats the address we ask for, end, as a hint,
                // not as an absolute requirement.  If we ask for the end