Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure Go GC based on pillar memory limit or global config #4273

Merged
merged 2 commits into from
Sep 23, 2024

Commits on Sep 23, 2024

  1. pillar: configure GOGC based on pillar memory limit or global config

    Patch introduces two settings for Golang runtime which
    impacts garbage collector behavior:
    
    1. `gogc.memory.limit.bytes` provides the runtime with a soft memory
        limit.  The runtime undertakes several processes to try to respect
        this memory limit, including adjustments to the frequency of
        garbage collections and returning memory to the underlying system
        more aggressively. The Go API call is described here:
        https://pkg.go.dev/runtime/debug#SetMemoryLimit
    
        By default, EVE setting is disabled (set to 0), meaning the Golang
        runtime memory limit will be set according to the following
        equation based on the `memory.limit_in_bytes` hard memory limit
        provided by the pillar `cgroups`:
    
        `limit = memory.limit_in_bytes * 0.6`
    
        The constant 0.6 was chosen empirically and is explained by simple
        logic: `memory.limit_in_bytes` is a hard limit for the whole
        pillar cgroup, meaning when reached, likely one of the processes
        will be killed by OOM. In turn Golang runtime memory limit is a
        soft limit, so the difference must be significant to ensure that
        after the soft limit is reached, there will be enough memory for
        the Go garbage collector to do its job and, fortunately, not to
        hit the hard limit.
    
    2. `gogc.percent` sets the garbage collection target percentage: a
        collection is triggered when the ratio of freshly allocated data
        to live data remaining after the previous collection reaches this
        percentage. The Go API call is described here:
        https://pkg.go.dev/runtime/debug#SetGCPercent
    
    The patch is motivated by a frequently observed bloated `zedbox`
    application (up to 500MB) that causes an OOM kill call to the /eve or
    /pillar cgroups. It is assumed that the bloated `zedbox` application
    is not caused by memory leaks, but by a delayed GC sweep cycle and a
    unconditionally growing runtime heap size. An explicit memory limit
    set for the Golang runtime (~400MB in the current version of EVE)
    should make the GC more aggressive when the soft memory limit is hit,
    which should result in a significant reduction in allocated but unused
    memory.
    
    Signed-off-by: Roman Penyaev <[email protected]>
    rouming committed Sep 23, 2024
    Configuration menu
    Copy the full SHA
    40feb16 View commit details
    Browse the repository at this point in the history
  2. docs: describe GOGC memory limit and percent settings

    Documentation for recent:
    
       gogc.memory.limit.bytes
       gogc.percent
    
    Golang runtime settings.
    
    Signed-off-by: Roman Penyaev <[email protected]>
    rouming committed Sep 23, 2024
    Configuration menu
    Copy the full SHA
    cf3f683 View commit details
    Browse the repository at this point in the history