Skip to content

Commit e604c6e

Browse files
committed
runtime: fix span unusedsince setup
Update #8832 This is probably not the root cause of the issue. Resolve TODO about setting unusedsince on a wrong span. Change-Id: I69c87e3d93cb025e3e6fa80a8cffba6ad6ad1395 Reviewed-on: https://go-review.googlesource.com/4390 Reviewed-by: Keith Randall <[email protected]>
1 parent f3b73e0 commit e604c6e

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/runtime/mheap.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,7 @@ HaveSpan:
318318
t.needzero = s.needzero
319319
s.state = _MSpanStack // prevent coalescing with s
320320
t.state = _MSpanStack
321-
mHeap_FreeSpanLocked(h, t, false, false)
322-
t.unusedsince = s.unusedsince // preserve age (TODO: wrong: t is possibly merged and/or deallocated at this point)
321+
mHeap_FreeSpanLocked(h, t, false, false, s.unusedsince)
323322
s.state = _MSpanFree
324323
}
325324
s.unusedsince = 0
@@ -395,7 +394,7 @@ func mHeap_Grow(h *mheap, npage uintptr) bool {
395394
h_spans[p+s.npages-1] = s
396395
atomicstore(&s.sweepgen, h.sweepgen)
397396
s.state = _MSpanInUse
398-
mHeap_FreeSpanLocked(h, s, false, true)
397+
mHeap_FreeSpanLocked(h, s, false, true, 0)
399398
return true
400399
}
401400

@@ -442,7 +441,7 @@ func mHeap_Free(h *mheap, s *mspan, acct int32) {
442441
memstats.heap_alloc -= uint64(s.npages << _PageShift)
443442
memstats.heap_objects--
444443
}
445-
mHeap_FreeSpanLocked(h, s, true, true)
444+
mHeap_FreeSpanLocked(h, s, true, true, 0)
446445
if trace.enabled {
447446
traceHeapAlloc()
448447
}
@@ -458,11 +457,11 @@ func mHeap_FreeStack(h *mheap, s *mspan) {
458457
s.needzero = 1
459458
lock(&h.lock)
460459
memstats.stacks_inuse -= uint64(s.npages << _PageShift)
461-
mHeap_FreeSpanLocked(h, s, true, true)
460+
mHeap_FreeSpanLocked(h, s, true, true, 0)
462461
unlock(&h.lock)
463462
}
464463

465-
func mHeap_FreeSpanLocked(h *mheap, s *mspan, acctinuse, acctidle bool) {
464+
func mHeap_FreeSpanLocked(h *mheap, s *mspan, acctinuse, acctidle bool, unusedsince int64) {
466465
switch s.state {
467466
case _MSpanStack:
468467
if s.ref != 0 {
@@ -488,7 +487,10 @@ func mHeap_FreeSpanLocked(h *mheap, s *mspan, acctinuse, acctidle bool) {
488487

489488
// Stamp newly unused spans. The scavenger will use that
490489
// info to potentially give back some pages to the OS.
491-
s.unusedsince = nanotime()
490+
s.unusedsince = unusedsince
491+
if unusedsince == 0 {
492+
s.unusedsince = nanotime()
493+
}
492494
s.npreleased = 0
493495

494496
// Coalesce with earlier, later spans.

0 commit comments

Comments
 (0)