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
+32-29Lines changed: 32 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,11 +10,16 @@ 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
+
-`import _ "github.com/KimMachineGun/automemlimit"` now automatically falls back to system memory when cgroup is unavailable or limit is not set (ErrNoLimit)
19
+
- When `ErrNoLimit` is returned from the provider, GOMEMLIMIT is set to `math.MaxInt64` (unlimited) and returned as a successful result
20
+
-`Set` now returns the previous GOMEMLIMIT value instead of 0 when skipping (e.g., `GOMEMLIMIT` already set or `AUTOMEMLIMIT=off`) or when an error occurs
21
+
-`WithRefreshInterval(ctx, duration)` now requires a `context.Context` to control the refresh goroutine
22
+
- New `WithMin(bytes)` option to set a minimum memory limit
18
23
19
24
## Installation
20
25
@@ -27,41 +32,39 @@ go get github.com/KimMachineGun/automemlimit@latest
27
32
```go
28
33
package main
29
34
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.
35
+
// Sets GOMEMLIMIT to 90% of cgroup's memory limit.
36
+
// Falls back to system memory if cgroup is unavailable or limit is not set (ErrNoLimit).
33
37
import _ "github.com/KimMachineGun/automemlimit"
34
38
```
35
39
36
-
or
40
+
> **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