<p>I am looking for resources that explains golang garbage collector and how to tune gc.</p>
<p>Does golang have the concept of eden and survivor space? And can golang switch gc strategy like concurrent mark sweep vs g1?</p>
<hr/>**评论:**<br/><br/>kostix: <pre><ol>
<li><p>The concurrent GC has been implemented in 1.5,
so see <a href="https://golang.org/doc/go1.5#gc" rel="nofollow">this</a>
and — most importantly — <a href="https://golang.org/s/go15gcpacing" rel="nofollow">this design doc</a>.</p>
<p>Basically, the only knob controlling the GC is the
<a href="https://golang.org/pkg/runtime/" rel="nofollow"><code>GOGC</code>env. variable</a>
and its <a href="https://golang.org/pkg/runtime/debug/#SetGCPercent" rel="nofollow"><code>runtime/debug.SetGCPercent()</code></a> counterpart.</p>
<p>You can also force garbage collection with <a href="https://golang.org/pkg/runtime/#GC" rel="nofollow"><code>runtime.GC()</code></a> but note that prior to 1.9 that
would be an STW operation.</p></li>
<li><p>No, you can't switch the GC strategy.
See <a href="https://blog.golang.org/go15gc" rel="nofollow">this</a> for backgrounds and the roadmap.</p></li>
</ol></pre>natefinch: <pre><p>It would be good to know what problem you're trying to solve. The garbage collector is intentionally not tweakable. This isn't java. The default works for the vast majority of cases.</p></pre>ChristophBerger: <pre><p>By pure chance, I just came across <a href="https://medium.com/samsara-engineering/running-go-on-low-memory-devices-536e1ca2fe8f" rel="nofollow">this post</a> that might be of help--scroll down to the section "Tuning the Garbage Collector", where the author describes how to tweak the GC for a low-memory scenario. </p>
<p>TL;DR: The GC only returns those pages to the OS that are unused for 5 minutes. To trigger this more frequently, use the method <code>FreeOSMemory()</code> from the <code>runtime/debug</code>package that forces a GC cycle and returns as much memory to the OS as possible.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传