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 · 292 comments
Open

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

LordMonoxide opened this issue Jun 17, 2019 · 292 comments
Assignees
Labels

Comments

@LordMonoxide
Copy link

@LordMonoxide 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 Drakota commented Jun 17, 2019

Same here with Docker running on Ubuntu 18.04
image

@benhillis
Copy link
Member

@benhillis benhillis commented Jun 17, 2019

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

@mithunshanbhag
Copy link

@mithunshanbhag 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 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 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 liyo commented Aug 1, 2019

Same issue on Win build 18950

@zachChilders
Copy link

@zachChilders zachChilders commented Aug 13, 2019

@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

@benhillis benhillis commented Aug 13, 2019

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

@avafloww
Copy link

@avafloww avafloww commented Aug 19, 2019

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

@david-dumke david-dumke commented Aug 22, 2019

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

@rob-solana rob-solana commented Aug 22, 2019

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

@mbc07
Copy link

@mbc07 mbc07 commented Aug 22, 2019

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

@rob-solana
Copy link

@rob-solana rob-solana commented Aug 22, 2019

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

@Beretta1979
Copy link

@Beretta1979 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?

@wmulligan87
Copy link

@wmulligan87 wmulligan87 commented Aug 28, 2019

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

@rob-solana rob-solana commented Aug 29, 2019

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

@benhillis benhillis commented Aug 29, 2019

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

@fabienheureux
Copy link

@fabienheureux fabienheureux commented Aug 29, 2019

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

@fabienheureux
Copy link

@fabienheureux fabienheureux commented Aug 29, 2019

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

@weberdominik weberdominik commented Aug 29, 2019

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

@benhillis benhillis commented Aug 29, 2019

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

@apostolos apostolos commented Aug 30, 2019

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.

@gund
Copy link

@gund gund commented Jul 7, 2020

So many useless comments in just one day...

Maintainers please lock this thread as a lot of people watching this issue and waiting for progress updates but all we get is yet another "me too" or just trolling!

@romitzz1
Copy link

@romitzz1 romitzz1 commented Jul 7, 2020

Before the thread gets locked again. I would love to hear more about the orginal idea of a fix #4166 (comment) vs the one that is in a PR.

It sounds like the PR fix would solve many of the issues in this thread, but won't do much for those of us with larger environments that would best benefit from everything being dynamic.

In the meantime, I've been using the drop caches trick when needed, and getting by.

@microsoft microsoft deleted a comment from megapro17 Jul 7, 2020
@microsoft microsoft deleted a comment from megapro17 Jul 7, 2020
@benhillis
Copy link
Member

@benhillis benhillis commented Jul 7, 2020

@megapro17 - this is your first and last warning.

@microsoft microsoft locked as too heated and limited conversation to collaborators Jul 7, 2020
@benhillis
Copy link
Member

@benhillis benhillis commented Jul 7, 2020

@romitzz1 - the former is a much larger change, the PR I reference is about more conservative defaults which will be in Insider builds soon.

@craigloewen-msft
Copy link
Member

@craigloewen-msft craigloewen-msft commented Jul 22, 2020

In build 20175 we've changed the default memory scheme in WSL 2 to use 50% of your memory in Windows, or 8GB (whichever is smaller). This change should help address some of the immediate pain points, and we are still working on improving our overall story with regards to cached files in memory. We'll be looking forwards to hearing your feedback!

@microsoft microsoft unlocked this conversation Jul 22, 2020
@chiqui3d
Copy link

@chiqui3d chiqui3d commented Jul 22, 2020

One thing that is helping me too, besides trying all the other things I've seen in this thread, is stopping all the containers I'm not using at the moment from other projects (docker-compose down -v), it's a pain in the ass, but it helps while they fix all this memory mess.

Another option is to buy a computer from NASA to be able to use WSL2 + Docker + Chrome

@LeandreBl
Copy link

@LeandreBl LeandreBl commented Jul 22, 2020

For my part I restart the WSL service, as stopping the containers still keeps more than 2GB of memory most of the time.

@stjeffrey
Copy link

@stjeffrey stjeffrey commented Jul 22, 2020

In build 20175 we've changed the default memory scheme in WSL 2 to use 50% of your memory in Windows, or 8GB (whichever is smaller). This change should help address some of the immediate pain points, and we are still working on improving our overall story with regards to cached files in memory. We'll be looking forwards to hearing your feedback!

