]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: more graceful out-of-memory crash
authorRuss Cox <rsc@golang.org>
Tue, 26 Apr 2011 12:25:40 +0000 (08:25 -0400)
committerRuss Cox <rsc@golang.org>
Tue, 26 Apr 2011 12:25:40 +0000 (08:25 -0400)
Used to fault trying to access l->list->next
when l->list == nil after MCentral_AllocList.
Now prints

runtime: out of memory: no room in arena for 65536-byte allocation (536870912 in use)
throw: out of memory

followed by stack trace.

Fixes #1650.

R=r, dfc
CC=golang-dev
https://golang.org/cl/4446062

src/pkg/runtime/mcache.c
src/pkg/runtime/mheap.c

index 0f41a0ebcd30834cf5fb6c93cbc27fa487544f23..e406211862e3fe8bb86ca2cda389e05de3390d77 100644 (file)
@@ -22,6 +22,8 @@ runtime·MCache_Alloc(MCache *c, int32 sizeclass, uintptr size, int32 zeroed)
                // Replenish using central lists.
                n = runtime·MCentral_AllocList(&runtime·mheap.central[sizeclass],
                        runtime·class_to_transfercount[sizeclass], &first);
+               if(n == 0)
+                       runtime·throw("out of memory");
                l->list = first;
                l->nlist = n;
                c->size += n*size;
index 8061b7cf88838a5ac03f0394813e98c324035cba..a36ac15ba1941cd3163498cb5f968b1f5c0053ad 100644 (file)
@@ -180,8 +180,10 @@ MHeap_Grow(MHeap *h, uintptr npage)
        // Allocate a multiple of 64kB (16 pages).
        npage = (npage+15)&~15;
        ask = npage<<PageShift;
-       if(ask > h->arena_end - h->arena_used)
+       if(ask > h->arena_end - h->arena_used) {
+               runtime·printf("runtime: out of memory: no room in arena for %D-byte allocation (%D in use)\n", (uint64)ask, (uint64)(h->arena_used - h->arena_start));
                return false;
+       }
        if(ask < HeapAllocChunk && HeapAllocChunk <= h->arena_end - h->arena_used)
                ask = HeapAllocChunk;
 
@@ -191,8 +193,10 @@ MHeap_Grow(MHeap *h, uintptr npage)
                        ask = npage<<PageShift;
                        v = runtime·MHeap_SysAlloc(h, ask);
                }
-               if(v == nil)
+               if(v == nil) {
+                       runtime·printf("runtime: out of memory: operating system refused %D-byte allocation\n", (uint64)ask);
                        return false;
+               }
        }
        mstats.heap_sys += ask;