From 99d567274b2ea725b5d1de2d2aaf77dca0522246 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 5 Jun 2024 10:27:53 -0700 Subject: [PATCH] config: add cgroup memory limit config --- src/apprt/gtk/cgroup.zig | 9 +++++---- src/config/Config.zig | 9 +++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/apprt/gtk/cgroup.zig b/src/apprt/gtk/cgroup.zig index 86cd48b3d..fdb04de6e 100644 --- a/src/apprt/gtk/cgroup.zig +++ b/src/apprt/gtk/cgroup.zig @@ -57,10 +57,11 @@ pub fn init(app: *App) ![]const u8 { // of "max" because it's a soft limit that can be exceeded and // can be monitored by things like systemd-oomd to kill if needed, // versus an instant hard kill. - // try internal_os.cgroup.configureMemoryLimit(transient, .{ - // // 1GB - // .high = 1 * 1024 * 1024 * 1024, - // }); + if (app.config.@"linux-cgroup-memory-limit") |limit| { + try internal_os.cgroup.configureMemoryLimit(transient, .{ + .high = limit, + }); + } return transient; } diff --git a/src/config/Config.zig b/src/config/Config.zig index b6e2d7342..2cc7d52ef 100644 --- a/src/config/Config.zig +++ b/src/config/Config.zig @@ -1012,6 +1012,15 @@ keybind: Keybinds = .{}, /// @"linux-cgroup": LinuxCgroup = .@"single-instance", +/// Memory limit for any individual terminal process (tab, split, window, +/// etc.) in bytes. If this is unset then no memory limit will be set. +/// +/// Note that this sets the "memory.high" configuration for the memory +/// controller, which is a soft limit. You should configure something like +/// systemd-oom to handle killing processes that have too much memory +/// pressure. +@"linux-cgroup-memory-limit": ?u64 = null, + /// If this is false, then any cgroup initialization (for linux-cgroup) /// will be allowed to fail and the failure is ignored. This is useful if /// you view cgroup isolation as a "nice to have" and not a critical resource