DEV Community

Cover image for WSL Tepes: The CPU/Memory vampire
Camilo Martinez
Camilo Martinez

Posted on • Updated on

WSL Tepes: The CPU/Memory vampire

Surely, you have ever seen the Chrome and Android Studio memes about the huge consumption of ram and CPU.

Image description

Well... I think we have a new contender for the crown.

The King is dead, hail the new king.
Your majesty: WSL! 👑

That is because have a known issue "WSL 2 consumes massive amounts of RAM and doesn't return it" and can't be solved until today.

not cool


It is not a definitive solution, but we can setup WSL with some advanced configurations to limit his resources.

All next steep need to be done on PowerShell (Windows side).

First, we need to close all terminals that are using WSL, and then shut it down to avoid data corruption running the wsl --shutdown command.

Create a .wslconfig file under the windows user profile path.

New-Item -Path '.wslconfig' -ItemType File
Enter fullscreen mode Exit fullscreen mode

Open this file with VSCode (or any editor that you like)

code .wslconfig
Enter fullscreen mode Exit fullscreen mode

And set limits for the max amount of resources that can take (according to you needs). For example:

# Settings apply across all Linux distros running on WSL 2

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

# Sets the VM to use two virtual processors

# Sets amount of swap storage space to 8GB, default is 25% of available RAM

# Sets swapfile path location, default is %USERPROFILE%\AppData\Local\Temp\swap.vhdx

# Turn off default connection to bind WSL 2 localhost to Windows localhost
Enter fullscreen mode Exit fullscreen mode

For more WSL advanced configuration check the documentation.

Save the file and restart WSL running wsl command.


It will still consume the entire 4GBs regardless of Linux memory usage and only 2 virtual processors, but at least it will stop growing more than that.


If you are still having issues with WSL, you can use Git Bash. It's not a "real" Linux distribution like WSL, but it's a good alternative to emulate an Unixish environment inside windows.

That’s All Folks!
Happy Coding


Top comments (0)