aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2011-04-26 08:25:40 -0400
committerRuss Cox <rsc@golang.org>2011-04-26 08:25:40 -0400
commite2f9c733918f08e07ce9557ed5124a8e6453fddb (patch)
tree3997644dd87660f4a64aff78349fe57c9c56d119
parentb1deb3be7f7ff9ec43b65b1adc25fdaf7dce56bb (diff)
downloadgo-e2f9c733918f08e07ce9557ed5124a8e6453fddb.tar.gz
go-e2f9c733918f08e07ce9557ed5124a8e6453fddb.zip
runtime: more graceful out-of-memory crash
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
-rw-r--r--src/pkg/runtime/mcache.c2
-rw-r--r--src/pkg/runtime/mheap.c8
2 files changed, 8 insertions, 2 deletions
diff --git a/src/pkg/runtime/mcache.c b/src/pkg/runtime/mcache.c
index 0f41a0ebcd..e406211862 100644
--- a/src/pkg/runtime/mcache.c
+++ b/src/pkg/runtime/mcache.c
@@ -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;
diff --git a/src/pkg/runtime/mheap.c b/src/pkg/runtime/mheap.c
index 8061b7cf88..a36ac15ba1 100644
--- a/src/pkg/runtime/mheap.c
+++ b/src/pkg/runtime/mheap.c
@@ -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;