Skip to content

Commit 5a37965

Browse files
mknyszekgopherbot
authored andcommitted
runtime: make mheap.pagesInUse an atomic.Uintptr
This change fixes an old TODO that made it a uint64 because it would make alignment within mheap more complicated. Now that we don't have to worry about it since we're using atomic types as much as possible, switch to using a Uintptr. This likely will improve performance a tiny bit on 32-bit platforms, but really it's mostly cleanup. Change-Id: Ie705799a111ccad977fc1f43de8b50cf611be303 Reviewed-on: https://go-review.googlesource.com/c/go/+/429221 Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Keith Randall <[email protected]> Auto-Submit: Michael Knyszek <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Michael Knyszek <[email protected]>
1 parent e28cc36 commit 5a37965

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

src/runtime/mheap.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,11 @@ type mheap struct {
100100
// accounting for current progress. If we could only adjust
101101
// the slope, it would create a discontinuity in debt if any
102102
// progress has already been made.
103-
pagesInUse atomic.Uint64 // pages of spans in stats mSpanInUse
104-
pagesSwept atomic.Uint64 // pages swept this cycle
105-
pagesSweptBasis atomic.Uint64 // pagesSwept to use as the origin of the sweep ratio
106-
sweepHeapLiveBasis uint64 // value of gcController.heapLive to use as the origin of sweep ratio; written with lock, read without
107-
sweepPagesPerByte float64 // proportional sweep ratio; written with lock, read without
108-
// TODO(austin): pagesInUse should be a uintptr, but the 386
109-
// compiler can't 8-byte align fields.
103+
pagesInUse atomic.Uintptr // pages of spans in stats mSpanInUse
104+
pagesSwept atomic.Uint64 // pages swept this cycle
105+
pagesSweptBasis atomic.Uint64 // pagesSwept to use as the origin of the sweep ratio
106+
sweepHeapLiveBasis uint64 // value of gcController.heapLive to use as the origin of sweep ratio; written with lock, read without
107+
sweepPagesPerByte float64 // proportional sweep ratio; written with lock, read without
110108

111109
// Page reclaimer state
112110

@@ -1379,7 +1377,7 @@ HaveSpan:
13791377
atomic.Or8(&arena.pageInUse[pageIdx], pageMask)
13801378

13811379
// Update related page sweeper stats.
1382-
h.pagesInUse.Add(int64(npages))
1380+
h.pagesInUse.Add(npages)
13831381
}
13841382

13851383
// Make sure the newly allocated span will be observed
@@ -1529,7 +1527,7 @@ func (h *mheap) freeSpanLocked(s *mspan, typ spanAllocType) {
15291527
print("mheap.freeSpanLocked - span ", s, " ptr ", hex(s.base()), " allocCount ", s.allocCount, " sweepgen ", s.sweepgen, "/", h.sweepgen, "\n")
15301528
throw("mheap.freeSpanLocked - invalid free")
15311529
}
1532-
h.pagesInUse.Add(-int64(s.npages))
1530+
h.pagesInUse.Add(-s.npages)
15331531

15341532
// Clear in-use bit in arena page bitmap.
15351533
arena, pageIdx, pageMask := pageIndexOf(s.base())

0 commit comments

Comments
 (0)