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

WSL 2 consumes massive amounts of RAM and doesn't return it #4166

Open
LordMonoxide opened this issue Jun 17, 2019 · 373 comments
Open

WSL 2 consumes massive amounts of RAM and doesn't return it #4166

LordMonoxide opened this issue Jun 17, 2019 · 373 comments
Assignees
Labels
wsl2 Issue/feature applies to WSL 2

Comments

@LordMonoxide
Copy link

LordMonoxide commented Jun 17, 2019

  • 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

corey@Corey-Laptop:/mnt/c/WINDOWS/system32$ vmstat -s
     15235516 K total memory
       920348 K used memory
      1886048 K active memory
      6434312 K inactive memory
      6606548 K free memory
        76280 K buffer memory
      7632340 K swap cache
            0 K total swap
            0 K used swap
            0 K free swap
       163729 non-nice user cpu ticks
          298 nice user cpu ticks
        13177 system cpu ticks
     68988300 idle cpu ticks
         8962 IO-wait cpu ticks
            0 IRQ cpu ticks
        10022 softirq cpu ticks
            0 stolen cpu ticks
      1481417 pages paged in
      6792976 pages paged out
            0 pages swapped in
            0 pages swapped out
      1079177 interrupts
      5131981 CPU context switches
   1560599814 boot time
         8772 forks
@Drakota
Copy link

Drakota commented Jun 17, 2019

Same here with Docker running on Ubuntu 18.04
image

@benhillis
Copy link
Member

Thanks for opening the issue. We have a fix for this in the works.

@mithunshanbhag
Copy link

mithunshanbhag commented Jun 19, 2019

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:

  • Ubuntu 18.04 and Debian on WSL2, but none are running anything at the moment.
  • Windows insider build 18917.1000 on Macbook Air (8 GB, 4 proc).

image
image

@crispinb
Copy link

crispinb commented Jul 2, 2019

After moving to WSL2, VmMem seems to be constantly pegging my CPU. Please see attached screenshots.

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 wsl --shutdown to stop it.

Windows insider build: 18922.1000
Linux distro: 18.04

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.

@md0x
Copy link

md0x commented Jul 22, 2019

Hi,
Same problem here.
Lots of memory consumption with WSL2, nodejs app and VS Code with Remote - WSL while very low consumption in WSL1 with the same tasks.

@liyo
Copy link

liyo commented Aug 1, 2019

Same issue on Win build 18950

@zachChilders
Copy link

@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

@benhillis
Copy link
Member

@zachChilders - ETA on this one is a bit hard unfortunately. Certainly before WSL2 ships to non-insiders.

@avafloww
Copy link

Can confirm this on 18963 as well. WSL 2 ate most (29GB+ of 32GB) of my RAM after less than 15 minutes of uptime for no good reason; all I've done is a rsync from the host NTFS volume to the ext4 volume, and an apt-get update.

@david-dumke
Copy link

I can confirm the same issue on Microsoft Windows [Version 10.0.18963.1000]

C:\Users\david_d>wsl -l -v
NAME STATE VERSION

  • Ubuntu-18.04 Running 2
    Ubuntu Stopped 1

image

I at the time was running gdb

@rob-solana
Copy link

rob-solana commented Aug 22, 2019

how about a workaround? this just started happening for me (with 18965) and it has effectively killed my WSL 2 environment

@mbc07
Copy link

mbc07 commented Aug 22, 2019

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...

@rob-solana
Copy link

does nocache follow children? I could start my shell with "nocache"...

@mbc07
Copy link

mbc07 commented Aug 22, 2019

Haven't tried, but if I understood how nocache works correctly, it should...

@rob-solana
Copy link

thanks! nocache has changed my env from "completely broken" to "merely sucks"

@Beretta1979
Copy link

Beretta1979 commented Aug 27, 2019

thanks! nocache has changed my env from "completely broken" to "merely sucks"

Hi, could you explain how nocache should be used?

