mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
Merge pull request #2085 from Syphdias/option-to-limit-procs
Add Config Option to Limit Number of Processes
This commit is contained in:
@ -66,8 +66,16 @@ pub fn init(app: *App) ![]const u8 {
|
|||||||
// can be monitored by things like systemd-oomd to kill if needed,
|
// can be monitored by things like systemd-oomd to kill if needed,
|
||||||
// versus an instant hard kill.
|
// versus an instant hard kill.
|
||||||
if (app.config.@"linux-cgroup-memory-limit") |limit| {
|
if (app.config.@"linux-cgroup-memory-limit") |limit| {
|
||||||
try internal_os.cgroup.configureMemoryLimit(surfaces, .{
|
try internal_os.cgroup.configureLimit(surfaces, .{
|
||||||
.high = limit,
|
.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,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1276,6 +1276,13 @@ keybind: Keybinds = .{},
|
|||||||
/// pressure.
|
/// pressure.
|
||||||
@"linux-cgroup-memory-limit": ?u64 = null,
|
@"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)
|
/// 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
|
/// 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
|
/// you view cgroup isolation as a "nice to have" and not a critical resource
|
||||||
|
@ -180,18 +180,19 @@ pub fn configureControllers(
|
|||||||
try file.writer().writeAll(v);
|
try file.writer().writeAll(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const MemoryLimit = union(enum) {
|
pub const Limit = union(enum) {
|
||||||
/// memory.high
|
memory_high: usize,
|
||||||
high: usize,
|
pids_max: usize,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Configure the memory limit for the given cgroup. Use the various
|
/// Configure a limit for the given cgroup. Use the various
|
||||||
/// fields in MemoryLimit to configure a specific type of limit.
|
/// fields in Limit to configure a specific type of limit.
|
||||||
pub fn configureMemoryLimit(cgroup: []const u8, limit: MemoryLimit) !void {
|
pub fn configureLimit(cgroup: []const u8, limit: Limit) !void {
|
||||||
assert(cgroup[0] == '/');
|
assert(cgroup[0] == '/');
|
||||||
|
|
||||||
const filename, const size = switch (limit) {
|
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
|
// Open our file
|
||||||
|
Reference in New Issue
Block a user