Window Subsystem Linux v2 (WSL2) is an iteration of the VM created by Microsoft, from Hyper-V to WSL and this the second generation of WSL. If it’s your first time accessing WSL2, it automatically provides you with the default setup which doesn’t provide any limits accessing your full workstation resources (CPU, RAM and other HDD). It means that if you have 8 cores CPU and 16Gb memory, it will use all that up. The problem with it is sometimes it affects your host computer, and it gets slow. So, to solve that problem we try to limit the resource consumption of WSL2.
Limit WSL Resource Consumption
On your profile directory
%USERPROFILE% create a new file named
.wslconfig. Set its content to the following:
[wsl2] memory=8GB processors=8
Change the settings based on your workstation capability, and this is what works for me.
Next, open up a powershell terminal in administrator mode and restart the LxssManager as this manages WSL2.
Get-Service LxssManager | Restart-Service
You could also use the
wsl --shutdown method to restart WSL. Check if the
vmmem process still consumes beyond its limit.
If the changes are still not reflecting, try to restart your machine and also restart Docker Desktop.