@willbuilds
Copy link

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... :(

@rob-solana
Copy link

I wrap compilations in nocache to keep limping along. wrapping nocache around a shell works, but breaks emacs. I've also ordered more RAM :-(

@benhillis
Copy link
Member

Sorry no firm timeline, certainly before WSL2 is out of Insider builds though.

@fabienheureux
Copy link

fabienheureux commented Aug 29, 2019

Hi @benhillis , do you have a workaround you could recommend though ?

@fabienheureux
Copy link

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 😎

@weberdominik
Copy link

I am facing the same issue. Is there any workaround (except shutting wsl down) for this @benhillis ?

@microsoft microsoft deleted a comment from md0x Aug 29, 2019
@benhillis
Copy link
Member

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.

@apostolos
Copy link

Workaround: Create a %UserProfile%\.wslconfig file in Windows and use it to limit memory assigned to WSL2 VM.

Example

[wsl2]
memory=6GB
swap=0
localhostForwarding=true

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.

@sarim
Copy link

sarim commented Mar 28, 2024

@Ali-thepro the system distro aka wslg is also running a wayland server & stuffs. You can disable wslg if free memory is that important to you. Also linux could use free memory as cache. You can tweak those too, but those are all linux quarks/features, not really WSL issue.

I also have 32GB ram in desktop and gave 16GB in .wslconfig. I can't remember facing a error with 32GB full ram. Seeing your task manager screenshot saying overall memory usage is 50% I'd its very okey, why worry?

@Ali-thepro
Copy link

@sarim

I know it's fine but a couple days ago it wasn't this much. I know right now it's only 3 gb but couple hours ago I shutdown my laptop and as soon as I opened it 6gb was being used.

@Ali-thepro
Copy link

after running wsl-shutdown vmmem goes to 1.5 gb but just opening vscode in wsl it goes back up to 3 gb, this issue never happened before.

@wolf99
Copy link

wolf99 commented Mar 28, 2024

after running wsl-shutdown vmmem goes to 1.5 gb but just opening vscode in wsl it goes back up to 3 gb, this issue never happened before.

IME , Running wsl-shutdown should stop vmmem completely.
If you still see 1.5 GB usage then perhaps your machine is running something else aside from WSL that is impacting this?

@Ali-thepro
Copy link

@wolf99

My mistake, I meant after running wsl after shutting it down it takes 1.5gb

@Ali-thepro
Copy link

image

just ran a small django and front end app on docker 👍, nice stuff wsl team, vmmem was using 10 gigs at one point as well.

@eboraks
Copy link

eboraks commented Apr 12, 2024

Something is not right with WSL2 with Windows version 10.0.22631, Build 22631. After a fresh restart of the system and nothing running on WSL2, it's consuming 8GB. I was able to reduce it to 4GB by running sudo sync; echo 3 | sudo tee /proc/sys/vm/drop_caches

@KoalaBear84
Copy link

KoalaBear84 commented Apr 12, 2024

Yes, I did have something similar, nothing super special about the containers, but this time it did fill up the whole 48GB RAM, by using 14GB or 24GB or so. Don't know anymore. I tried updating Windows, wsl --shutdown etc and rebooting. Rebooting didn't help for long. Now I've finally made the %userprofile%.wslconfig file.

# Settings apply across all Linux distros running on WSL 2
[wsl2]

# Limits VM memory to use no more than 4 GB, this can be set as whole numbers using GB or MB
memory=8GB

[experimental]
autoMemoryReclaim=gradual

Seems for work for the last days. Currently the vmmem 'process' is using only 2774 MB.

@wasuaje
Copy link

wasuaje commented Apr 13, 2024

I'm having the same issue, I'm trying this for a while

# Settings apply across all Linux distros running on WSL 2
[wsl2]

# Limits VM memory to use no more than 4 GB, this can be set as whole numbers using GB or MB
memory=8GB

[experimental]
autoMemoryReclaim=gradual

@moracabanas
Copy link

moracabanas commented Apr 19, 2024

Same issuse as mentioned here:

I deleted docker recently, but vmmem is still using a lot of memory, couple days ago it was fine now after fresh boot its using 3 gb of memory. I just have 2 wsl terminals open. If I close them it will go down to 1.5. image

This is what I get from htop image

I have 32 gb ram on my laptop but its getting annoying, its taking too much storage. I tried to limit it in .wslconfig but it causes perfomance issues if I set it too low.

My fresh ubuntu WSL with autoMemoryReclaim=dropcache

image

My exact same WSL fresh instance afeter just opening vscode:

image

The first time I started to use WSL2 when it came out, it was a breeze. Then Docker Desktop integration was a dream to work with.
Finally, today I cannot just run a single container without taking 90% RAM of my 16Gb and start noticing massive performance drop because Swap start kicking in. Not even to mention about building simple docker images.
Suddenly your .vhdx distro virtual disk will eat your space if you work with large files, python environment and that wont ever be reclaimed back. You can try to compress the .vhdx with DISKPART googling some tutorials, or try the next .wslconfig:

[experimental]
sparseVhd=true

But when that experimental feature came out, it just destroyed my windows system, corrupting random files across my computer. I was forced to format once.
I am giving it a last chance to work with WSL and sparseVhd. But my productivity is hold by a thin rope because of this issue.

I finally uninstalled Docker Desktop and installed Docker CE on WSL2 but the problem persist with VSCode as a RAM hoarder.
Today, after years of recommending wsl to my teammates, my dream development environment is a nightmare and I cannot fix theirs.

I am forced to dual boot again as the last workaround.

@italocjs
Copy link

Same issue:

  • fresh install of win 11 23H2
  • WSL2 + ubuntu (default)
  • installed docker desktop (followed official documentation)
  • 32GB of ram in host, wsl using 8-12gb just by opening a vscode devcontainer.
    code --version 1.88.1 e170252f762678dec6ca2cc69aba1570769a5d39 x64

Before reinstalling windows (just did a fresh reinstall today) i rarely hit 2gb, unfortunately i did not register the exact versions

@craigloewen-msft
Copy link
Member

@moracabanas When you had autoMemoryReclaim=dropCache turned on, did you find it wasn't dropping cache? Even when your machine was idle and you were using it?

We turned that feature on by default in latest WSL pre-release builds and our aim is for it to help tackle the 'WSL holds onto lots of my RAM' problem.

@arelhabib
Copy link

so i have this problem where's vmmem still using the memory if terminate instance by using terminate command even though theres no running instances, and only wsl --shutdown will released the memory
image

did wsl --terminate works with the 10 minutes dropcache idle time, so after 10 minutes period wsl will free the memory/kill the vmm process? my WSL version: 2.1.5.0

@mystiverv
Copy link

I am having this same issue , WSL2 ubuntu 20.04 on Windows 11 i9-13900HX with 32GB of RAM. WSL2 will take up to 70% of my RAM while installing a simple apt package or coding and won't return it when the process is finished. It just keeps building its memory use until I shut it down.

image

@mrAnomalyy
Copy link

mrAnomalyy commented May 4, 2024

Same here on AMD Processor (5800H). After using Ollama in WSL, after stopping it, WSL never releases the RAM.

updt. I am quite wrong about this. It works as it descibed early in this topic. I mean, WSL releases memory when Windows requests it - when RAM load goes above 90%.
On screenshot I used Ollama in WSL and it took 12 Gb of RAM, but after I simulated RAM requests (basically starting games which require a lot of memory) we can see Windows very simply and fast releases RAM. So it isnt an issue for me for now I guess.
image

@gustavozantut
Copy link

I really don't know who said Microsoft isn't mining Bitcoin on our machine. It really looks like

@kingindanord
Copy link

@gustavozantut 100%

@adrianprocopiou
Copy link

After years of following this thread I came to the conclusion that the problem was ME trying to use Docker on Windows, it simply isn't functional, it has already been said that WSL2 is behaving as it should. For MY NEEDS, I was simply able to work better using Linux in dualboot, where Docker works perfectly for ME, without leaving my computer without resources to carry out other activities, such as debugging in my IDE what is running in Docker. I'm not speaking in a hateful tone, I'm just advising other colleagues that this could be a more productive way out.

@theAkito
Copy link

theAkito commented May 9, 2024

After years of following this thread I came to the conclusion that the problem was ME trying to use Docker on Windows, it simply isn't functional, it has already been said that WSL2 is behaving as it should. For MY NEEDS, I was simply able to work better using Linux in dualboot, where Docker works perfectly for ME, without leaving my computer without resources to carry out other activities, such as debugging in my IDE what is running in Docker. I'm not speaking in a hateful tone, I'm just advising other colleagues that this could be a more productive way out.

Could you please link the issue you opened on Docker's end?

@moracabanas
Copy link

After years of following this thread I came to the conclusion that the problem was ME trying to use Docker on Windows, it simply isn't functional, it has already been said that WSL2 is behaving as it should. For MY NEEDS, I was simply able to work better using Linux in dualboot, where Docker works perfectly for ME, without leaving my computer without resources to carry out other activities, such as debugging in my IDE what is running in Docker. I'm not speaking in a hateful tone, I'm just advising other colleagues that this could be a more productive way out.

Could you please link the issue you opened on Docker's end?

In my case I switched from docker desktop to docker ce in wsl and there is no 4GB ram overhead anymore.
Use lazydocker a cli UI like docker desktop and you are good to go.

I am sorry but Docker desktop is taking more and more ram to the point my workflow is to expect not hitting swap by running 1 python container and maxing out resources.

@terebentina
Copy link

@moracabanas any tutorial you followed to switch to docker ce? I'd like to try the same but too busy lazy to figure out all steps by myself.

@kyriakos
Copy link

@moracabanas any tutorial you followed to switch to docker ce? I'd like to try the same but too busy lazy to figure out all steps by myself.
this works:
https://onlyutkarsh.medium.com/running-docker-in-wsl2-ubuntu-distro-without-docker-desktop-6ec495e8bb4d

@ddolgov
Copy link

ddolgov commented Jun 7, 2024

After years of following this thread I came to the conclusion that the problem was ME trying to use Docker on Windows, it simply isn't functional, it has already been said that WSL2 is behaving as it should. For MY NEEDS, I was simply able to work better using Linux in dualboot, where Docker works perfectly for ME, without leaving my computer without resources to carry out other activities, such as debugging in my IDE what is running in Docker. I'm not speaking in a hateful tone, I'm just advising other colleagues that this could be a more productive way out.

I am not using Docker, but have the same problem with WSL2 gobbling up RAM and .wslconfig is useless

@Apellamen
Copy link

for who using docker only for ollama, I have resolved removing docker and running ollama on pinokio.

@mslinn
Copy link

mslinn commented Jun 7, 2024

IMO, using Docker to run everything adds complexity and overhead without commensurate benefit. I wrote an article describing how I run Ollama on WSL2.

@sultanmaa0
Copy link

trying .wslconfig method but it still useless
image
image
as you can see, i have 32 GB RAM installed and limiting wsl ram usage to 2GB but vmmem still consuming lot of RAM even though it didnt show in task manager (possibly more than 40%) and if i keep it runn for 2-3 days it will grow up to 80-90%

tried using wsl --shutdown to release the RAM but still useless, cause i see that in task manager it still consume 80-(90% RAM

@sarim
Copy link

sarim commented Jun 18, 2024

trying .wslconfig method but it still useless image image as you can see, i have 32 GB RAM installed and limiting wsl ram usage to 2GB but vmmem still consuming lot of RAM even though it didnt show in task manager (possibly more than 40%) and if i keep it runn for 2-3 days it will grow up to 80-90%

tried using wsl --shutdown to release the RAM but still useless, cause i see that in task manager it still consume 80-(90% RAM

525 + 1.1G = ~1.6G. Task manager shows 1701mb ~ 1.6G. Whats the problem?

@onomatopellan
Copy link

limiting wsl ram usage to 2GB but vmmem still consuming lot of RAM even though it didnt show in task manager.

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.

@fdc2005
Copy link

fdc2005 commented Jun 21, 2024

I am having a similar problem with wsl 2 and Docker. After a few days of running smoothly, vmmem takes up 90-100% of CPU and remains at this level, even after I shutdown docker desktop, and issue multiple "wsl --shutdown" commands. Note that this is a laptop - could it be related to putting the laptop to sleep occasionally?

Here is what I see:
image

I have tried to out-wait it to see what happens, but in each case I've become frustrated after 15-20 minutes and end up rebooting to fix the problem. Here is what I see after the reboot - I don't know why "docker-desktop-data" and "docker-desktop" appear now in the list, but didn't prior to the reboot:
image

@swebs
Copy link

swebs commented Jun 21, 2024

There is a different issue regarding high CPU use: #8529

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wsl2 Issue/feature applies to WSL 2
Projects
None yet
Development

No branches or pull requests