Skip to content
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

Add setting to warn about copying/hashing large paths #10661

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

edolstra
Copy link
Member

@edolstra edolstra commented May 7, 2024

Motivation

This is useful for diagnosing whether an evaluation is copying large paths to the store. Example:

$ nix build .#packages.x86_64-linux.default --large-path-warning-threshold 1000000
warning: copied large path '/home/eelco/Dev/nix-master/' to the store (6.0 MiB)
warning: copied large path '«github:NixOS/nixpkgs/b550fe4b4776908ac2a861124307045f8e717c8e?narHash=sha256-7kkJQd4rZ%2BvFrzWu8sTRtta5D1kBG0LSRYAfhtmMlSo%3D»/' to the store (148.1 MiB)
warning: copied large path '«github:libgit2/libgit2/45fd9ed7ae1a9b74b957ef4f337bc3c8b3df01b5?narHash=sha256-oX4Z3S9WtJlwvj0uH9HlYcWv%2Bx1hqp8mhXl7HsLu2f0%3D»/' to the store (21.1 MiB)
warning: copied large path '/nix/store/d5c5zw2z245sg3g05n0v3azgpcry8r2j-source' to the store (5.6 MiB)

The default is to not warn about large paths.

Fixes #4034.

Context

Priorities and Process

Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

@edolstra edolstra added the feature Feature request or proposal label May 7, 2024
@github-actions github-actions bot added the store Issues and pull requests concerning the Nix store label May 7, 2024
src/libstore/store-api.cc Outdated Show resolved Hide resolved
@fricklerhandwerk
Copy link
Contributor

Generally, rather than a new option, could this have been a higher-verbosity-level output with a greppable message pattern?

@edolstra
Copy link
Member Author

@fricklerhandwerk Yeah it could be done that way, but the main motivation is to get warnings when you aren't aware yet that you're doing something wrong (like having an attribute src = ./big-tree in a devShell). We might even want to set the default value for this option to something like 100 MiB.

@fricklerhandwerk
Copy link
Contributor

Yes I was wondering indeed why the default is maxint, because (at least in the past?) there has been a warning when the path is > 256 MB. Would make sense to leave it at that and simply make that configurable.

Copy link
Member

@roberth roberth left a comment

Choose a reason for hiding this comment

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

This is already very helpful and is definitely worth a release note!

src/libutil/util.cc Show resolved Hide resolved
src/libutil/util.hh Outdated Show resolved Hide resolved
total += n;
return n;
}
};
Copy link
Member

Choose a reason for hiding this comment

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

thoughts, optional

Previously we've used such a source or sink that warned as soon as the threshold was passed. I believe it counted the wrong thing, but that doesn't seem to be the case with its caller in this PR.

The benefit of warning as we go is that we can catch mistakes before the user has to wait for their store to fill up.
(For example, the backport action will instruct users to create nixpkgs/.worktree, which blows up ${nixpkgs} massively if not fetched via git, and it takes a long time to copy and produces no diagnostic feedback during that time)

Possible scheme and defaults:

  • Add the first 1GB silently
  • Print when passing 1GB
  • Print size when larger than 256 MB (nixpkgs seems to be around 170)

Example log (brief)

copying very large path /home/user/nixpkgs to the store. Is this what you intended? See `<url>#conf-large-path-warning-limit`
copied /home/user/nixpkgs to the store (2.3 GiB)

Copy link
Member

Choose a reason for hiding this comment

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

Another helpful feature is to have an enforced limit, which will also let us print a backtrace or launch the debugger.

Copy link
Member Author

Choose a reason for hiding this comment

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

The benefit of warning as we go is that we can catch mistakes before the user has to wait for their store to fill up.

Nowadays this is already somewhat handled by the progress bar (which will show "copying to the store" for a long time if it's a large path). It could be improved by showing the amount of data copied, like a download.

edolstra and others added 5 commits May 13, 2024 11:52
This is useful for diagnosing whether an evaluation is copying large
paths to the store. Example:

   $ nix build .#packages.x86_64-linux.default --large-path-warning-threshold 1000000
   warning: copied large path '/home/eelco/Dev/nix-master/' to the store (6271792 bytes)
   warning: copied large path '«github:NixOS/nixpkgs/b550fe4b4776908ac2a861124307045f8e717c8e?narHash=sha256-7kkJQd4rZ%2BvFrzWu8sTRtta5D1kBG0LSRYAfhtmMlSo%3D»/' to the store (155263768 bytes)
   warning: copied large path '«github:libgit2/libgit2/45fd9ed7ae1a9b74b957ef4f337bc3c8b3df01b5?narHash=sha256-oX4Z3S9WtJlwvj0uH9HlYcWv%2Bx1hqp8mhXl7HsLu2f0%3D»/' to the store (22175416 bytes)
   warning: copied large path '/nix/store/z985088mcd6w23qwdlirsinnyzayagki-source' to the store (5885872 bytes)
Also always include the unit (i.e. "MiB" instead of "M").
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Setting<uint64_t> largePathWarningThreshold{
this,
std::numeric_limits<uint64_t>::max(),
"large-path-warning-threshold",
Copy link
Member

Choose a reason for hiding this comment

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

Potential to improve discovery a bit by alphabetical grouping. Puts it next to warn-dirty.

Suggested change
"large-path-warning-threshold",
"warn-large-path-threshold",

@roberth
Copy link
Member

roberth commented May 13, 2024

Oh, don't forget the release note.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation feature Feature request or proposal new-cli Relating to the "nix" command store Issues and pull requests concerning the Nix store
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Warn when adding large local paths
4 participants