|
7 | 7 | package runtime
|
8 | 8 |
|
9 | 9 | import (
|
10 |
| - "internal/goarch" |
11 | 10 | "runtime/internal/atomic"
|
12 | 11 | "unsafe"
|
13 | 12 | )
|
@@ -565,29 +564,29 @@ func updatememstats() {
|
565 | 564 | memstats.heapStats.unsafeRead(&consStats)
|
566 | 565 |
|
567 | 566 | // Collect large allocation stats.
|
568 |
| - totalAlloc := uint64(consStats.largeAlloc) |
569 |
| - memstats.nmalloc += uint64(consStats.largeAllocCount) |
570 |
| - totalFree := uint64(consStats.largeFree) |
571 |
| - memstats.nfree += uint64(consStats.largeFreeCount) |
| 567 | + totalAlloc := consStats.largeAlloc |
| 568 | + memstats.nmalloc += consStats.largeAllocCount |
| 569 | + totalFree := consStats.largeFree |
| 570 | + memstats.nfree += consStats.largeFreeCount |
572 | 571 |
|
573 | 572 | // Collect per-sizeclass stats.
|
574 | 573 | for i := 0; i < _NumSizeClasses; i++ {
|
575 | 574 | // Malloc stats.
|
576 |
| - a := uint64(consStats.smallAllocCount[i]) |
| 575 | + a := consStats.smallAllocCount[i] |
577 | 576 | totalAlloc += a * uint64(class_to_size[i])
|
578 | 577 | memstats.nmalloc += a
|
579 | 578 | memstats.by_size[i].nmalloc = a
|
580 | 579 |
|
581 | 580 | // Free stats.
|
582 |
| - f := uint64(consStats.smallFreeCount[i]) |
| 581 | + f := consStats.smallFreeCount[i] |
583 | 582 | totalFree += f * uint64(class_to_size[i])
|
584 | 583 | memstats.nfree += f
|
585 | 584 | memstats.by_size[i].nfree = f
|
586 | 585 | }
|
587 | 586 |
|
588 | 587 | // Account for tiny allocations.
|
589 |
| - memstats.nfree += uint64(consStats.tinyAllocCount) |
590 |
| - memstats.nmalloc += uint64(consStats.tinyAllocCount) |
| 588 | + memstats.nfree += consStats.tinyAllocCount |
| 589 | + memstats.nmalloc += consStats.tinyAllocCount |
591 | 590 |
|
592 | 591 | // Calculate derived stats.
|
593 | 592 | memstats.total_alloc = totalAlloc
|
@@ -703,17 +702,20 @@ type heapStatsDelta struct {
|
703 | 702 | inPtrScalarBits int64 // byte delta of memory reserved for unrolled GC prog bits
|
704 | 703 |
|
705 | 704 | // Allocator stats.
|
706 |
| - tinyAllocCount uintptr // number of tiny allocations |
707 |
| - largeAlloc uintptr // bytes allocated for large objects |
708 |
| - largeAllocCount uintptr // number of large object allocations |
709 |
| - smallAllocCount [_NumSizeClasses]uintptr // number of allocs for small objects |
710 |
| - largeFree uintptr // bytes freed for large objects (>maxSmallSize) |
711 |
| - largeFreeCount uintptr // number of frees for large objects (>maxSmallSize) |
712 |
| - smallFreeCount [_NumSizeClasses]uintptr // number of frees for small objects (<=maxSmallSize) |
713 |
| - |
714 |
| - // Add a uint32 to ensure this struct is a multiple of 8 bytes in size. |
715 |
| - // Only necessary on 32-bit platforms. |
716 |
| - _ [(goarch.PtrSize / 4) % 2]uint32 |
| 705 | + // |
| 706 | + // These are all uint64 because they're cumulative, and could quickly wrap |
| 707 | + // around otherwise. |
| 708 | + tinyAllocCount uint64 // number of tiny allocations |
| 709 | + largeAlloc uint64 // bytes allocated for large objects |
| 710 | + largeAllocCount uint64 // number of large object allocations |
| 711 | + smallAllocCount [_NumSizeClasses]uint64 // number of allocs for small objects |
| 712 | + largeFree uint64 // bytes freed for large objects (>maxSmallSize) |
| 713 | + largeFreeCount uint64 // number of frees for large objects (>maxSmallSize) |
| 714 | + smallFreeCount [_NumSizeClasses]uint64 // number of frees for small objects (<=maxSmallSize) |
| 715 | + |
| 716 | + // NOTE: This struct must be a multiple of 8 bytes in size because it |
| 717 | + // is stored in an array. If it's not, atomic accesses to the above |
| 718 | + // fields may be unaligned and fail on 32-bit platforms. |
717 | 719 | }
|
718 | 720 |
|
719 | 721 | // merge adds in the deltas from b into a.
|
|
0 commit comments