From 7c7cd69591440b565bde2bfb2c804a99a17999ad Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Mon, 27 Apr 2015 14:50:42 -0400 Subject: [PATCH] runtime: fix stack use accounting ReadMemStats accounts for stacks slightly differently than the runtime does internally. Internally, only stacks allocated by newosproc0 are accounted in memstats.stacks_sys and other stacks are accounted in heap_sys. readmemstats_m shuffles the statistics so all stacks are accounted in StackSys rather than HeapSys. However, currently, readmemstats_m assumes StackSys will be zero when it does this shuffle. This was true until commit 6ad33be. If it isn't (e.g., if something called newosproc0), StackSys+HeapSys will be different before and after this shuffle, and the Sys sum that was computed earlier will no longer agree with the sum of its components. Fix this by making the shuffle in readmemstats_m not assume that StackSys is zero. Fixes #10585. Change-Id: If13991c8de68bd7b85e1b613d3f12b4fd6fd5813 Reviewed-on: https://go-review.googlesource.com/9366 Reviewed-by: Russ Cox --- src/runtime/mstats.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/mstats.go b/src/runtime/mstats.go index 270449d0fd..098f5da8dc 100644 --- a/src/runtime/mstats.go +++ b/src/runtime/mstats.go @@ -176,7 +176,7 @@ func readmemstats_m(stats *MemStats) { memmove(unsafe.Pointer(stats), unsafe.Pointer(&memstats), sizeof_C_MStats) // Stack numbers are part of the heap numbers, separate those out for user consumption - stats.StackSys = stats.StackInuse + stats.StackSys += stats.StackInuse stats.HeapInuse -= stats.StackInuse stats.HeapSys -= stats.StackInuse } -- 2.50.0