Commits

Dave Cheney  committed d2d54e5

runtime: use uintptr where possible in malloc stats

linux/arm OMAP4 pandaboard

benchmark old ns/op new ns/op delta
BenchmarkBinaryTree17 6872329700037026214000 -46.12%
BenchmarkFannkuch11 3496240200035958435000 +2.85%
BenchmarkGobDecode 137298600124182150 -9.55%
BenchmarkGobEncode 6071716060006700 -1.17%
BenchmarkGzip 56471560005550873000 -1.70%
BenchmarkGunzip 11963500001198670000 +0.19%
BenchmarkJSONEncode 863012800782898000 -9.28%
BenchmarkJSONDecode 33129890002781800000 -16.03%
BenchmarkMandelbrot200 4572754045703120 -0.05%
BenchmarkParse 7478180059990840 -19.78%
BenchmarkRevcomp 140043650139462300 -0.42%
BenchmarkTemplate 64676820005832153000 -9.83%

benchmark old MB/s new MB/s speedup
BenchmarkGobDecode 5.59 6.18 1.11x
BenchmarkGobEncode 12.64 12.79 1.01x
BenchmarkGzip 3.44 3.50 1.02x
BenchmarkGunzip 16.22 16.19 1.00x
BenchmarkJSONEncode 2.25 2.48 1.10x
BenchmarkJSONDecode 0.59 0.70 1.19x
BenchmarkParse 0.77 0.97 1.26x
BenchmarkRevcomp 18.15 18.23 1.00x
BenchmarkTemplate 0.30 0.33 1.10x

darwin/386 core duo

benchmark old ns/op new ns/op delta
BenchmarkBinaryTree17 105916165779678245733 -8.62%
BenchmarkFannkuch11 1075847331510749303846 -0.09%
BenchmarkGobDecode 3437978534121250 -0.75%
BenchmarkGobEncode 2352372123475750 -0.20%
BenchmarkGzip 24861914922446539568 -1.59%
BenchmarkGunzip 444179328444250293 +0.02%
BenchmarkJSONEncode 221138507219757826 -0.62%
BenchmarkJSONDecode 10560344281048975133 -0.67%
BenchmarkMandelbrot200 1986251619868346 +0.03%
BenchmarkRevcomp 37426108723724821662 -0.48%
BenchmarkTemplate 960283112944791517 -1.61%

benchmark old MB/s new MB/s speedup
BenchmarkGobDecode 22.33 22.49 1.01x
BenchmarkGobEncode 32.63 32.69 1.00x
BenchmarkGzip 7.80 7.93 1.02x
BenchmarkGunzip 43.69 43.68 1.00x
BenchmarkJSONEncode 8.77 8.83 1.01x
BenchmarkJSONDecode 1.84 1.85 1.01x
BenchmarkRevcomp 67.91 68.24 1.00x
BenchmarkTemplate 2.02 2.05 1.01x

R=rsc, 0xe2.0x9a.0x9b, mirtchovski
CC=golang-dev, minux.ma
http://codereview.appspot.com/6297047

Committer: Russ Cox <rsc@golang.org>

  • Participants
  • Parent commits 86c67b7

Comments (0)

Files changed (2)

File src/pkg/runtime/malloc.goc

 		// setup for mark sweep
 		runtime·markspan(v, 0, 0, true);
 	}
+
+	if (sizeof(void*) == 4 && c->local_total_alloc >= (1<<30)) {
+		// purge cache stats to prevent overflow
+		runtime·lock(&runtime·mheap);
+		runtime·purgecachedstats(m);
+		runtime·unlock(&runtime·mheap);
+	}
+
 	if(!(flag & FlagNoGC))
 		runtime·markallocated(v, size, (flag&FlagNoPointers) != 0);
 
 	MSpan *s;
 
 	m->mcache->local_nlookup++;
+	if (sizeof(void*) == 4 && m->mcache->local_nlookup >= (1<<30)) {
+		// purge cache stats to prevent overflow
+		runtime·lock(&runtime·mheap);
+		runtime·purgecachedstats(m);
+		runtime·unlock(&runtime·mheap);
+	}
+
 	s = runtime·MHeap_LookupMaybe(&runtime·mheap, v);
 	if(sp)
 		*sp = s;

File src/pkg/runtime/malloc.h

 struct MCache
 {
 	MCacheList list[NumSizeClasses];
-	uint64 size;
-	int64 local_cachealloc;	// bytes allocated (or freed) from cache since last lock of heap
-	int64 local_objects;	// objects allocated (or freed) from cache since last lock of heap
-	int64 local_alloc;	// bytes allocated (or freed) since last lock of heap
-	int64 local_total_alloc;	// bytes allocated (even if freed) since last lock of heap
-	int64 local_nmalloc;	// number of mallocs since last lock of heap
-	int64 local_nfree;	// number of frees since last lock of heap
-	int64 local_nlookup;	// number of pointer lookups since last lock of heap
+	uintptr size;
+	intptr local_cachealloc;	// bytes allocated (or freed) from cache since last lock of heap
+	intptr local_objects;	// objects allocated (or freed) from cache since last lock of heap
+	intptr local_alloc;	// bytes allocated (or freed) since last lock of heap
+	uintptr local_total_alloc;	// bytes allocated (even if freed) since last lock of heap
+	uintptr local_nmalloc;	// number of mallocs since last lock of heap
+	uintptr local_nfree;	// number of frees since last lock of heap
+	uintptr local_nlookup;	// number of pointer lookups since last lock of heap
 	int32 next_sample;	// trigger heap sample after allocating this many bytes
 	// Statistics about allocation size classes since last lock of heap
 	struct {
-		int64 nmalloc;
-		int64 nfree;
+		uintptr nmalloc;
+		uintptr nfree;
 	} local_by_size[NumSizeClasses];
 
 };