英文:
What are "safe point functions" as alluded to in the Go source code?
问题
在Go源代码的runtime/proc.go
文件中,有许多注释提到安全点函数,这些函数似乎与在安全时刻进行垃圾回收有关。然而,我找不到这些函数的定义。
安全点函数是什么,它们用于什么,有哪些示例函数?
英文:
In the file runtime/proc.go
of the Go source code, there are many comments referring to safe point functions, which appear to be related to points in time where it is safe to garbage collect. However, I could not find any definitions of these functions.
What are safe point functions, what are they used for, and what are some examples of such functions?
答案1
得分: 4
这是我在这个主题上找到的所有信息。
我在这里找到了一些关于Go的GC安全点的讨论。
从Go实现中使用的安全点来看,它们实际上与传统定义的安全点相同:
关键点,GC可以跟踪变量和寄存器的内容
同一讨论串中的另一个用户提到GC将抢占点折叠到函数前导中的堆栈检查中,并提供了以下来源:https://github.com/golang/go/issues/10958
根据golang-dev邮件列表上的这篇文章,安全点也被称为“调用点”。
为了了解Go的安全点的性质,我认为看一下它的GC的演变是很重要的。这篇文章提到了以下内容:
在Go 1.5之前,Go使用了并行的停止-全局(STW)收集器。
Go 1.5引入了并发收集器。
对于那个问题的另一个回答提到:
从Go 1.7开始,未绑定和潜在的非平凡的停止-全局(STW)时间的最后一个来源是堆栈重新扫描。
从1.8开始,最坏情况下的停止-全局时间已经得到改善。
此外,这里是Go的垃圾收集器的当前实现。如果你阅读评论,你会发现它是一个非代数标记-清除收集器。你可以在这里阅读更多信息:https://blog.plan99.net/modern-garbage-collection-911ef4f8bd8e#.udz1kjk3b
最后,这里是Gil Tene在golang-dev邮件列表上的一篇旧文章,他在文章中提到了使用移动垃圾收集器的动机。他在2012年时声称Go使用的是“保守的、非重定位的收集器”,并讨论了安全点的特性,这些特性可以允许长时间运行的垃圾收集器。
虽然Go的垃圾收集器已经在摆脱长时间暂停方面有所改进,现在是一个“并发的、三色的、标记-清除收集器”,但它仍然是一个非代数的GC。而且看起来Go的GC是建立在70年代的GC思想上,而不是现代的企业方法。
看起来Go对安全点的概念更符合传统的安全点概念,而不是具有允许代数垃圾收集的现代特性的安全点。
英文:
Here is everything I could dig up on this topic.
I found some discussion about Go's GC safepoints here.
It looks like safe points (as used in the Go implementation) are effectively the same as the traditional definition of a safe point:
> key points where the GC can track what all variables and registers
> hold
Another user on the same thread mentions that the GC
> folds the preemption points into the stack checks during function
> prologs
and that the source for this claim is the following: https://github.com/golang/go/issues/10958
According to this post on the golang-dev mailing list, safepoints are also called "call sites".
To gain some insight into the nature of Go's safepoints, I think it's important to look at the evolution of its GC. This post mentions the following:
> Prior to Go 1.5, Go has used a parallel stop-the-world (STW)
> collector.
>
> Go 1.5 introduces a concurrent collector.
Another answer to that question mentions:
> As of Go 1.7, the one remaining source of unbounded and potentially
> non-trivial stop-the-world (STW) time is stack re-scanning.
As of 1.8, it looks like worst-case stop-the-world times have been improved.
Also, here is the current implementation of Go's garbage collector. If you read through the comments, you'll see that it is a non-generational mark-sweep collector. You can read more about this here: https://blog.plan99.net/modern-garbage-collection-911ef4f8bd8e#.udz1kjk3b
Finally, here is an old post by Gil Tene on the golang-dev mailing list which motivates the use of a moving garbage collector. He claimed (at the time in 2012) that Go was using a "conservative, non-relocating collector" and he discussed the characteristics of safepoints which would permit a long-running garbage collector.
While Go's garbage collector has been moving away from long pauses and is now a "concurrent, tri-color, mark-sweep collector", it's still a non-generational GC. It also looks like Go's GC is building on GC ideas from the 70s rather than modern, enterprise approaches.
It looks like Go's notion of a safepoint is more in line with the traditional notion of a safepoint rather than a safepoint with modern qualities which permit generational garbage collection.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论