Skip to content

Commit

Permalink
runtime: fix span unusedsince setup
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
dvyukov committed Feb 11, 2015
1 parent f3b73e0 commit e604c6e
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/runtime/mheap.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,7 @@ HaveSpan:
t.needzero = s.needzero
s.state = _MSpanStack // prevent coalescing with s
t.state = _MSpanStack
mHeap_FreeSpanLocked(h, t, false, false)
t.unusedsince = s.unusedsince // preserve age (TODO: wrong: t is possibly merged and/or deallocated at this point)
mHeap_FreeSpanLocked(h, t, false, false, s.unusedsince)
s.state = _MSpanFree
}
s.unusedsince = 0
Expand Down Expand Up @@ -395,7 +394,7 @@ func mHeap_Grow(h *mheap, npage uintptr) bool {
h_spans[p+s.npages-1] = s
atomicstore(&s.sweepgen, h.sweepgen)
s.state = _MSpanInUse
mHeap_FreeSpanLocked(h, s, false, true)
mHeap_FreeSpanLocked(h, s, false, true, 0)
return true
}

Expand Down Expand Up @@ -442,7 +441,7 @@ func mHeap_Free(h *mheap, s *mspan, acct int32) {
memstats.heap_alloc -= uint64(s.npages << _PageShift)
memstats.heap_objects--
}
mHeap_FreeSpanLocked(h, s, true, true)
mHeap_FreeSpanLocked(h, s, true, true, 0)
if trace.enabled {
traceHeapAlloc()
}
Expand All @@ -458,11 +457,11 @@ func mHeap_FreeStack(h *mheap, s *mspan) {
s.needzero = 1
lock(&h.lock)
memstats.stacks_inuse -= uint64(s.npages << _PageShift)
mHeap_FreeSpanLocked(h, s, true, true)
mHeap_FreeSpanLocked(h, s, true, true, 0)
unlock(&h.lock)
}

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

// Stamp newly unused spans. The scavenger will use that
// info to potentially give back some pages to the OS.
s.unusedsince = nanotime()
s.unusedsince = unusedsince
if unusedsince == 0 {
s.unusedsince = nanotime()
}
s.npreleased = 0

// Coalesce with earlier, later spans.
Expand Down

0 comments on commit e604c6e

Please sign in to comment.