• Michael Anthony Knyszek's avatar
    runtime: ensure heap memstats are updated atomically · ae4534e6
    Michael Anthony Knyszek authored
    For the most part, heap memstats are already updated atomically when
    passed down to OS-level memory functions (e.g. sysMap). Elsewhere,
    however, they're updated with the heap lock.
    
    In order to facilitate holding the heap lock for less time during
    allocation paths, this change more consistently makes the update of
    these statistics atomic by calling mSysStat{Inc,Dec} appropriately
    instead of simply adding or subtracting. It also ensures these values
    are loaded atomically.
    
    Furthermore, an undocumented but safe update condition for these
    memstats is during STW, at which point using atomics is unnecessary.
    This change also documents this condition in mstats.go.
    
    Updates #35112.
    
    Change-Id: I87d0b6c27b98c88099acd2563ea23f8da1239b66
    Reviewed-on: https://go-review.googlesource.com/c/go/+/196638
    Run-TryBot: Michael Knyszek <mknyszek@google.com>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    Reviewed-by: default avatarAustin Clements <austin@google.com>
    ae4534e6
mgcscavenge.go 25 KB