Will docker containers backed by WSL be running with the memory restriction or are the containers using memory outside what is used by WSL?

@craigloewen-msft
Copy link
Member

@craigloewen-msft craigloewen-msft commented Jul 22, 2020

In build 20175 we've changed the default memory scheme in WSL 2 to use 50% of your memory in Windows, or 8GB (whichever is smaller). This change should help address some of the immediate pain points, and we are still working on improving our overall story with regards to cached files in memory. We'll be looking forwards to hearing your feedback!

Will docker containers backed by WSL be running with the memory restriction or are the containers using memory outside what is used by WSL?

This change affects the total memory available to your WSL 2 VM. We changed it from 80% of your Windows memory to 50% by default. So on my 16GB machine the total memory I see when I run free -h went from ~13GB to ~8GB. This can also be overriden to be any value you like using the .wslconfig file.

@robhaswell
Copy link

@robhaswell robhaswell commented Jul 22, 2020

Will docker containers backed by WSL be running with the memory restriction or are the containers using memory outside what is used by WSL?

The memory is being consumed by the guest OS's filesystem cache, not the Docker containers. So yes memory is being used beyond what the containers have allocated to them.

@mark-i-m
Copy link

@mark-i-m mark-i-m commented Jul 22, 2020

Sorry if this has come up before (it's a long thread, and I haven't read all of it). Have y'all considered adding some sort of "balloon driver" to allow reclaiming memory from the VM?

EDIT: to give a bit more context, I'm ok with WSL taking all of my memory as long as it gives it back later.

@darkRaspberry
Copy link

@darkRaspberry darkRaspberry commented Jul 23, 2020

Thanks for that mod of 50%. Atleast my explorer don't crash.

@mati865
Copy link

@mati865 mati865 commented Jul 23, 2020

@darkRaspberry it was said hundreds times on WSL bugtracker. Linux considers free RAM as useless and it doesn't like useless memory so it's using it as a cache for disk: https://www.linuxatemyram.com/

You can drop current cache this way: https://www.tecmint.com/clear-ram-memory-cache-buffer-and-swap-space-on-linux/

@swebs
Copy link

@swebs swebs commented Jul 23, 2020

Apologies if this has already been said, but some discussion of this issue and instructions for using the .wslconfig file to adjust max memory usage should be added to the WSL docs, probably under troubleshooting, maybe FAQs. I just had a look here and didn't notice mention of this:
https://docs.microsoft.com/en-us/windows/wsl/

@manuelnucci
Copy link

@manuelnucci manuelnucci commented Jul 23, 2020

Here are the settings that can be customized: https://docs.microsoft.com/en-us/windows/wsl/wsl-config#configure-global-options-with-wslconfig. I'm struggling right now with the memory key because I would like to specify a percentaje instead of a raw value in GB. It isn't well described in the docs, if anyone can help me, really appreciated.

@benhillis
Copy link
Member

@benhillis benhillis commented Jul 23, 2020

@manuelnucci - only raw values are supported.

@darkRaspberry
Copy link

@darkRaspberry darkRaspberry commented Jul 24, 2020

This change affects the total memory available to your WSL 2 VM. We changed it from 80% of your Windows memory to 50% by default. So on my 16GB machine the total memory I see when I run free -h went from ~13GB to ~8GB. This can also be overriden to be any value you like using the .wslconfig file.

This idea of .wslconfig is awesome. i just limited it to 512 MB and it work nice on any node or python. docker command.
now i can use chrome with wsl
Thats seriouslly nice. 👍🏻

@robhaswell
Copy link

@robhaswell robhaswell commented Jul 24, 2020

I feel like we have reached the end of meaningful discussion on this thread again. The most recent comments here nicely explain the workaround to future explorers, I think this thread should be locked until there is more news on the more complete solution.

@benhillis
Copy link
Member

@benhillis benhillis commented Jul 24, 2020

Agreed. We are continuing to work on a better solution.

@sarim
Copy link

@sarim sarim commented Jul 24, 2020

@benhillis what would happen if wsl mounts root with dax flag right now? I tried adding it to /etc/fstab, but wsl doesn't seem to apply flags from fstab...

@benhillis
Copy link
Member

@benhillis benhillis commented Jul 24, 2020

@sarim - I wish it were that easy...

@microsoft microsoft locked as spam and limited conversation to collaborators Jul 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet