limit app slice to less than all ram as well

This commit is contained in:
Daniel Olsen 2023-01-16 11:09:00 +01:00
parent b94a54ec98
commit fd22fa23b7
4 changed files with 17 additions and 3 deletions

View File

@ -10,6 +10,7 @@
name = "DanixLaptop"; name = "DanixLaptop";
eth = "enp0s31f6"; eth = "enp0s31f6";
wlan = "wlp5s0"; wlan = "wlp5s0";
cores = 4;
}; };
profiles.base.enable = true; profiles.base.enable = true;
profiles.base.plus = true; profiles.base.plus = true;

View File

@ -23,6 +23,10 @@ in
name = lib.mkOption { name = lib.mkOption {
type = lib.types.str; type = lib.types.str;
}; };
cores = lib.mkOption {
type = lib.types.ints.positive;
default = 1;
};
systemd = lib.mkOption { systemd = lib.mkOption {
type = lib.types.bool; type = lib.types.bool;
default = true; default = true;

View File

@ -4,7 +4,7 @@ let
cfg = config.profiles.xsession; cfg = config.profiles.xsession;
non-nixos = config.profiles.non-nixos; non-nixos = config.profiles.non-nixos;
mkGL = program: "${lib.strings.optionalString non-nixos.enable "${pkgs.nixgl.auto.nixGLDefault}/bin/nixGL "}${program}"; mkGL = program: "${lib.strings.optionalString non-nixos.enable "${pkgs.nixgl.auto.nixGLDefault}/bin/nixGL "}${program}";
execScope = program: "exec bash -c \"systemd-run --user --scope --unit='app-i3-exec-$RANDOM' -p CollectMode=inactive-or-failed -p MemoryHigh=92% -p MemoryMax=98% \"${program}\"\""; execScope = program: "exec bash -c \"systemd-run --user --scope --unit='app-i3-exec-$RANDOM' -p CollectMode=inactive-or-failed -p MemoryHigh=85% -p MemoryMax=92% -p MemorySwapMax=5G -p MemoryAccounting=true \"${program}\"\"";
in in
{ {
imports = [ ./dunstrc.nix ./terminal.nix ./polybar.nix ]; imports = [ ./dunstrc.nix ./terminal.nix ./polybar.nix ];
@ -17,6 +17,14 @@ in
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
profiles.gui.enable = true; profiles.gui.enable = true;
systemd.user.slices.app.Slice = {
MemoryHigh="90%";
MemoryMax="94%";
MemorySwapMax="8G";
CPUQuota="${toString ((config.machine.cores - 1)*100)}%";
MemoryAccounting = true;
};
home.keyboard = { home.keyboard = {
layout = "no"; layout = "no";
variant = "nodeadkeys"; variant = "nodeadkeys";

View File

@ -115,8 +115,9 @@ declare -ga runargs=(
--slice="app.slice" # run as part of `app.slice` --slice="app.slice" # run as part of `app.slice`
--unit="${prefix}${name}-${rand}" --unit="${prefix}${name}-${rand}"
-p MemoryHigh=92% -p MemoryHigh=85%
-p MemoryMax=98% -p MemoryMax=92%
-p MemorySwapMax=5G
# unit name # unit name
--description="dmenu selection ${selection[*]@Q}" --description="dmenu selection ${selection[*]@Q}"
) )