mirror of
https://github.com/golang/go
synced 2024-11-19 20:54:39 -07:00
runtime: optimize markspan
Increases throughput by 2x on a memory hungry program on 8-node NUMA machine. LGTM=rsc R=rsc CC=golang-codereviews https://golang.org/cl/100230043
This commit is contained in:
parent
2e1ddeb136
commit
acb03b8028
@ -2785,7 +2785,7 @@ runtime·checkfreed(void *v, uintptr n)
|
|||||||
void
|
void
|
||||||
runtime·markspan(void *v, uintptr size, uintptr n, bool leftover)
|
runtime·markspan(void *v, uintptr size, uintptr n, bool leftover)
|
||||||
{
|
{
|
||||||
uintptr *b, off, shift, i;
|
uintptr *b, *b0, off, shift, i, x;
|
||||||
byte *p;
|
byte *p;
|
||||||
|
|
||||||
if((byte*)v+size*n > (byte*)runtime·mheap.arena_used || (byte*)v < runtime·mheap.arena_start)
|
if((byte*)v+size*n > (byte*)runtime·mheap.arena_used || (byte*)v < runtime·mheap.arena_start)
|
||||||
@ -2804,6 +2804,9 @@ runtime·markspan(void *v, uintptr size, uintptr n, bool leftover)
|
|||||||
p = v;
|
p = v;
|
||||||
if(leftover) // mark a boundary just past end of last block too
|
if(leftover) // mark a boundary just past end of last block too
|
||||||
n++;
|
n++;
|
||||||
|
|
||||||
|
b0 = nil;
|
||||||
|
x = 0;
|
||||||
for(; n-- > 0; p += size) {
|
for(; n-- > 0; p += size) {
|
||||||
// Okay to use non-atomic ops here, because we control
|
// Okay to use non-atomic ops here, because we control
|
||||||
// the entire span, and each bitmap word has bits for only
|
// the entire span, and each bitmap word has bits for only
|
||||||
@ -2812,8 +2815,15 @@ runtime·markspan(void *v, uintptr size, uintptr n, bool leftover)
|
|||||||
off = (uintptr*)p - (uintptr*)runtime·mheap.arena_start; // word offset
|
off = (uintptr*)p - (uintptr*)runtime·mheap.arena_start; // word offset
|
||||||
b = (uintptr*)runtime·mheap.arena_start - off/wordsPerBitmapWord - 1;
|
b = (uintptr*)runtime·mheap.arena_start - off/wordsPerBitmapWord - 1;
|
||||||
shift = off % wordsPerBitmapWord;
|
shift = off % wordsPerBitmapWord;
|
||||||
*b = (*b & ~(bitMask<<shift)) | (bitAllocated<<shift);
|
if(b0 != b) {
|
||||||
|
if(b0 != nil)
|
||||||
|
*b0 = x;
|
||||||
|
b0 = b;
|
||||||
|
x = 0;
|
||||||
|
}
|
||||||
|
x |= bitAllocated<<shift;
|
||||||
}
|
}
|
||||||
|
*b0 = x;
|
||||||
}
|
}
|
||||||
|
|
||||||
// unmark the span of memory at v of length n bytes.
|
// unmark the span of memory at v of length n bytes.
|
||||||
|
Loading…
Reference in New Issue
Block a user