Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Config Option to Limit Number of Processes #2085

Merged
merged 2 commits into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/apprt/gtk/cgroup.zig
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,16 @@ pub fn init(app: *App) ![]const u8 {
// 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(surfaces, .{
.high = limit,
try internal_os.cgroup.configureLimit(surfaces, .{
.memory_high = limit,
});
}

// Configure the "max" pids limit. This is a hard limit and cannot be
// exceeded.
if (app.config.@"linux-cgroup-processes-limit") |limit| {
try internal_os.cgroup.configureLimit(surfaces, .{
.pids_max = limit,
});
}

Expand Down
7 changes: 7 additions & 0 deletions src/config/Config.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1276,6 +1276,13 @@ keybind: Keybinds = .{},
/// pressure.
@"linux-cgroup-memory-limit": ?u64 = null,

/// Number of processes limit for any individual terminal process (tab, split,
/// window, etc.). If this is unset then no limit will be set.
///
/// Note that this sets the "pids.max" configuration for the process number
/// controller, which is a hard limit.
@"linux-cgroup-processes-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
Expand Down
15 changes: 8 additions & 7 deletions src/os/cgroup.zig
Original file line number Diff line number Diff line change
Expand Up @@ -180,18 +180,19 @@ pub fn configureControllers(
try file.writer().writeAll(v);
}

pub const MemoryLimit = union(enum) {
/// memory.high
high: usize,
pub const Limit = union(enum) {
memory_high: usize,
pids_max: usize,
};

/// Configure the memory limit for the given cgroup. Use the various
/// fields in MemoryLimit to configure a specific type of limit.
pub fn configureMemoryLimit(cgroup: []const u8, limit: MemoryLimit) !void {
/// Configure a limit for the given cgroup. Use the various
/// fields in Limit to configure a specific type of limit.
pub fn configureLimit(cgroup: []const u8, limit: Limit) !void {
assert(cgroup[0] == '/');

const filename, const size = switch (limit) {
.high => |v| .{ "memory.high", v },
.memory_high => |v| .{ "memory.high", v },
.pids_max => |v| .{ "pids.max", v },
};

// Open our file
Expand Down
Loading