Skip to content

rust-analyzer triggers the OOM killer (on a machine with 32GB RAM) #16908

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
RalfJung opened this issue Mar 21, 2024 · 11 comments
Closed

rust-analyzer triggers the OOM killer (on a machine with 32GB RAM) #16908

RalfJung opened this issue Mar 21, 2024 · 11 comments
Labels
A-perf performance issues Broken Window Bugs / technical debt to be addressed immediately C-bug Category: bug

Comments

@RalfJung
Copy link
Member

RalfJung commented Mar 21, 2024

RA uses a lot of RAM. I know there are existing issues for that, but recently it seems to have gotten a lot worse. In the last 2 days I had two situations where my machine would freeze. In one case my entire session got restarted, in one case only RA got killed. This is the first time ever that happened since I got this machine about a year ago -- usually, 32GB of RAM is plenty enough. And it always was enough for RA as well, even when working on rustc. But now, not any more:

[2862128.625072] gjs invoked oom-killer: gfp_mask=0x140cca(GFP_HIGHUSER_MOVABLE|__GFP_COMP), order=0, oom_score_adj=200
[...]
[2721289.221086] Tasks state (memory values in pages):
[2721289.221087] [  pid  ]   uid  tgid total_vm      rss pgtables_bytes swapents oom_score_adj name
[...]
[2862128.625531] [3362372]  1000 3362372  7956223  4677234 37851136        0           100 rust-analyzer
[...]
[2862128.625539] [3389510]  1000 3389510   613998   267026  2478080        0           100 rust-analyzer
[...]
[2862128.625582] Out of memory: Killed process 3362372 (rust-analyzer) total-vm:31824892kB, anon-rss:18706536kB, file-rss:2400kB, shmem-rss:0kB, UID:1000 pgtables:36964kB oom_score_adj:100

I have also seen the RA extension lose track of RA processes -- there was a single vscode window open with a Rust project, and yet pidof rust-analyzer would report two processes. Closing the window would only terminate one of these processes, the other had to be killed by hand. And it seems like that was the case above as well, according to the task list printed by the OOM killer. However, in the past I had 3 vscode windows open with RA (2 times rustc and one time Miri) and didn't run into freezes, so just having two instances (i.e., double the RAM usage) doesn't suffice to explain this.

rust-analyzer version: rust-analyzer version: 0.3.1885-standalone (b6d1887 2024-03-17)

@RalfJung RalfJung added the C-bug Category: bug label Mar 21, 2024
@Veykril
Copy link
Member

Veykril commented Mar 21, 2024

Closing the window would only terminate one of these processes, the other had to be killed by hand.

Might be that VSCode leaves the LSP processes around if they don't shut down by themselves after receiving a shutdown request (which would be the case if r-a hangs up for some reason).

Just to check, you are not using the new test explorer feature right? (it's opt-in and has some known perf problems).

I don't see anything special that we added in last stable release that could explain this 😕 https://rust-analyzer.github.io/thisweek/2024/03/18/changelog-225.html

@Veykril
Copy link
Member

Veykril commented Mar 21, 2024

Just to double check, are you sure you are not on a nightly r-a version? Because if yes then this is most likely the same issue as #16902

@RalfJung
Copy link
Member Author

Just to double check, are you sure you are not on a nightly r-a version? Because if yes then this is most likely the same issue as #16902

I copied the RA version that vscode reports. I never intentionally opted-in to a nightly version. I am using vscodium with its open-source extension store; not sure if that would make a difference?

Just to check, you are not using the new test explorer feature right? (it's opt-in and has some known perf problems).

I have no idea what a test explorer is so I think I am not using it. :D

@Veykril Veykril added A-perf performance issues Broken Window Bugs / technical debt to be addressed immediately labels Mar 21, 2024
@msvbg
Copy link

msvbg commented Mar 21, 2024

I'm also experiencing this. Using nightly rust analyzer rust-analyzer 1.79.0-nightly (a7e4de13 2024-03-19) on a normal small-ish project, my system OOM:ed and RA was using 70+ GB of RAM.

@HKalbasi
Copy link
Member

HKalbasi commented Mar 21, 2024

Might be similar to #16907? Does it happen in nightlies older than 03-19? the OP is on nightly 03-17

@msvbg
Copy link

msvbg commented Mar 21, 2024

I was previously running the nightly from March 3rd I think, and it was not exhibiting this.

@vnghia
Copy link

vnghia commented Mar 22, 2024

I'm also experiencing this with rust-analyzer 1.79.0-nightly (0ad927c 2024-03-21) with a relatively small project. I've got OOM while running rust-analyzer analysis-stats .

@Veykril
Copy link
Member

Veykril commented Mar 22, 2024

It might just be #16907, I experienced OOMs after upgrading my nightly toolchain today as well

@RalfJung
Copy link
Member Author

Just had another OOM take down my entire Gnome session.

Mär 22 15:11:17 r-ethtop kernel: Out of memory: Killed process 3571299 (rust-analyzer) total-vm:31849660kB, anon-rss:19261664kB, file-rss:1920kB, shmem-rss:0kB, UID:1000 pgtables:38112kB oom_score_adj:100

I guess the OOM killer was too late and that's why the gnome shell died as well, or something like that.

@the8472
Copy link
Member

the8472 commented Mar 24, 2024

I'm running into this too. To ensure that not the entire system gets bogged down and instead only vscode gets killed I start it with

systemd-run --user -p "MemoryMax=40G" vscode

to constrain the memory of the entire process tree via cgroups (this requires cgroups v2 and delegation of the memory controller).

Pointing rust-analyzer.server.path to a wrapper script might work too so the limit only gets applied to the LSP instead all of the entire editor.

@kawadakk
Copy link

kawadakk commented Apr 3, 2024

nightly-2024-04-01 (rust-analyzer 1.79.0-nightly (80581365 2024-03-31)) doesn't cause an excessive memory usage anymore for me.

@Veykril Veykril closed this as completed Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-perf performance issues Broken Window Bugs / technical debt to be addressed immediately C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

7 participants