From c798fc116a04d4f397e4b9a5a91b9ca995dc8585 Mon Sep 17 00:00:00 2001 From: Aly Raffauf Date: Thu, 19 Dec 2024 23:53:11 -0500 Subject: [PATCH] hw/gaming: integrate cachyos sysctl and udev rules --- hwModules/common/gaming/default.nix | 46 +++++++++++++++-------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/hwModules/common/gaming/default.nix b/hwModules/common/gaming/default.nix index d4f378a0..b87c7ed6 100644 --- a/hwModules/common/gaming/default.nix +++ b/hwModules/common/gaming/default.nix @@ -6,39 +6,47 @@ boot = { kernel.sysctl = { # Improved file monitoring + "fs.file-max" = lib.mkDefault 2097152; # Set size of file handles and inode cache "fs.inotify.max_user_instances" = lib.mkOverride 100 8192; # Re-use the default from Bazzite even though the default NixOS value is higher. # "fs.inotify.max_user_watches" = lib.mkOverride 100 524288; - # Disable watchdogs for maximum performance at the cost of resiliency - "kernel.nmi_watchdog" = lib.mkOverride 100 0; - "kernel.soft_watchdog" = lib.mkDefault 0; - # "kernel.split_lock_mitigate" = lib.mkOverride 100 0; - "kernel.watchdog" = lib.mkDefault 0; - + "kernel.nmi_watchdog" = lib.mkOverride 100 0; # Disable watchdogs for maximum performance at the cost of resiliency "kernel.sched_cfs_bandwidth_slice_u" = lib.mkDefault 3000; "kernel.sched_latency_ns" = lib.mkDefault 3000000; - "kernel.sched_min_granularity_ns" = lib.mkDefault 300000; - "kernel.sched_wakeup_granularity_ns" = lib.mkDefault 500000; "kernel.sched_migration_cost_ns" = lib.mkDefault 50000; + "kernel.sched_min_granularity_ns" = lib.mkDefault 300000; "kernel.sched_nr_migrate" = lib.mkDefault 128; + "kernel.sched_wakeup_granularity_ns" = lib.mkDefault 500000; + "kernel.soft_watchdog" = lib.mkDefault 0; "kernel.split_lock_mitigate" = lib.mkDefault 0; + "kernel.unprivileged_userns_clone" = lib.mkDefault 1; + "kernel.watchdog" = lib.mkDefault 0; # Network optimizations "net.core.default_qdisc" = lib.mkDefault "fq"; + "net.core.netdev_max_backlog" = lib.mkDefault 16384; # Increase netdev receive queue "net.ipv4.tcp_congestion_control" = lib.mkDefault "bbr"; + "net.ipv4.tcp_ecn" = lib.mkDefault 1; + "net.ipv4.tcp_fastopen" = lib.mkDefault 3; "net.ipv4.tcp_fin_timeout" = lib.mkDefault 5; "net.ipv4.tcp_mtu_probing" = lib.mkForce 1; + "net.ipv4.tcp_rfc1337" = lib.mkDefault 1; # Protect against tcp time-wait assassination hazards, drop RST packets for sockets in the time-wait state. Not widely supported outside of Linux, but conforms to RFC. + "net.ipv4.tcp_slow_start_after_idle" = 0; # Disable TCP slow start after idle + "net.ipv4.tcp_timestamps" = lib.mkDefault 0; # https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux_for_real_time/7/html/tuning_guide/reduce_tcp_performance_spikes # Memory management "vm.dirty_background_bytes" = lib.mkDefault 134217728; "vm.dirty_bytes" = lib.mkDefault 268435456; - # "vm.max_map_count" = lib.mkOverride 100 2147483642; + "vm.dirty_writeback_centisecs" = lib.mkDefault 1500; + "vm.max_map_count" = lib.mkOverride 100 2147483642; "vm.page-cluster" = lib.mkDefault 0; - "vm.swappiness" = lib.mkDefault 180; + "vm.swappiness" = lib.mkDefault 150; + "vm.vfs_cache_pressure" = lib.mkDefault 50; "vm.watermark_boost_factor" = lib.mkDefault 0; "vm.watermark_scale_factor" = lib.mkDefault 125; }; + kernelModules = ["ntsync"]; kernelPackages = pkgs.linuxPackages_cachyos; }; @@ -128,18 +136,12 @@ }; udev.extraRules = '' - # Significantly improved I/O performance - ## SSD - ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="0", ATTR{queue/scheduler}="kyber" - - ## NVME - ACTION=="add|change", KERNEL=="nvme[0-9]n[0-9]", ATTR{queue/rotational}=="0", ATTR{queue/scheduler}="kyber" - - ## MicroSD - ACTION=="add|change", KERNEL=="mmcblk[0-9]p[0-9]", ATTR{queue/rotational}=="0", ATTR{queue/scheduler}="bfq" - - ## HDD - ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="1", ATTR{queue/scheduler}="bfq" + ACTION=="add|change", KERNEL=="mmcblk[0-9]p[0-9]", ATTR{queue/rotational}=="0", ATTR{queue/scheduler}="bfq" # SD cards use BFQ scheduler. + ACTION=="add|change", KERNEL=="nvme[0-9]n[0-9]", ATTR{queue/rotational}=="0", ATTR{queue/scheduler}="kyber" # NVMe use kyber scheduler. + ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="0", ATTR{queue/scheduler}="kyber" # SSD use kyber scheduler. + ACTION=="add|change", KERNEL=="sd[a-z]", ATTR{queue/rotational}=="1", ATTR{queue/scheduler}="bfq" # HHDs use BFW scheduler. + DEVPATH=="/devices/virtual/misc/cpu_dma_latency", OWNER="root", GROUP="audio", MODE="0660" # cpu_dma_latency writeable by audio group + KERNEL=="ntsync", MODE="0644" # /dev/ntsync user writeable ''; };