From 97335ca0def226733b98a7346ce961816baadfa6 Mon Sep 17 00:00:00 2001 From: Antoine Viallon Date: Thu, 11 May 2023 20:33:50 +0200 Subject: [PATCH] [FileSystems/Btrfs] improve performance + fix autoScrub conf --- filesystems/btrfs.nix | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/filesystems/btrfs.nix b/filesystems/btrfs.nix index 8455d5b..8deabea 100644 --- a/filesystems/btrfs.nix +++ b/filesystems/btrfs.nix @@ -9,10 +9,17 @@ let in { options.aviallon.filesystems.btrfs = { enable = mkEnableOption "BTRFS support"; - autoScrub = mkOption { - type = types.bool; - default = true; - description = "Wether to enable automatic scrubbing"; + autoScrub = { + enable = mkOption { + type = types.bool; + default = true; + description = "Wether to enable automatic scrubbing"; + }; + paths = mkOption { + type = with types; nonEmptyListOf path; + default = btrfsPaths; + description = "What paths to scrub. Must be a btrfs mount point."; + }; }; autoDedup = { enable = mkOption { @@ -43,29 +50,37 @@ in { }; }; - config = mkIf cfg.enable { services.btrfs.autoScrub = { - enable = true; - fileSystems = [ "/" ]; + enable = cfg.autoScrub.enable; + fileSystems = cfg.autoScrub.paths; }; systemd.services.duperemove = { script = '' mkdir -p $DATA_DIR - exec ${pkgs.duperemove}/bin/duperemove --io-threads=${toString cfg.autoDedup.ioThreads} --cpu-threads=${toString cfg.autoDedup.cpuThreads} -h --dedupe-options=fiemap,same --hashfile=$DATA_DIR/hashes.db -v -Ard "$@" + exec ${pkgs.duperemove}/bin/duperemove \ + --io-threads=${toString cfg.autoDedup.ioThreads} --cpu-threads=${toString cfg.autoDedup.cpuThreads} \ + --dedupe-options=fiemap,same \ + --hashfile=$DATA_DIR/hashes.db -h -v -Ard "$@" ''; scriptArgs = concatStringsSep " " cfg.autoDedup.paths; # %S : state environment = { DATA_DIR = "%S/duperemove"; }; + unitConfig = { + ConditionCPUPressure = "50%"; + ConditionIOPressure = "30%"; + }; serviceConfig = { CPUQuota = "50%"; + CPUWeight = 1; Nice = 19; MemoryAccounting = true; MemoryHigh = "33%"; MemoryMax = "50%"; IOWeight = 10; + ManagedOOMMemoryPressure = "kill"; }; requires = [ "local-fs.target" ]; };