From: Austin Clements Date: Tue, 14 Apr 2015 02:43:05 +0000 (-0400) Subject: runtime: fix freed page accounting in mHeap_ReclaimList X-Git-Tag: go1.5beta1~1118 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=69001e404ecd8a802c2c8bf87772e20f56ec78fd;p=gostls13.git runtime: fix freed page accounting in mHeap_ReclaimList mHeap_ReclaimList is asked to reclaim at least npages pages, but it counts the number of spans reclaimed, not the number of pages reclaimed. The number of spans reclaimed is strictly larger than the number of pages, so this is not strictly wrong, but it is forcing more reclamation than was intended by the caller, which delays large allocations. Fix this by increasing the count by the number of pages in the swept span, rather than just increasing it by 1. Fixes #9048. Change-Id: I5ae364a9837a6012e68fcd431bba000340cfd50c Reviewed-on: https://go-review.googlesource.com/8920 Reviewed-by: Dmitry Vyukov Reviewed-by: Rick Hudson --- diff --git a/src/runtime/mheap.go b/src/runtime/mheap.go index 7b4b046764..c78005c9af 100644 --- a/src/runtime/mheap.go +++ b/src/runtime/mheap.go @@ -286,15 +286,9 @@ retry: // swept spans are at the end of the list mSpanList_InsertBack(list, s) unlock(&h.lock) + snpages := s.npages if mSpan_Sweep(s, false) { - // TODO(rsc,dvyukov): This is probably wrong. - // It is undercounting the number of pages reclaimed. - // See golang.org/issue/9048. - // Note that if we want to add the true count of s's pages, - // we must record that before calling mSpan_Sweep, - // because if mSpan_Sweep returns true the span has - // been - n++ + n += snpages } lock(&h.lock) if n >= npages {