From: Michael Anthony Knyszek Date: Tue, 18 Feb 2025 22:32:00 +0000 (+0000) Subject: runtime: minor mfinal.go code cleanup X-Git-Tag: go1.25rc1~974 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=57cd75a351a170e6ec6f3525972d16a3135b9398;p=gostls13.git runtime: minor mfinal.go code cleanup This change moves finBlockSize into mfinal.go and renames finblock to finBlock. Change-Id: I20a0bc3907e7b028a2caa5d2fe8cf3f76332c871 Reviewed-on: https://go-review.googlesource.com/c/go/+/650695 Auto-Submit: Michael Knyszek LUCI-TryBot-Result: Go LUCI Reviewed-by: Carlos Amedee Reviewed-by: Ian Lance Taylor --- diff --git a/src/runtime/mfinal.go b/src/runtime/mfinal.go index 4962a63a41..05d26e6cd6 100644 --- a/src/runtime/mfinal.go +++ b/src/runtime/mfinal.go @@ -14,19 +14,21 @@ import ( "unsafe" ) -// finblock is an array of finalizers to be executed. finblocks are -// arranged in a linked list for the finalizer queue. +const finBlockSize = 4 * 1024 + +// finBlock is an block of finalizers/cleanups to be executed. finBlocks +// are arranged in a linked list for the finalizer queue. // -// finblock is allocated from non-GC'd memory, so any heap pointers +// finBlock is allocated from non-GC'd memory, so any heap pointers // must be specially handled. GC currently assumes that the finalizer // queue does not grow during marking (but it can shrink). -type finblock struct { +type finBlock struct { _ sys.NotInHeap - alllink *finblock - next *finblock + alllink *finBlock + next *finBlock cnt uint32 _ int32 - fin [(_FinBlockSize - 2*goarch.PtrSize - 2*4) / unsafe.Sizeof(finalizer{})]finalizer + fin [(finBlockSize - 2*goarch.PtrSize - 2*4) / unsafe.Sizeof(finalizer{})]finalizer } var fingStatus atomic.Uint32 @@ -40,16 +42,15 @@ const ( fingWake ) -// This runs durring the GC sweep phase. Heap memory can't be allocated while sweep is running. var ( finlock mutex // protects the following variables fing *g // goroutine that runs finalizers - finq *finblock // list of finalizers that are to be executed - finc *finblock // cache of free blocks - finptrmask [_FinBlockSize / goarch.PtrSize / 8]byte + finq *finBlock // list of finalizers that are to be executed + finc *finBlock // cache of free blocks + finptrmask [finBlockSize / goarch.PtrSize / 8]byte ) -var allfin *finblock // list of all blocks +var allfin *finBlock // list of all blocks // NOTE: Layout known to queuefinalizer. type finalizer struct { @@ -108,7 +109,7 @@ func queuefinalizer(p unsafe.Pointer, fn *funcval, nret uintptr, fint *_type, ot lock(&finlock) if finq == nil || finq.cnt == uint32(len(finq.fin)) { if finc == nil { - finc = (*finblock)(persistentalloc(_FinBlockSize, 0, &memstats.gcMiscSys)) + finc = (*finBlock)(persistentalloc(finBlockSize, 0, &memstats.gcMiscSys)) finc.alllink = allfin allfin = finc if finptrmask[0] == 0 { diff --git a/src/runtime/mgc.go b/src/runtime/mgc.go index d10f3c09cf..25345abca9 100644 --- a/src/runtime/mgc.go +++ b/src/runtime/mgc.go @@ -135,8 +135,7 @@ import ( ) const ( - _DebugGC = 0 - _FinBlockSize = 4 * 1024 + _DebugGC = 0 // concurrentSweep is a debug flag. Disabling this flag // ensures all spans are swept while the world is stopped.