Skip to content

nixos/sysctl: dynamic inotify watches or higher defaults #126777

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions nixos/modules/config/sysctl.nix
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,21 @@ in
# Disable YAMA by default to allow easy debugging.
boot.kernel.sysctl."kernel.yama.ptrace_scope" = mkDefault 0;

# Dynamic since kernel v5.12
# https://github.com/torvalds/linux/commit/ac7b79fd190b02e7151bc7d2b9da692f537657f3
# From version 5.12 inotify instances are charegd memcg, so to let memcg work
# properly in all possible circumstance, kernel mainatainers (see commit) suggest
# to make this value ineffective by setting it to the maximum
boot.kernel.sysctl."fs.inotify.max_user_instances" =
if (config.boot.kernelPackages.kernel.kernelAtLeast "5.12")
then mkDefault 2147483647 # INT_MAX, dynamically limited based on available memory
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make boot.kernel.INT_MAX a variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess, it would be more like in the stdenv, though or lib or even builtin. I can make a quick follow-up PR once this is merged.

else mkDefault 8192; # instead of 128

# Dynamic since kernel v5.11
# https://github.com/torvalds/linux/commit/92890123749bafc317bbfacbe0a62ce08d78efb7
boot.kernel.sysctl."fs.inotify.max_user_watches" = mkIf
(config.boot.kernelPackages.kernel.kernelOlder "5.11")
(mkDefault 1048576); # instead of 8192

};
}
6 changes: 0 additions & 6 deletions nixos/modules/services/x11/xserver.nix
Original file line number Diff line number Diff line change
Expand Up @@ -663,12 +663,6 @@ in
icons.enable = true;
};

# The default max inotify watches is 8192.
# Nowadays most apps require a good number of inotify watches,
# the value below is used by default on several other distros.
boot.kernel.sysctl."fs.inotify.max_user_instances" = mkDefault 524288;
boot.kernel.sysctl."fs.inotify.max_user_watches" = mkDefault 524288;

systemd.defaultUnit = mkIf cfg.autorun "graphical.target";

systemd.services.display-manager =
Expand Down
2 changes: 0 additions & 2 deletions nixos/modules/virtualisation/lxd.nix
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,6 @@ in {

boot.kernel.sysctl = mkIf cfg.recommendedSysctlSettings {
"fs.inotify.max_queued_events" = 1048576;
"fs.inotify.max_user_instances" = 1048576;
"fs.inotify.max_user_watches" = 1048576;
"vm.max_map_count" = 262144;
"kernel.dmesg_restrict" = 1;
"net.ipv4.neigh.default.gc_thresh3" = 8192;
Expand Down