Skip to content

Commit 8d68b38

Browse files
mknyszekgopherbot
authored andcommitted
runtime: flush each idle P's page cache at the end of each GC cycle
Currently pages may linger in an idle P's page cache, hiding the memory from the scavenger precisely when it's useful to return memory to the OS and reduce the application's footprint. Change-Id: I49fbcd806b6c66991d1ca87949f76a9f06708e70 Reviewed-on: https://go-review.googlesource.com/c/go/+/453622 Run-TryBot: Michael Knyszek <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Michael Pratt <[email protected]> Auto-Submit: Michael Knyszek <[email protected]>
1 parent 96e8e62 commit 8d68b38

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/runtime/mgc.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,9 +1104,21 @@ func gcMarkTermination() {
11041104
// mcache before allocating, but idle Ps may not. Since this
11051105
// is necessary to sweep all spans, we need to ensure all
11061106
// mcaches are flushed before we start the next GC cycle.
1107+
//
1108+
// While we're here, flush the page cache for idle Ps to avoid
1109+
// having pages get stuck on them. These pages are hidden from
1110+
// the scavenger, so in small idle heaps a significant amount
1111+
// of additional memory might be held onto.
11071112
systemstack(func() {
11081113
forEachP(func(pp *p) {
11091114
pp.mcache.prepareForSweep()
1115+
if pp.status == _Pidle {
1116+
systemstack(func() {
1117+
lock(&mheap_.lock)
1118+
pp.pcache.flush(&mheap_.pages)
1119+
unlock(&mheap_.lock)
1120+
})
1121+
}
11101122
})
11111123
})
11121124
// Now that we've swept stale spans in mcaches, they don't

0 commit comments

Comments
 (0)