From fd22fa23b7418bffb95a2d83b6edef45853f77b3 Mon Sep 17 00:00:00 2001 From: Daniel Olsen Date: Mon, 16 Jan 2023 11:09:00 +0100 Subject: [PATCH] limit app slice to less than all ram as well --- machines/laptop.nix | 1 + profiles/base/default.nix | 4 ++++ profiles/xsession/default.nix | 10 +++++++++- scripts/dmenu_run_systemd | 5 +++-- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/machines/laptop.nix b/machines/laptop.nix index 1d1005e..8b6fa86 100644 --- a/machines/laptop.nix +++ b/machines/laptop.nix @@ -10,6 +10,7 @@ name = "DanixLaptop"; eth = "enp0s31f6"; wlan = "wlp5s0"; + cores = 4; }; profiles.base.enable = true; profiles.base.plus = true; diff --git a/profiles/base/default.nix b/profiles/base/default.nix index 9c32a3b..5461c38 100644 --- a/profiles/base/default.nix +++ b/profiles/base/default.nix @@ -23,6 +23,10 @@ in name = lib.mkOption { type = lib.types.str; }; + cores = lib.mkOption { + type = lib.types.ints.positive; + default = 1; + }; systemd = lib.mkOption { type = lib.types.bool; default = true; diff --git a/profiles/xsession/default.nix b/profiles/xsession/default.nix index f34a09a..a8b12cf 100644 --- a/profiles/xsession/default.nix +++ b/profiles/xsession/default.nix @@ -4,7 +4,7 @@ let cfg = config.profiles.xsession; non-nixos = config.profiles.non-nixos; 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 { imports = [ ./dunstrc.nix ./terminal.nix ./polybar.nix ]; @@ -17,6 +17,14 @@ in config = lib.mkIf cfg.enable { 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 = { layout = "no"; variant = "nodeadkeys"; diff --git a/scripts/dmenu_run_systemd b/scripts/dmenu_run_systemd index d63cc62..937fe23 100755 --- a/scripts/dmenu_run_systemd +++ b/scripts/dmenu_run_systemd @@ -115,8 +115,9 @@ declare -ga runargs=( --slice="app.slice" # run as part of `app.slice` --unit="${prefix}${name}-${rand}" - -p MemoryHigh=92% - -p MemoryMax=98% + -p MemoryHigh=85% + -p MemoryMax=92% + -p MemorySwapMax=5G # unit name --description="dmenu selection ${selection[*]@Q}" )