Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

fix(rexctl): only warn about overcommit when memory is low (#3773)

Hampus454d657ae0a0
diff --git a/fluxer_docs/src/content/docs/operator/running.mdx b/fluxer_docs/src/content/docs/operator/running.mdx
index 0402df7e1..5c170d494 100644
--- a/fluxer_docs/src/content/docs/operator/running.mdx
+++ b/fluxer_docs/src/content/docs/operator/running.mdx
@@ -199,6 +199,8 @@ rexctl doctor
This checks your instance and the machine, and tells you how to fix each problem it finds. `rexctl doctor --fix` fixes the problems rexctl can fix safely.
+If `rexctl doctor` says memory overcommit is off, the machine has little free memory compared with Fluxer's cache. The cache saves its data in the background by briefly copying itself, and with `vm.overcommit_memory` set to 0 Linux can refuse that copy when memory runs low. `rexctl doctor --fix` sets it to 1, which is what Valkey recommends. With plenty of free memory and swap, rexctl doesn't warn about it.
+
`rexctl status` shows whether each Fluxer service is running, and `rexctl logs` shows their logs.
## Manage it without rexctl
diff --git a/fluxer_rexctl/internal/checks/overcommit.go b/fluxer_rexctl/internal/checks/overcommit.go
index e4851dccd..9402339ef 100644
--- a/fluxer_rexctl/internal/checks/overcommit.go
+++ b/fluxer_rexctl/internal/checks/overcommit.go
@@ -6,11 +6,18 @@ import (
"context"
"github.com/fluxerapp/fluxer/fluxer_rexctl/internal/host"
+ "github.com/fluxerapp/fluxer/fluxer_rexctl/internal/voice"
)
var (
overcommit = host.Overcommit
enableOvercommit = host.EnableOvercommit
+ freeMemory = host.FreeMemory
+)
+
+const (
+ defaultValkeyMaxMemory = 192 << 20
+ valkeyHeadroom = 4
)
const overcommitOff = "Memory overcommit is off, so Fluxer's cache can fail to save data when memory runs low."
@@ -19,8 +26,12 @@ func init() {
Register(Check{ID: "memory-overcommit", Phases: Preinstall | Installed, Run: runOvercommit, Fix: fixOvercommit, SafeFix: true})
}
-func runOvercommit(_ context.Context, _ *Env) Result {
- switch overcommit() {
+func runOvercommit(_ context.Context, e *Env) Result {
+ state := overcommit()
+ if (state == host.OvercommitOff || state == host.OvercommitLocked) && enoughForValkey(e) {
+ return pass("Memory overcommit is off, and this machine has enough free memory for Fluxer's cache to save its data.")
+ }
+ switch state {
case host.OvercommitUnknown:
return skip("")
case host.OvercommitLocked:
@@ -36,3 +47,16 @@ func runOvercommit(_ context.Context, _ *Env) Result {
func fixOvercommit(ctx context.Context, _ *Env) error {
return enableOvercommit(ctx)
}
+
+func enoughForValkey(e *Env) bool {
+ limit := uint64(defaultValkeyMaxMemory)
+ if v := e.value("FLUXER_VALKEY_MAXMEMORY"); v != "" {
+ n, ok := voice.ParseBytes(v)
+ if !ok {
+ return false
+ }
+ limit = n
+ }
+ free := freeMemory()
+ return free > 0 && free >= limit*valkeyHeadroom
+}
diff --git a/fluxer_rexctl/internal/host/overcommit.go b/fluxer_rexctl/internal/host/overcommit.go
index d7c40e351..9a55958f7 100644
--- a/fluxer_rexctl/internal/host/overcommit.go
+++ b/fluxer_rexctl/internal/host/overcommit.go
@@ -60,6 +60,27 @@ func overcommitAt(path string, root bool) OvercommitState {
return OvercommitOff
}
+func FreeMemory() uint64 {
+ if runtime.GOOS != "linux" {
+ return 0
+ }
+ data, err := os.ReadFile("/proc/meminfo")
+ if err != nil {
+ return 0
+ }
+ var free uint64
+ for _, line := range strings.Split(string(data), "\n") {
+ fields := strings.Fields(line)
+ if len(fields) < 2 || fields[0] != "MemAvailable:" && fields[0] != "SwapFree:" {
+ continue
+ }
+ if kb, err := strconv.ParseUint(fields[1], 10, 64); err == nil {
+ free += kb << 10
+ }
+ }
+ return free
+}
+
func EnableOvercommit(ctx context.Context) error {
if _, err := output(ctx, false, "sh", "-c", "printf '"+OvercommitSetting+"\\n' > "+OvercommitFile); err != nil {
return err