The vmmem
process associated with Windows Subsystem for Linux (WSL) manages memory allocation for your WSL instances, and sometimes it can reserve more memory than necessary.
Here’s how to tackle high vmmem memory usage:
1. Identify Running WSL Instances:
-
Let’s list all your running WSL distributions along with their version and memory usage.
-
Over a Command Prompt or PowerShell window, type the following command and press Enter:
wsl --list --verbose
OR
wsl -l -v
2. Shut Down Unneeded WSL Distributions:
-
If you find distributions you’re not actively using, terminate them.
-
Type the following command, replacing
{distro}
with the actual name of the distribution you want to shut down:wsl --terminate [distro_name]
OR
wsl -t [distro_name]
3. Optionally, Shut Down All WSL Instances:
-
If you want to shut down all WSL / WSL 2 instances at once, you can use the following command:
wsl --shutdown
4. Shut Down Docker (if applicable):
-
If you’re using Docker within your WSL 2 environment, you might be interested in this.
-
Stopping Docker or a Docker container does not automatically stop the associated WSL (Windows Subsystem for Linux) instance. The WSL instance will continue running even if the Docker container is stopped.
-
You can use the following command to stop all running containers without removing them:
docker compose stop
-
You can use the following command to start them again:
docker compose start
5. (Optional) Adjust WSL Memory Allocation:
-
Docker Desktop for Windows integrates seamlessly with WSL 2. Ensure Docker Desktop is set to use the WSL 2 backend by navigating to Settings > General and enabling the Use the WSL 2 based engine option.
-
Manage resources by configuring settings in Docker Desktop such as CPU, memory, and disk space allocated to WSL 2.
-
For advanced users, regardless of Docker being used, you can further fine-tune WSL memory allocation by editing the
.wslconfig
file. This involves setting a specific memory limit for your WSL instances. However, proceed with caution as an incorrect configuration can lead to performance issues. Please refer to the official documentation here.
Shutting down WSL instances you’re not actively using is the quickest way to free up resources.
Additional Resources:
- Microsoft Docs on WSL: https://learn.microsoft.com/en-us/windows/wsl/
- Blog posts referenced in this article: