Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are "safe point functions" as alluded to in the Go source code?

Tags:

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?

like image 358
merlin2011 Avatar asked Sep 28 '15 21:09

merlin2011


1 Answers

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.

like image 58
rudolph1024 Avatar answered Nov 15 '22 17:11

rudolph1024