-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Reduce memory leaks #7811
Reduce memory leaks #7811
Conversation
This looks great!
What's Could you add your findings to the |
I don't know how I got this binary. Brew should install in /usr/local/bin so it seems builtin in MacOS . I can add those but I prefer using LeakSanitizer (better error reporting) I don't know why it stopped working and I haven't a commit where it worked (I will search one with date) |
Thanks for making this! I'm also trying to eval nixpkgs recursively and hitting memory errors. This PR might help with #7816 |
Code lgtm. Could you squash the commits? |
… objects We are looking for *$ because it indicate that it was constructed with a new but not release. De-referencing shallow copy so deleting as whole might create dangling pointer that's why we move it so we delete a empty containers + the nice perf boost.
5e889c9
to
cec23f5
Compare
done |
Thank you so much @Et7f3 !
I think the reasoning was that it's more efficient not to clean those up correctly. If that's really the case, perhaps we should have a compilation flag that enables correct cleanup, just for the purpose of evaluating code quality.
|
It is not a performance choice because it copy Lines 905 to 908 in a88ae62
(new std::string {...})->c_str() and leak only the structure or keep using std::string_view
And Line 185 in e4726a0
I would advocate for second option: by managing ourself it might show place where we could do move and get a perf boost. Also an other argument is in the sampling, the GC is already overloaded and AST node are not needed at eval time since Value are created. Do you want I move the |
For my use case I use repl and it leaks a lot (it is acceptable for a short lived program). What nix program are log-lived server that might leak ? |
Motivation
I wanted to evaluate all nixpkgs recursively. So I can get the derivers for the package I can and dependents. I saw the warning but just wanted to evaluate so it should be safe ? When I did it, the process hang and with sampling I saw it was in GC code very often
I saw virtual memory going crazy (75Go I think it is uncompressed because I haven't seen a such large swap file) and it shows me:
I didn't fixed all the leaks but almost an halved the node allocation and solved 90% of leaked bytes. It is a memory usage improvement because I move instead of copying.
On master:
after my PR:
LeakSanitizer doesn't works with nixpkgs so I used:
1>leaks_log_master 2>&1 /usr/bin/leaks --atExit -- nix-master/bin/nix repl ../nixpkgs <<<$(echo legacyPackages.x86_64-darwin); 1>leaks_log_built 2>&1 /usr/bin/leaks --atExit -- src/nix/nix repl ../nixpkgs <<<$(echo legacyPackages.x86_64-darwin)
I identified other leaks root cause:
Expr*
Expr
and derived doesn't implement destructor correctly so even with the GC they can't free the whole memory used.Those cause would imply a more bigger change so I open-ed PR to see if it is worth.
Context
Each commit I diffed with master to see no regression and didn't see one so it should be correct even if
installcheck
isn't running on master.The first commit isn't worth a PR (so it is their) but while I changed code I just saw and I modified it.
Each commit should be droppable but I intend to merge all expect the first.
Checklist for maintainers
Maintainers: tick if completed or explain if not relevant
tests/**.sh
src/*/tests
tests/nixos/*