-
Notifications
You must be signed in to change notification settings - Fork 821
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
WSL 2 consumes massive amounts of RAM and doesn't return it #4166
Comments
Thanks for opening the issue. We have a fix for this in the works. |
After moving to WSL2, VmMem seems to be constantly pegging my CPU. Please see attached screenshots. Anything I can do to help your team troubleshoot? Relevant details:
|
I'm experiencing this too. It happens every time I run wsl after some elapsed time (varying from minutes to hours). It continues regardless of what's running in wsl, and I need to issue a Windows insider build: 18922.1000 I assume this really belongs in a new issue, but wanted to group my comment with that of @mithunshanbhag so I'll leave it here. |
Hi, |
Same issue on Win build 18950 |
@benhillis - Do we have a rough ETA on the fix? I'm actually hitting OOM issues on a machine with 32 gigs while just running a normal ninja build that should succeed. Build 18955 |
@zachChilders - ETA on this one is a bit hard unfortunately. Certainly before WSL2 ships to non-insiders. |
how about a workaround? this just started happening for me (with 18965) and it has effectively killed my WSL 2 environment |
Depending of your usage, nocache utility can be used as a workaround to greatly reduce WSL 2 memory consumption, especially if whatever you're running inside it does a lot of filesystem operations... |
does nocache follow children? I could start my shell with "nocache"... |
Haven't tried, but if I understood how nocache works correctly, it should... |
thanks! nocache has changed my env from "completely broken" to "merely sucks" |
Hi, could you explain how nocache should be used? |
Hi @benhillis , any update on when a fix for this might be deployed to insiders? My 8gb of ram is really getting hammered by this issue... :( |
I wrap compilations in nocache to keep limping along. wrapping nocache around a shell works, but breaks emacs. I've also ordered more RAM :-( |
Sorry no firm timeline, certainly before WSL2 is out of Insider builds though. |
Hi @benhillis , do you have a workaround you could recommend though ? |
Well...I need it all day long and the memory consumption goes crazy after only a few minutes (using docker and a quite heavy stack: elastic search, lots of workers, some databases etc). So...not an option unfortunately. Maybe go back to linux while it is not fixed 😎 |
I am facing the same issue. Is there any workaround (except shutting wsl down) for this @benhillis ? |
Not currently. For some additional context this change requires some changes to the Linux kernel that are in the process of being upstreamed. We will be integrating these changes into the WSL2 kernel as soon as we can. |
Workaround: Create a Example
This will still consume the entire 6GBs regardless of Linux memory usage, but at least it'll stop growing more than that. Supported settings are documented here. |
IMO, using Docker to run everything adds complexity and overhead without commensurate benefit. I wrote an article describing how I run Ollama on WSL2. |
That doesn't make sense. Open Resource Monitor and look at the Memory tab for the real culprit. Also make sure there is not running another Windows user session. |
There is a different issue regarding high CPU use: #8529 |
Just tried running my auto HandbreakCLI encoder on WSL2 and encountered this. Meanwhile my proxmox lxc which has been running for days is using 12G with the exact same OS and config and 2x the cores (id assume that effects encoding memory usage) To be clear this is a fresh barebones WSL2 with only FFMPEG, core-utils and handbreakCLI installed. its just nuts. |
I only use WSL for small processes. For bigger processes, I either use VirtualBox or native Linux. |
For users with AMD gpu, the community discovered a memory leak in the Adrenaline v24 video drivers. Disable the integrated GPU or downgrade the video drivers to Adrenaline v23. More info in this thread: |
I don't have this problem on Win10, but have it on Win11. |
same issue 5 years later |
Simply copying a few gigs of data in WSL is enough to consume a lot of RAM by WSL. |
So WSL 2.3.11 update does not improve the situation? There is nothing in the notes about it |
How would they mine Bitcoin in our pc if they address this issue |
Still having the same issue even with the latest WSL2. Docker-Desktop having its own memory leaks isn't helping either :/ This is on a always running VMWare VM with Nested Virtualized Enabled on an Intel Xeon Gold 6430, Windows 10 and fully updated VM, WSL etc. WSL2 Ubuntu 22.04.03 has been allocated 20GB RAM max (Out of 64GB). I had it saying 54GB used yesterday, so I ran RAMMAP64.exe. Amazingly, it flushed the RAM, and I went down to 22-24GB, which is about typical for my dev environment. As you can see here, "Driver Locked" memory is what has stolen all of my RAM, and repeatedly terminating WSL2 / Docker to clear RAM shouldn't be the solution Even after stopping WSL2 and Docker, we still have 16-20GB of unusable memory noted by Task Manager. |
same problem here |
Same here... The more I use WSL, the more I want to return to native Linux. It has way too many issues. |
Avoid using Docker Desktop, switch to Docker CE directly in your WSL2 distro - noticed memory usage has been a lot better and you don't miss anything other than the clunky electron UI of docker-desktop. |
How is this issue still open after ~ 5 years? |
Many users face issues because they don’t properly configure the Docker VM WSL2 limits when using Docker Desktop. Additionally, there’s a general misunderstanding of how RAM is used in Linux. For more information, check out this link: https://www.linuxatemyram.com/ |
I am sorry about being toxic at this point, but I bet for WSL from V1 as my team's main development environment. Now after waiting and fighting against the memory leak bug for 3 years or so, we ended up giving up for that. We also bought 32Gb RAM laptops in case they are usable and they couldn't handle building docker images in some cases without hitting swap (throttling by rising disk I/O to 100%). It feels like Docker Desktop, VSCode & WSL2 are doing this RAM hoarding on purpose. I also tried out the new Sadly we are migrating to Linux desktop and pushing happy people on windows to a new OS, something we hate to do honestly. I really hope a comeback on this issue Thanks for trying 🙏 |
To be clear, my comment was directed toward the developers / maintainers of WSL. I just don't understand how an issue could be reported and not solved in 5 years. You could rewrite the entire thing from scratch twice in that timeframe. I too have continually revisited v2 and resorted to reverting to v1 for various reasons. |
The OP did not mention Docker. This issue is not restricted to Docker, and is not dependent on Docker. |
You are right, Docker and VSCode makes the issue worse taking large amounts of ram. Docker had issues itself taking more than 3Gb just for running 0 containers. VSCode WSL extension adds an extra layer of memory leak as reported in other thread, where a faulty AMD driver from x version takes pieces of RAM over the time on top of this thread issue. |
The longer WSL runs and I do things in it, even after configuring WSL to only use a maximum amount of memory, it will use more and overage usage will become "hidden" in task manager until the usage is hitting 90+ percent of 64GB of memory with task manager stating WSL is only using around the max I set. People online will say "Unused ram is wasted ram" but as this reaches over 90 percent used ram, many other processes begin slowing down -- this ram can't be freed for some odd reason. Even shutting down WSL will not free the majority of ram this process secretly consumes. |
While is true that unused RAM is wasted RAM, not the case when you have two OSes competing for it. sync; echo 3 > /proc/sys/vm/drop_caches And it actually works, you will see the memory being reclaimed. I guess its a trick to make Plan9 share not suck, which ended up not flushing any cache. |
Any chance to run this with cron so every X seconds the unused memory is released? |
Let me introduce my script which does exactly the same thing you mentioned, based on CPU load so you won't lose required cached data: https://github.com/validatedev/drop-cache-if-idle |
You can't imagine how much appreciated hommie. |
Yes, its in one of the hidden comments above. I had the same problem with docker. I just don't have enough memory, but instead of releasing the cache, the WSL VM simply tries to get more RAM instead. and ends up swapping as a result. Not sure if validatedev's solution will work, since you are supposed to be busy while building these images. You get a performance hit for dropping the caches, but at least things continue working and it won't kill the SSD, which is what I'm concerned. Lucky me I can totally use WSLv1 for most of my stuff, and it just works. Until you get a bsod that is. |
Your Windows build number: 18917
What's wrong / what should be happening instead: WSL 2 starts using huge amounts of RAM after a while, just using it like normal. At the moment I'm using phpstorm, and did a dump/load of a database.
Vmmem
is using 7 GB of my 16 GB of RAM and not returning any, even though Ubuntu is actually using much less. I have seen it grow until nearly 100% of my system memory is in use, and it will not release it until I shut down the WSL 2 VM.This may or may not be related to #4159
The text was updated successfully, but these errors were encountered: