You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+35-29Lines changed: 35 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,11 +10,19 @@ See more details about `GOMEMLIMIT` [here](https://tip.golang.org/doc/gc-guide#M
10
10
11
11
## Notice
12
12
13
-
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`.
14
-
You can also use system memory limits via `memlimit.FromSystem` provider directly.
13
+
Version `v1.0.0` introduces breaking changes to improve usability by simplifying multiple functions into a single `memlimit.Set()` function with options, and to provide more consistent and predictable behavior.
15
14
16
-
This feature is under evaluation and might become a default or be removed based on user feedback.
17
-
If you have any feedback about this feature, please open an issue.
15
+
Key changes from v0.x:
16
+
-`SetGoMemLimitWithOpts`, `SetGoMemLimit`, `SetGoMemLimitWithProvider`, `SetGoMemLimitWithEnv` removed; use `Set` instead
17
+
-`FromCgroupV1`, `FromCgroupV2`, `FromCgroupHybrid` removed; use `FromCgroup` instead
18
+
-`AUTOMEMLIMIT_EXPERIMENT=system` removed; use `memlimit.ApplyFallback(memlimit.FromCgroup, memlimit.FromSystem)` for explicit fallback
19
+
-`AUTOMEMLIMIT_DEBUG` removed; use `memlimit.WithLogger(slog.Default())` instead
20
+
-`import _ "github.com/KimMachineGun/automemlimit"` now automatically falls back to system memory when cgroup is unavailable or limit is not set (ErrNoLimit). Note: `memlimit.Set()` does NOT fall back automatically; use `memlimit.ApplyFallback` explicitly.
21
+
- When `ErrNoLimit` is returned from the provider, GOMEMLIMIT is set to `math.MaxInt64` (unlimited) and returned as a successful result
22
+
-`Set` now returns the previous GOMEMLIMIT value instead of 0 when skipping or on error
23
+
-`WithRefreshInterval(ctx, duration)` now requires a `context.Context` to control the refresh goroutine
24
+
- When refresh is enabled, provider errors are logged and ignored; skipping does not start refresh
25
+
- New `WithMin(bytes)` option to set a minimum memory limit
18
26
19
27
## Installation
20
28
@@ -27,41 +35,39 @@ go get github.com/KimMachineGun/automemlimit@latest
27
35
```go
28
36
package main
29
37
30
-
// By default, it sets `GOMEMLIMIT` to 90% of cgroup's memory limit.
31
-
// This is equivalent to `memlimit.SetGoMemLimitWithOpts(memlimit.WithLogger(slog.Default()))`
32
-
// To disable logging, use `memlimit.SetGoMemLimitWithOpts` directly.
38
+
// Sets GOMEMLIMIT to 90% of cgroup's memory limit.
39
+
// Falls back to system memory if cgroup is unavailable or limit is not set (ErrNoLimit).
33
40
import _ "github.com/KimMachineGun/automemlimit"
34
41
```
35
42
36
-
or
43
+
> **Note:**`memlimit.Set()` defaults to `memlimit.FromCgroup` only. Use `memlimit.ApplyFallback(memlimit.FromCgroup, memlimit.FromSystem)` explicitly if you need system memory fallback.
0 commit comments