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

Make local evaluation less memory intensive #103

Open
Mic92 opened this issue May 5, 2020 · 11 comments
Open

Make local evaluation less memory intensive #103

Mic92 opened this issue May 5, 2020 · 11 comments

Comments

@Mic92
Copy link
Owner

Mic92 commented May 5, 2020

Currently nix needs around 3.6GB heap space when evaluation nixpkgs.
This is too much.

@piegamesde
Copy link

I see evaluations easily go over 6GiB memory usage, which way beyond reasonable.

I think the issue is that all the evaluated code is kept in RAM at once, although we never need more than what is required to evaluate one package at a time. If we could evaluate the packages sequentially in a way that discards the result as soon as possible that would help a lot.

I don't know but I suspect that fixing this will require improving stuff within Nix itself.

@mweinelt
Copy link

mweinelt commented Feb 3, 2022

Aaand I just saw 7-8 GB of memory usage. 👏

@Mic92
Copy link
Owner Author

Mic92 commented Feb 4, 2022

The issue is there is no real way of evaluating sequentially. For each package you would need to evaluate its dependencies at least. So you would trait a way longer CPU time for memory.

@Mic92
Copy link
Owner Author

Mic92 commented Feb 4, 2022

An efficient evaluator might be written in c++ itself. It could cache some evaluated store paths in memory while throwing away all the leaked nix state

@Et7f3
Copy link
Contributor

Et7f3 commented Apr 8, 2023

Last time I tried to reduce nix memory usage. I understand that all expression are keep in memory because you don't know in advance if they will be required later:

{
  foo = callPackage ./pkgs/foo {};
  bar = callPackage ./pkgs/bar {};
  baz = callPackage ./pkgs/baz {};
}

bar might need foo. Once bar is evaluated we can't throw foo because it might be needed for evaluating baz. If we throw it we will need to recompute baz. So it will be more CPU hungry.

Here is some hint if you want to improve nix memory usage NixOS/nix#7811 (comment)

@katexochen
Copy link

Just observed 14 GB of memory usage. o_0

@llakala
Copy link

llakala commented Sep 21, 2024

I'm actually getting an entire system crash when running nix-shell -p nixpkgs-review --run "nixpkgs-review pr 336494". I have 16 gigabytes of RAM, and the utilization just climbs and climbs until it hits 100% and the Gnome shell crashes.

@pbsds
Copy link
Contributor

pbsds commented Sep 23, 2024

related:

I believe the switch to nix-eval-jobs will also aid in reducing the memory requirements, trading heap memory for duplicate computations.

@Frontear
Copy link

Frontear commented Oct 1, 2024

+1 to this. On Linux 6.11+ evaluation entirely fails on my system. I wrote up a little bit more about it over on nix-index: nix-community/nix-index#64 (comment)

On a side note, I've been actually struggling a lot in the testing of a large nixpkgs PR entirely due to this exact problem. So far, every single build (not eval yes, but closely related to Nix) failure I've run into was a result of system resource exhaustion, and it's become quite bothersome.

@HeitorAugustoLN
Copy link

I've been hitting 99% RAM Usage too, when trying to run nixpkgs-review, and after that my terminal just crashes with 16GB of RAM.

@myclevorname
Copy link

I have hit around 15 GB of RAM, which is twice my laptop's capacity. Enabling zram and disabling my swap partition caused the OOM killer to crash my system last night (or earlier today, i forgot).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants