From dda6a22ea968af5414b4fc2e854dbd50bb3183ca Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 5 Jun 2024 10:42:43 -0700 Subject: [PATCH] apprt/gtk: cgroup hierarchy only affects surfaces --- src/apprt/gtk/Surface.zig | 2 +- src/apprt/gtk/cgroup.zig | 12 ++++++++++-- src/termio/Exec.zig | 3 +++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/apprt/gtk/Surface.zig b/src/apprt/gtk/Surface.zig index f3543ed0a..d696d8b38 100644 --- a/src/apprt/gtk/Surface.zig +++ b/src/apprt/gtk/Surface.zig @@ -358,7 +358,7 @@ pub fn init(self: *Surface, app: *App, opts: Options) !void { var buf: [256]u8 = undefined; const name = std.fmt.bufPrint( &buf, - "surface({X}).scope", + "surfaces/{X}.service", .{@intFromPtr(self)}, ) catch unreachable; diff --git a/src/apprt/gtk/cgroup.zig b/src/apprt/gtk/cgroup.zig index fdb04de6e..b936d83a1 100644 --- a/src/apprt/gtk/cgroup.zig +++ b/src/apprt/gtk/cgroup.zig @@ -45,20 +45,28 @@ pub fn init(app: *App) ![]const u8 { // Create the app cgroup and put ourselves in it. This is // required because controllers can't be configured while a // process is in a cgroup. - try internal_os.cgroup.create(transient, "app.scope", pid); + try internal_os.cgroup.create(transient, "app", pid); + + // Create a cgroup that will contain all our surfaces. We will + // enable the controllers and configure resource limits for surfaces + // only on this cgroup so that it doesn't affect our main app. + try internal_os.cgroup.create(transient, "surfaces", null); + const surfaces = try std.fmt.allocPrint(alloc, "{s}/surfaces", .{transient}); + defer alloc.free(surfaces); // Enable all of our cgroup controllers. If these fail then // we just log. We can't reasonably undo what we've done above // so we log the warning and still return the transient group. // I don't know a scenario where this fails yet. try enableControllers(alloc, transient); + try enableControllers(alloc, surfaces); // Configure the "high" memory limit. This limit is used instead // 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. if (app.config.@"linux-cgroup-memory-limit") |limit| { - try internal_os.cgroup.configureMemoryLimit(transient, .{ + try internal_os.cgroup.configureMemoryLimit(surfaces, .{ .high = limit, }); } diff --git a/src/termio/Exec.zig b/src/termio/Exec.zig index 1978659dd..d6342deb3 100644 --- a/src/termio/Exec.zig +++ b/src/termio/Exec.zig @@ -1321,6 +1321,9 @@ const Subprocess = struct { log.warn("error killing command during cleanup err={}", .{err}); }; log.info("started subcommand path={s} pid={?}", .{ self.args[0], cmd.pid }); + if (comptime builtin.os.tag == .linux) { + log.info("subcommand cgroup={s}", .{self.linux_cgroup orelse "-"}); + } self.command = cmd; return switch (builtin.os.tag) {