runtime: TestMemStats is flaky #38712
The failure is
Given the timing, the most likely cause is the new
The text was updated successfully, but these errors were encountered:
What's particularly strange is the "bad sys value" since the way sys is set is very clear. In the darwin-amd64-10_12 builder, Sys is 256 KiB smaller than the sum of the values it's supposed to match. Maybe there's now an update to one of the values that goes into sys after sys is calculated but before the rest of the values are copied?
What this means for certain is that between the first few lines of
All the other stats are too small (<256 KiB) to be culprits operating under this assumption.
Given all the evidence (the timing implicating
Figured it out.
Consider the following chain of events:
The fix is to purge the
Currently mcaches are flushed to mcentral after a bunch of memstats have already been read. This is not safe (in the sense that it doesn't ensure consisent memstats) since memstats may in general change when mcentral data structures are manipulated. Note that prior to the new mcentral implementation this was not a problem because mcentral operations happened to never modify certain memstats. As of the new mcentral implementation, we might for example persistentalloc when uncaching a span, which would change memstats. This can cause a skew between the value of sys (which currently is calculated before mcaches are flushed) and the value of gc_sys and other_sys. Fix this by moving mcache flushing to the very top of updatememstats. Also leave a comment explaining that this must be done first, in general, because mcentrals make no guarantee that they will not influence memstats (and doing so would be unnecessarily restrictive). Fixes golang#38712. Change-Id: I15bacb313c54a46e380a945a71bb75db67169c1b Reviewed-on: https://go-review.googlesource.com/c/go/+/230498 Run-TryBot: Michael Knyszek <firstname.lastname@example.org> Reviewed-by: Russ Cox <email@example.com>