]> Cypherpunks repositories - gostls13.git/commit
runtime: fix ReadMemStatsSlow's and CheckScavengedBits' chunk iteration
authorMichael Anthony Knyszek <mknyszek@google.com>
Wed, 9 Sep 2020 16:52:18 +0000 (16:52 +0000)
committerMichael Knyszek <mknyszek@google.com>
Wed, 9 Sep 2020 17:48:56 +0000 (17:48 +0000)
commit34835df04891a1d54394888b763af88f9476101d
tree6e903f81e4021e9d149a80b398c16918edfb0fd9
parent9ef3ee339634d1a349e7b9bb4cae32aacc326f61
runtime: fix ReadMemStatsSlow's and CheckScavengedBits' chunk iteration

Both ReadMemStatsSlow and CheckScavengedBits iterate over the page
allocator's chunks but don't actually check if they exist. During the
development process the chunks index became sparse, so now this was a
possibility. If the runtime tests' heap is sparse we might end up
segfaulting in either one of these functions, though this will generally
be very rare.

The pattern here to return nil for a nonexistent chunk is also useful
elsewhere, so this change introduces tryChunkOf which won't throw, but
might return nil. It also updates the documentation of chunkOf.

Fixes #41296.

Change-Id: Id5ae0ca3234480de1724fdf2e3677eeedcf76fa0
Reviewed-on: https://go-review.googlesource.com/c/go/+/253777
Run-TryBot: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
src/runtime/export_test.go
src/runtime/mpagealloc.go