MCPcopy Index your code
hub / github.com/KimMachineGun/automemlimit

github.com/KimMachineGun/automemlimit @v0.7.5

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.7.5 ↗ · + Follow
89 symbols 216 edges 19 files 39 documented · 44% 26 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

automemlimit

Go Reference Go Report Card Test

Automatically set GOMEMLIMIT to match Linux cgroups(7) memory limit.

See more details about GOMEMLIMIT here.

Notice

Version v0.5.0 introduces a fallback to system memory limits as an experimental feature when cgroup limits are unavailable. Activate this by setting AUTOMEMLIMIT_EXPERIMENT=system. You can also use system memory limits via memlimit.FromSystem provider directly.

This feature is under evaluation and might become a default or be removed based on user feedback. If you have any feedback about this feature, please open an issue.

Installation

go get github.com/KimMachineGun/automemlimit@latest

Usage

package main

// By default, it sets `GOMEMLIMIT` to 90% of cgroup's memory limit.
// This is equivalent to `memlimit.SetGoMemLimitWithOpts(memlimit.WithLogger(slog.Default()))`
// To disable logging, use `memlimit.SetGoMemLimitWithOpts` directly.
import _ "github.com/KimMachineGun/automemlimit"

or

package main

import "github.com/KimMachineGun/automemlimit/memlimit"

func init() {
    memlimit.SetGoMemLimitWithOpts(
        memlimit.WithRatio(0.9),
        memlimit.WithProvider(memlimit.FromCgroup),
        memlimit.WithLogger(slog.Default()),
        memlimit.WithRefreshInterval(1*time.Minute),
    )
    memlimit.SetGoMemLimitWithOpts(
        memlimit.WithRatio(0.9),
        memlimit.WithProvider(
            memlimit.ApplyFallback(
                memlimit.FromCgroup,
                memlimit.FromSystem,
            ),
        ),
        memlimit.WithRefreshInterval(1*time.Minute),
    )
    memlimit.SetGoMemLimit(0.9)
    memlimit.SetGoMemLimitWithProvider(memlimit.Limit(1024*1024), 0.9)
    memlimit.SetGoMemLimitWithProvider(memlimit.FromCgroup, 0.9)
    memlimit.SetGoMemLimitWithProvider(memlimit.FromCgroupV1, 0.9)
    memlimit.SetGoMemLimitWithProvider(memlimit.FromCgroupHybrid, 0.9)
    memlimit.SetGoMemLimitWithProvider(memlimit.FromCgroupV2, 0.9)
}

Extension points exported contracts — how you extend this code

Provider (FuncType)
Provider is a function that returns the memory limit.
memlimit/provider.go
Option (FuncType)
Option is a function that configures the behavior of SetGoMemLimitWithOptions.
memlimit/memlimit.go

Core symbols most depended-on inside this repo

SetGoMemLimitWithOpts
called by 10
memlimit/memlimit.go
WithProvider
called by 9
memlimit/memlimit.go
Limit
called by 7
memlimit/provider.go
SetGoMemLimitWithProvider
called by 5
memlimit/memlimit.go
WithRatio
called by 4
memlimit/memlimit.go
ApplyFallback
called by 3
memlimit/provider.go
FromCgroup
called by 3
memlimit/cgroups_linux.go
WithLogger
called by 3
memlimit/memlimit.go

Shape

Function 75
Struct 8
Method 4
FuncType 2

Languages

Go100%

Modules by API surface

memlimit/memlimit.go17 symbols
memlimit/cgroups.go16 symbols
memlimit/memlimit_test.go6 symbols
memlimit/memlimit_unsupported_test.go5 symbols
memlimit/memlimit_linux_test.go5 symbols
memlimit/logger.go5 symbols
memlimit/provider.go4 symbols
memlimit/cgroups_unsupported_test.go4 symbols
memlimit/cgroups_unsupported.go4 symbols
memlimit/cgroups_linux_test.go4 symbols
memlimit/cgroups_linux.go4 symbols
memlimit/cgroups_test.go3 symbols

For agents

$ claude mcp add automemlimit \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page