mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 00:36:07 +03:00
config: control cgroup isolation
This commit is contained in:
@ -44,6 +44,9 @@ config: Config,
|
|||||||
app: *c.GtkApplication,
|
app: *c.GtkApplication,
|
||||||
ctx: *c.GMainContext,
|
ctx: *c.GMainContext,
|
||||||
|
|
||||||
|
/// True if the app was launched with single instance mode.
|
||||||
|
single_instance: bool,
|
||||||
|
|
||||||
/// The "none" cursor. We use one that is shared across the entire app.
|
/// The "none" cursor. We use one that is shared across the entire app.
|
||||||
cursor_none: ?*c.GdkCursor,
|
cursor_none: ?*c.GdkCursor,
|
||||||
|
|
||||||
@ -269,6 +272,7 @@ pub fn init(core_app: *CoreApp, opts: Options) !App {
|
|||||||
.ctx = ctx,
|
.ctx = ctx,
|
||||||
.cursor_none = cursor_none,
|
.cursor_none = cursor_none,
|
||||||
.x11_xkb = x11_xkb,
|
.x11_xkb = x11_xkb,
|
||||||
|
.single_instance = single_instance,
|
||||||
// If we are NOT the primary instance, then we never want to run.
|
// If we are NOT the primary instance, then we never want to run.
|
||||||
// This means that another instance of the GTK app is running and
|
// This means that another instance of the GTK app is running and
|
||||||
// our "activate" call above will open a window.
|
// our "activate" call above will open a window.
|
||||||
@ -388,9 +392,12 @@ pub fn run(self: *App) !void {
|
|||||||
// If we are running, then we proceed to setup our app.
|
// If we are running, then we proceed to setup our app.
|
||||||
|
|
||||||
// Setup our cgroup configurations for our surfaces.
|
// Setup our cgroup configurations for our surfaces.
|
||||||
if (cgroup.init(self)) |cgroup_path| {
|
if (switch (self.config.@"linux-cgroup") {
|
||||||
self.transient_cgroup_base = cgroup_path;
|
.never => false,
|
||||||
} else |err| {
|
.always => true,
|
||||||
|
.@"single-instance" => self.single_instance,
|
||||||
|
}) cgroup: {
|
||||||
|
const path = cgroup.init(self) catch |err| {
|
||||||
// If we can't initialize cgroups then that's okay. We
|
// If we can't initialize cgroups then that's okay. We
|
||||||
// want to continue to run so we just won't isolate surfaces.
|
// want to continue to run so we just won't isolate surfaces.
|
||||||
// NOTE(mitchellh): do we want a config to force it?
|
// NOTE(mitchellh): do we want a config to force it?
|
||||||
@ -398,7 +405,12 @@ pub fn run(self: *App) !void {
|
|||||||
"failed to initialize cgroups, terminals will not be isolated err={}",
|
"failed to initialize cgroups, terminals will not be isolated err={}",
|
||||||
.{err},
|
.{err},
|
||||||
);
|
);
|
||||||
}
|
break :cgroup;
|
||||||
|
};
|
||||||
|
|
||||||
|
log.info("cgroup isolation enabled base={s}", .{path});
|
||||||
|
self.transient_cgroup_base = path;
|
||||||
|
} else log.debug("cgroup isoation disabled config={}", .{self.config.@"linux-cgroup"});
|
||||||
|
|
||||||
// Setup our menu items
|
// Setup our menu items
|
||||||
self.initActions();
|
self.initActions();
|
||||||
|
@ -12,7 +12,7 @@ pub const fish_completions = comptimeGenerateFishCompletions();
|
|||||||
|
|
||||||
fn comptimeGenerateFishCompletions() []const u8 {
|
fn comptimeGenerateFishCompletions() []const u8 {
|
||||||
comptime {
|
comptime {
|
||||||
@setEvalBranchQuota(13000);
|
@setEvalBranchQuota(15000);
|
||||||
var counter = std.io.countingWriter(std.io.null_writer);
|
var counter = std.io.countingWriter(std.io.null_writer);
|
||||||
try writeFishCompletions(&counter.writer());
|
try writeFishCompletions(&counter.writer());
|
||||||
|
|
||||||
|
@ -988,6 +988,30 @@ keybind: Keybinds = .{},
|
|||||||
/// This does not work with GLFW builds.
|
/// This does not work with GLFW builds.
|
||||||
@"macos-option-as-alt": OptionAsAlt = .false,
|
@"macos-option-as-alt": OptionAsAlt = .false,
|
||||||
|
|
||||||
|
/// Put every surface (tab, split, window) into a dedicated Linux cgroup.
|
||||||
|
///
|
||||||
|
/// This makes it so that resource management can be done on a per-surface
|
||||||
|
/// granularity. For example, if a shell program is using too much memory,
|
||||||
|
/// only that shell will be killed by the oom monitor instead of the entire
|
||||||
|
/// Ghostty process. Similarly, if a shell program is using too much CPU,
|
||||||
|
/// only that surface will be CPU-throttled.
|
||||||
|
///
|
||||||
|
/// This will cause startup times to be slower (a hundred milliseconds or so),
|
||||||
|
/// so the default value is "single-instance." In single-instance mode, only
|
||||||
|
/// one instance of Ghostty is running (see gtk-single-instance) so the startup
|
||||||
|
/// time is a one-time cost. Additionally, single instance Ghostty is much
|
||||||
|
/// more likely to have many windows, tabs, etc. so cgroup isolation is a
|
||||||
|
/// big benefit.
|
||||||
|
///
|
||||||
|
/// Valid values are:
|
||||||
|
///
|
||||||
|
/// * `never` - Never use cgroups.
|
||||||
|
/// * `always` - Always use cgroups.
|
||||||
|
/// * `single-instance` - Enable cgroups only for Ghostty instances launched
|
||||||
|
/// as single-instance applications (see gtk-single-instance).
|
||||||
|
///
|
||||||
|
@"linux-cgroup": LinuxCgroup = .@"single-instance",
|
||||||
|
|
||||||
/// If true, the Ghostty GTK application will run in single-instance mode:
|
/// If true, the Ghostty GTK application will run in single-instance mode:
|
||||||
/// each new `ghostty` process launched will result in a new window if there
|
/// each new `ghostty` process launched will result in a new window if there
|
||||||
/// is already a running process.
|
/// is already a running process.
|
||||||
@ -3495,3 +3519,10 @@ pub const GraphemeWidthMethod = enum {
|
|||||||
legacy,
|
legacy,
|
||||||
unicode,
|
unicode,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// See linux-cgroup
|
||||||
|
pub const LinuxCgroup = enum {
|
||||||
|
never,
|
||||||
|
always,
|
||||||
|
@"single-instance",
|
||||||
|
};
|
||||||
|
Reference in New Issue
Block a user