From d176e3d7c5bb50685c95aaf1e0e3133bea0ea57f Mon Sep 17 00:00:00 2001 From: Dmitriy Vyukov Date: Tue, 28 Jan 2014 22:38:39 +0400 Subject: [PATCH] runtime: prefetch next block in mallocgc json-1 cputime 99600000 98600000 -1.00% time 100005493 98859693 -1.15% garbage-1 cputime 15760000 15440000 -2.03% time 15791759 15471701 -2.03% LGTM=khr R=golang-codereviews, gobot, khr, dave CC=bradfitz, golang-codereviews, iant https://golang.org/cl/57310043 --- src/pkg/runtime/malloc.goc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/pkg/runtime/malloc.goc b/src/pkg/runtime/malloc.goc index 3dfa63dbec..b00d690aad 100644 --- a/src/pkg/runtime/malloc.goc +++ b/src/pkg/runtime/malloc.goc @@ -40,7 +40,7 @@ runtime·mallocgc(uintptr size, uintptr typ, uint32 flag) intgo rate; MCache *c; MCacheList *l; - MLink *v; + MLink *v, *next; byte *tiny; if(size == 0) { @@ -120,7 +120,10 @@ runtime·mallocgc(uintptr size, uintptr typ, uint32 flag) if(l->list == nil) runtime·MCache_Refill(c, TinySizeClass); v = l->list; - l->list = v->next; + next = v->next; + if(next != nil) // prefetching nil leads to a DTLB miss + PREFETCH(next); + l->list = next; l->nlist--; ((uint64*)v)[0] = 0; ((uint64*)v)[1] = 0; @@ -144,7 +147,10 @@ runtime·mallocgc(uintptr size, uintptr typ, uint32 flag) if(l->list == nil) runtime·MCache_Refill(c, sizeclass); v = l->list; - l->list = v->next; + next = v->next; + if(next != nil) // prefetching nil leads to a DTLB miss + PREFETCH(next); + l->list = next; l->nlist--; if(!(flag & FlagNoZero)) { v->next = nil; -- 2.48.1