838103616 bytes is 799 MiB (Mebibytes, the power-of-two-based prefix), which matches GC 13. (Note that the computation for the heap goal just divides by 1<<20, or 1 MiB.)
The discrepancy in GC count is probably due to the fact that the GC count value reported by the GC trace is *after* the increment in mark termination, but it reports the previous cycle's heap goal. This makes sense because the GC trace isn't reporting a count of completed GCs, but reporting on the Nth GC, which just finished. (This is why the GC trace count starts at 1 instead of 0.) More concretely, you'll observe that 799 MiB heap goal after 12 GCs have completed (your read of numgc), but you'll be reading that heap goal *during* the 13th GC cycle, which is what the GC trace is reporting on. On Tuesday, January 30, 2024 at 10:48:26 AM UTC-5 Michael Mitchell wrote: > Might it have something to do with the comment in mgc.go about how the > increment of memstats.numgc differs from the increment of GC cycles for > gctrace? memstats.numgc seems to get incremented earlier (after mark > termination) whereas gctrace waits until the sweep is done. > > // cycles is the number of completed GC cycles, where a GC > // cycle is sweep termination, mark, mark termination, and > // sweep. This differs from memstats.numgc, which is > // incremented at mark termination. > cycles uint32 > > On Monday, January 29, 2024 at 7:12:53 AM UTC-5 Michael Mitchell wrote: > >> In the twelfth garbage collection of a short program I ran, GC trace >> reports the goal heap size as 735 MB (see below for gc11, gc12 and gc13 >> from GC trace) I also checked runtime Memstats (see attached image), and >> it says the nextGC target after 12 GCs have run is 838103616. >> >> Should goal Heap Size of GC Trace and NextGC of runtime.Memstats not be >> the same? >> >> >> gc 11 @22.009s 0%: 0.004+12+0.034 ms clock, 0.019+0.13/11/0.94+0.13 ms >> cpu, 562->562->367 MB, 964 MB goal, 4 P >> >> gc 12 @32.925s 0%: 0.003+16+0.024 ms clock, 0.014+0/3.7/13+0.099 ms cpu, >> 410->410->399 MB, 735 MB goal, 4 P (forced) >> >> gc 13 @32.964s 0%: 0.019+21+0.036 ms clock, 0.079+0/21/0.56+0.14 ms cpu, >> 400->400->399 MB, 799 MB goal, 4 P (forced) >> > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/ecfdfe66-9de8-4936-9248-617e8a6a4d03n%40googlegroups.com.