mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 10:37:23 +01:00
blockvolume: an underivable cgroup memory limit starts on the default
With neither --memory-limit-mib nor GOMEMLIMIT, a cgroup v2 limit that cannot be derived (a membership outside the cgroup2 mount of the holder's mount namespace, an unreadable or malformed memory.max) is the no-limit case: the holder keeps the 256 MiB default and starts, instead of exiting 2. applyMemoryLimit, run once logging is configured, logs one level=WARN line naming the derivation's error and the two ways to choose a limit, and status reports the reason in Memory.SoftLimitFallback (empty otherwise). Only an explicit but invalid limit still refuses. Docs: the flag's help, the operator guide's memory section, the status schema and the v1.1 notes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
aa512ab6d4
commit
7a70a7a1ca
8 files changed
+54
-20
No files matched your search
@@ -165,7 +165,8 @@ type flags struct {
|
||||
version bool
|
||||
|
||||
// memoryLimitFallback says why the default soft memory limit is in
|
||||
// force instead of a cgroup-derived one (seam).
|
||||
// force instead of a cgroup-derived one: the derivation's error. Empty
|
||||
// when a limit was derived, given, or not needed.
|
||||
memoryLimitFallback string
|
||||
}
|
||||
|
||||
@@ -193,7 +194,7 @@ func parseFlagsWithCgroup(args []string, readFile func(string) ([]byte, error))
|
||||
var f flags
|
||||
fs := flag.NewFlagSet("blockvolume", flag.ContinueOnError)
|
||||
fs.StringVar(&f.logLevel, "log-level", "info", "log verbosity: info or debug; timestamps are UTC with microseconds")
|
||||
fs.Int64Var(&f.memoryLimitMiB, "memory-limit-mib", 4*storage.DefaultCutPayloadMemoryBudget/(1<<20), "process Go soft memory limit in MiB; unset: 90% of the effective cgroup v2 memory.max, or 256 MiB without a limit; 0 preserves GOMEMLIMIT; explicit GOMEMLIMIT is preserved unless this flag is set")
|
||||
fs.Int64Var(&f.memoryLimitMiB, "memory-limit-mib", 4*storage.DefaultCutPayloadMemoryBudget/(1<<20), "process Go soft memory limit in MiB; unset: 90% of the effective cgroup v2 memory.max, or 256 MiB without a limit or when it cannot be derived (one WARN says why); 0 preserves GOMEMLIMIT; explicit GOMEMLIMIT is preserved unless this flag is set")
|
||||
fs.StringVar(&f.masterAddr, "master", "", "master gRPC address (required)")
|
||||
fs.StringVar(&f.serverID, "server-id", "", "this server identity (required)")
|
||||
fs.StringVar(&f.masterTLS.Cert, "master-tls-cert", "", "this node's certificate (PEM) for mutual TLS to blockmaster; its CN must equal --server-id")
|
||||
@@ -297,11 +298,13 @@ func parseFlagsWithCgroup(args []string, readFile func(string) ([]byte, error))
|
||||
if !memoryFlagSet && os.Getenv("GOMEMLIMIT") != "" {
|
||||
f.memoryLimitMiB = 0
|
||||
} else if !memoryFlagSet && !f.version {
|
||||
// An underivable cgroup limit is the no-limit case: the default stays
|
||||
// in force and applyMemoryLimit warns why. Only an explicit limit
|
||||
// (the flag, or GOMEMLIMIT read by the runtime) may refuse.
|
||||
limit, err := cgroupMemoryLimitMiB(readFile)
|
||||
if err != nil {
|
||||
return flags{}, fmt.Errorf("derive memory limit: %w", err)
|
||||
}
|
||||
if limit != 0 {
|
||||
f.memoryLimitFallback = err.Error()
|
||||
} else if limit != 0 {
|
||||
f.memoryLimitMiB = limit
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +75,8 @@ func cgroupMemoryLimitMiB(readFile func(string) ([]byte, error)) (int64, error)
|
||||
|
||||
// mountinfo names both the filesystem subtree root and its visible mountpoint.
|
||||
// A membership path must resolve inside that view; an unresolved v2 hierarchy
|
||||
// is a configuration error, not evidence of unlimited memory.
|
||||
// is an error here, not evidence of unlimited memory: the caller keeps the
|
||||
// default limit and warns why.
|
||||
func cgroupMemoryDirectory(group string, readFile func(string) ([]byte, error)) (string, string, error) {
|
||||
data, err := readFile("/proc/self/mountinfo")
|
||||
if err != nil {
|
||||
|
||||
@@ -1,11 +1,21 @@
|
||||
package main
|
||||
|
||||
import "runtime/debug"
|
||||
import (
|
||||
"runtime/debug"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/host/volume"
|
||||
)
|
||||
|
||||
// applyMemoryLimit sets the process's Go soft memory limit from the parsed
|
||||
// flags (seam: no fallback report yet).
|
||||
// flags. When the default is in force because the cgroup v2 limit could not
|
||||
// be derived, it logs one WARN naming why and how to choose a limit, and
|
||||
// status reports the reason (Memory.SoftLimitFallback).
|
||||
func applyMemoryLimit(f flags, logf func(string, ...any)) {
|
||||
if f.memoryLimitMiB > 0 {
|
||||
debug.SetMemoryLimit(f.memoryLimitMiB << 20)
|
||||
}
|
||||
volume.SetSoftLimitFallback(f.memoryLimitFallback)
|
||||
if f.memoryLimitFallback != "" {
|
||||
logf("blockvolume: level=WARN memory limit: the cgroup v2 limit could not be derived (%s); running with the %d MiB default soft limit; set --memory-limit-mib or GOMEMLIMIT to choose a limit", f.memoryLimitFallback, f.memoryLimitMiB)
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,21 @@
|
||||
package volume
|
||||
|
||||
// SetSoftLimitFallback records why the process runs on the default soft
|
||||
// memory limit (seam: not reported yet).
|
||||
func SetSoftLimitFallback(reason string) {}
|
||||
import "sync/atomic"
|
||||
|
||||
// SoftLimitFallback is the reason SetSoftLimitFallback recorded (seam).
|
||||
func SoftLimitFallback() string { return "" }
|
||||
// softLimitFallback is why the process runs on the default soft memory limit
|
||||
// instead of a cgroup-derived one; the limit itself is process-wide too.
|
||||
var softLimitFallback atomic.Pointer[string]
|
||||
|
||||
// SetSoftLimitFallback records why the process runs on the default soft
|
||||
// memory limit; empty clears it.
|
||||
func SetSoftLimitFallback(reason string) {
|
||||
softLimitFallback.Store(&reason)
|
||||
}
|
||||
|
||||
// SoftLimitFallback is the reason SetSoftLimitFallback recorded, or empty.
|
||||
func SoftLimitFallback() string {
|
||||
if p := softLimitFallback.Load(); p != nil {
|
||||
return *p
|
||||
}
|
||||
return ""
|
||||
}
|
||||
@@ -16,9 +16,7 @@ type ProcessMemoryStatus struct {
|
||||
HeapSysBytes uint64 // Go heap bytes obtained from the OS (HeapSys)
|
||||
HeapReleasedBytes uint64 // Go heap bytes returned to the OS (HeapReleased)
|
||||
SoftLimitBytes int64 // the Go soft memory limit in force (flag, GOMEMLIMIT or cgroup-derived default)
|
||||
// SoftLimitFallback says why SoftLimitBytes is the default instead of a
|
||||
// cgroup-derived limit (seam).
|
||||
SoftLimitFallback string `json:",omitempty"`
|
||||
SoftLimitFallback string `json:",omitempty"` // why SoftLimitBytes is the 256 MiB default instead of a cgroup-derived limit (the derivation's error)
|
||||
RSSBytes uint64 // resident set size from /proc/self/status (VmRSS); 0 off Linux
|
||||
AnonymousRSSBytes uint64 // anonymous resident memory (RssAnon); 0 off Linux
|
||||
}
|
||||
@@ -26,7 +24,7 @@ type ProcessMemoryStatus struct {
|
||||
func processMemoryStatus() ProcessMemoryStatus {
|
||||
var m runtime.MemStats
|
||||
runtime.ReadMemStats(&m)
|
||||
out := ProcessMemoryStatus{HeapAllocBytes: m.HeapAlloc, HeapInuseBytes: m.HeapInuse, HeapSysBytes: m.HeapSys, HeapReleasedBytes: m.HeapReleased, SoftLimitBytes: debug.SetMemoryLimit(-1)}
|
||||
out := ProcessMemoryStatus{HeapAllocBytes: m.HeapAlloc, HeapInuseBytes: m.HeapInuse, HeapSysBytes: m.HeapSys, HeapReleasedBytes: m.HeapReleased, SoftLimitBytes: debug.SetMemoryLimit(-1), SoftLimitFallback: SoftLimitFallback()}
|
||||
b, err := os.ReadFile("/proc/self/status")
|
||||
if err != nil {
|
||||
return out
|
||||
|
||||
@@ -271,9 +271,13 @@ are its only SeaweedFS flags. Run SeaweedFS on a trusted network; mTLS covers th
|
||||
Automatic sizing requires the cgroup v2 memory controller. On cgroup v1,
|
||||
or a hybrid hierarchy without v2 `memory.max`, set `--memory-limit-mib`
|
||||
explicitly for a large volume; otherwise it receives the 256 MiB fallback.
|
||||
An unreadable or malformed cgroup limit refuses startup with a diagnostic;
|
||||
an explicit memory flag or `GOMEMLIMIT` bypasses this detection.
|
||||
Inspect `Memory.SoftLimitBytes` on the holder's status for the value in force.
|
||||
A cgroup limit that cannot be derived (unreadable or malformed, or a
|
||||
membership outside the cgroup2 mount visible in the holder's mount namespace)
|
||||
does not stop the holder: it starts on the 256 MiB default and logs one
|
||||
`level=WARN` line naming why. An explicit memory flag or `GOMEMLIMIT` bypasses
|
||||
this detection; only an explicit but invalid one refuses startup.
|
||||
Inspect `Memory.SoftLimitBytes` on the holder's status for the value in force,
|
||||
and `Memory.SoftLimitFallback` for why the default is in force.
|
||||
- **Measured throughput on one host** (three runs; 16 cores, 23.2 GiB RAM, one consumer NVMe drive, fsync on every
|
||||
volume):
|
||||
|
||||
|
||||
@@ -20,6 +20,10 @@ These notes collect v1.1's changes as they land; v1.1 is not released.
|
||||
- A normal cut that has held its host slot for `--host-limit-yield-after` (default 5 min) gives the slot to a waiting
|
||||
cut at its next staging batch, keeping what it staged; its next attempt queues behind the waiters. A lone cut never
|
||||
yields, and status counts yields apart from failures (`CutYields`).
|
||||
- A `blockvolume` whose cgroup v2 memory limit cannot be derived (for example, its cgroup membership lies outside
|
||||
the cgroup2 mount visible in its mount namespace) now starts on the 256 MiB default soft limit and logs one
|
||||
`level=WARN` line naming why, instead of exiting 2; status reports the reason in `Memory.SoftLimitFallback`. An
|
||||
explicit but invalid `--memory-limit-mib` or `GOMEMLIMIT` still refuses.
|
||||
|
||||
## Upgrade
|
||||
- With `--host-limit-dir` set, the limiter's `configuration.json` in that directory records the flags it was
|
||||
|
||||
@@ -26,6 +26,7 @@ The volume's authority and health projection. Go type `volume.StatusProjection`.
|
||||
| `Memory.HeapSysBytes` | uint64 | Go heap bytes obtained from the OS (HeapSys) |
|
||||
| `Memory.HeapReleasedBytes` | uint64 | Go heap bytes returned to the OS (HeapReleased) |
|
||||
| `Memory.SoftLimitBytes` | int64 | the Go soft memory limit in force (flag, GOMEMLIMIT or cgroup-derived default) |
|
||||
| `Memory.SoftLimitFallback` | string | why SoftLimitBytes is the 256 MiB default instead of a cgroup-derived limit (the derivation's error) (omitted when empty) |
|
||||
| `Memory.RSSBytes` | uint64 | resident set size from /proc/self/status (VmRSS); 0 off Linux |
|
||||
| `Memory.AnonymousRSSBytes` | uint64 | anonymous resident memory (RssAnon); 0 off Linux |
|
||||
| `FrontendPrimaryReady` | bool | FrontendPrimaryReady: this replica is the healthy, non-superseded primary, its local durable backend admits I/O, and it may serve guest I/O (INV-FE-PRIMARY-READY-OPERATIONAL-001). |
|
||||
|
||||
Reference in new issue
Block a user