Help us shape the future of Go! Take the 2026 Go Developer Survey

memlimit

package
v0.55.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 2, 2026 License: BSD-2-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package memlimit applies the container's memory ceiling to the Go runtime.

Without it the runtime never learns the cgroup limit: GOGC defaults to 100, so the heap may grow to twice the live set before a collection is forced, regardless of how much memory the container is actually allowed to use. An executor whose live heap is ~108MiB therefore targets ~216MiB and is OOM-killed by a 256Mi limit it was never told about.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyFromCgroup

func ApplyFromCgroup()

ApplyFromCgroup reads the container's memory limit and applies it to the Go runtime as a soft memory limit.

An explicit GOMEMLIMIT wins: the runtime has already applied it, and overwriting it here would silently discard an operator's setting. A missing or unlimited cgroup file leaves the runtime's own default in place, so the function never lowers a limit it could not read.

func ParseCgroupLimit

func ParseCgroupLimit(raw string) (int64, bool)

ParseCgroupLimit converts a cgroup memory file's contents into a byte count.

It reports false for the three shapes that do not name a real ceiling: cgroup v2's "max", an empty file, and cgroup v1's unlimited sentinel, which the kernel publishes instead of omitting the file. A malformed or non-positive value is also rejected.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL