How can I reduce the consumption of the `vmmem` process?

229,269

Solution 1

Daniiel B is on the money. To turn off Vmmem simply go into Powershell or whatever terminal you like to use under admin rights and enter the command wsl --shutdown, when your done with playing in wsl1/2.

Solution 2

I edit the WSL config to limit the memory usage as mentioned here.

# turn off all wsl instances such as docker-desktop
wsl --shutdown
notepad "$env:USERPROFILE/.wslconfig"

Set the values you want for CPU core and Memory:

[wsl2]
memory=3GB   # Limits VM memory in WSL 2 up to 3GB
processors=2 # Makes the WSL 2 VM use two virtual processors

Solution 3

vmmem even after docker has shut down, will run for a few seconds up to 1 minute before completely shutting off. So try shutting down your containers and docker and it should disappear soon enough.

The accepted answer talks about shutting down WSL (the windows subsystem for Linux) which makes sense if you actually opened and installed a distro, but since you mentioned about Docker, i'm guessing your vmmem is just showing the usage of docker containers only.

Here's a nice explanation from a trustworthy individual : https://devblogs.microsoft.com/oldnewthing/20180717-00/?p=99265

Edit:

Considering the main question was about how to reduce the consumption of RAM, and since you're using docker; take a look at : Docker Resource Contraints

More specifically the --memory=2g parameter, you can limit the RAM a container will use, and in turn vmmem itself will use less RAM as well.

Solution 4

Restart WSL2, by running the following command in PowerShell right click and run in Administrator mode:

Restart-Service LxssManager

Solution 5

The memory is being consumed by Linux to cache files. It can be seen in the buff/cache section of free command. To drop the cache, simply run echo 3 | sudo tee /proc/sys/vm/drop_caches.

Share:
229,269
CiaranWelsh
Author by

CiaranWelsh

Updated on September 18, 2022

Comments

  • CiaranWelsh
    CiaranWelsh almost 2 years

    I installed docker on windows home which uses WSL2 as a backend. However, since doing this a process called vmmem seems to be consistently consuming a lot of computational resources. I ran docker stop $(docker ps -aq) to kill all running containers (there were 12 - oops) which has improved the issue significantly. However, even after closing docker down vmmem is still taking ~1.5 - 2Gb of ram and ~20% CPU. Since there are no longer any containers running, shouldn't the resource consumption of vmmem be minimal? How can I reduce the consumption of the vmmem process?

  • Joey Baruch
    Joey Baruch over 3 years
    this doesn't answer the question - I need my dockers to run, but I just want to bound the RAM consumption
  • CiaranWelsh
    CiaranWelsh over 3 years
    Odd, I thought docker on windows only worked with WSL.
  • Bill Tarbell
    Bill Tarbell over 3 years
    I'm not an expert on the matter, but i did verify that Windows Subsystem for Linux is not checked in my Windows Features list.
  • dhasson
    dhasson over 3 years
    @CiaranWelsh it only works with WSL for Windows 10 Home, but for other systems like Windows 10 Pro or Enterprise it doesn't need WSL: docs.docker.com/docker-for-windows/install
  • Bill Tarbell
    Bill Tarbell over 3 years
    That makes sense.. I'm on Win10 Enterprise.
  • luis.espinal
    luis.espinal over 3 years
    That pretty much answer your question. For as long as you use docker (or anything using WLS2 as the backend), you'll see vmmem consuming your RAM. If you run your dockers, vmmem will be there.
  • Tonatio
    Tonatio about 3 years
    This works. Close Docker Desktop and after a minute, vmmem disappears from Task Manager.
  • Lorenzo
    Lorenzo about 3 years
    @JoeyBaruch Take a look at : docs.docker.com/config/containers/resource_constraints Specifically the --memory=2g parameter, since you're using docker you can limit the RAM it will use when you run it through WSL, and in turn vmmem itself will use less RAM as well since it just represents the total memory used by your containers; and in my parameter example, you'd restrict the container to 2GB of RAM usage only
  • Bob Stein
    Bob Stein almost 3 years
    Similarly, a minute after closing all WSL terminals, vmmem goes away
  • Hassan Faghihi
    Hassan Faghihi almost 3 years
    Docker generate error over unexpected shutdown, is there any better way to turn it off?
  • T.Todua
    T.Todua over 2 years
    Should be accepted answer.
  • Diego Lima
    Diego Lima over 2 years
    this is it. combining this cache clearing command with limiting WSL memory usage, I'm happy
  • Community
    Community about 2 years
    As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
  • Admin
    Admin about 2 years
    Or wsl --restart