From 3409317a67c436c2e38cd54af03245377c3558aa Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Mon, 19 Jun 2023 22:38:58 -0700 Subject: [PATCH] lib/cgroup: add SetGOGC() function This function is going to be used by VictoriaLogs --- lib/cgroup/mem.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/cgroup/mem.go b/lib/cgroup/mem.go index f35d3cbad..93c127f08 100644 --- a/lib/cgroup/mem.go +++ b/lib/cgroup/mem.go @@ -34,6 +34,18 @@ func initGOGC() { } } +// SetGOGC sets GOGC to the given percent +func SetGOGC(percent int) { + if percent <= 0 { + return + } + if percent > 100 { + percent = 100 + } + gogc = percent + debug.SetGCPercent(gogc) +} + var gogc int // GetMemoryLimit returns cgroup memory limit