Skip to content

Commit 0c12b63

Browse files
mknyszekgopherbot
authored andcommitted
_content/doc: update huge page details with max_ptes_none workarounds
Go 1.21.1 and Go 1.22 have ceased working around an issue with Linux kernel defaults for transparent huge pages that can result in excessive memory overheads. (https://bugzilla.kernel.org/show_bug.cgi?id=93111) Many Linux distributions disable huge pages altogether these days, so this problem isn't quite as far-reaching as it used to be. Also, the problem only affects Go programs with very particular memory usage patterns. That being said, because the runtime used to actively deal with this problem (but with some unpredictable behavior), it's preventing users that don't have a lot of control over their execution environment from upgrading to Go beyond Go 1.20. This adds documentation about this change in behavior in both the GC guide and the Go 1.21 release notes. For golang/go#64332. Change-Id: I29baaffcc678d08255364a3cd6f11211ce4164ba Reviewed-on: https://go-review.googlesource.com/c/website/+/547675 Auto-Submit: Michael Knyszek <[email protected]> Reviewed-by: Mauri de Souza Meneguzzo <[email protected]> Reviewed-by: Michael Pratt <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 8cd3591 commit 0c12b63

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

_content/doc/gc-guide.html

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,7 +1539,7 @@ <h3 id="Linux_transparent_huge_pages">Linux transparent huge pages (THP)</h3>
15391539
</p>
15401540
</li>
15411541
<li>
1542-
<p>
1542+
<p id="Linux_THP_max_ptes_none_workaround">
15431543
Set <code>/sys/kernel/mm/transparent_hugepage/khugepaged/max_ptes_none</code>
15441544
to <code>0</code>.
15451545
<br />
@@ -1551,8 +1551,18 @@ <h3 id="Linux_transparent_huge_pages">Linux transparent huge pages (THP)</h3>
15511551
runtime does to return memory to the OS</a>.
15521552
Before Go 1.21, the Go runtime tried to mitigate the negative effects of the
15531553
default setting, but it came with a CPU cost.
1554-
With Go 1.21+ and Linux 6.2+, the Go runtime will coalesce regular pages
1555-
into huge pages itself with its own more accurate heuristics.
1554+
With Go 1.21+ and Linux 6.2+, the Go runtime no longer mutates huge page
1555+
state.
1556+
<br />
1557+
<br />
1558+
If you experience an increase in memory usage when upgrading to Go 1.21.1 or
1559+
later, try applying this setting; it will likely resolve your issue.
1560+
As an additional workaround, you can call
1561+
<a href="/pkg/golang.org/x/sys/unix#Prctl">the <code>Prctl</code>
1562+
function</a> with <code>PR_SET_THP_DISABLE</code> to disable huge pages at
1563+
the process level, or you can set <code>GODEBUG=disablethp=1</code> (to be
1564+
added in Go 1.21.6 and Go 1.22) to disable huge pages for heap memory.
1565+
Note that the <code>GODEBUG</code> setting may be removed in a future release.
15561566
</p>
15571567
</li>
15581568
</ul>

_content/doc/go1.21.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,13 @@ now manages which parts of the heap may be backed by huge pages more
231231
explicitly. This leads to better utilization of memory: small heaps
232232
should see less memory used (up to 50% in pathological cases) while
233233
large heaps should see fewer broken huge pages for dense parts of the
234-
heap, improving CPU usage and latency by up to 1%.
234+
heap, improving CPU usage and latency by up to 1%. A consequence of this
235+
change is that the runtime no longer tries to work around a particular
236+
problematic Linux configuration setting, which may result in higher
237+
memory overheads. The recommended fix is to adjust the OS's huge page
238+
settings according to the [GC guide](/doc/gc-guide#Linux_transparent_huge_pages).
239+
However, other workarounds are available as well. See the [section on
240+
`max_ptes_none`](/doc/gc-guide#Linux_THP_max_ptes_none_workaround).
235241

236242
<!-- https://go.dev/issue/57069, https://go.dev/issue/56966 -->
237243
As a result of runtime-internal garbage collection tuning,

0 commit comments

Comments
 (0)