Commit 69001e40 authored by Austin Clements's avatar Austin Clements

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/8920Reviewed-by: default avatarDmitry Vyukov <dvyukov@google.com>
Reviewed-by: default avatarRick Hudson <rlh@golang.org>
parent bedb6f8a
......@@ -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 {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment