WSL2 when setup doesn't provide any limits. 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.
On your profile directory
%USERPROFILE% create a new file named
.wslconfig. Set it's content to the following:
Change the settings base 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.
You could also use the
wsl --shutdown method to restart WSL. Check if the
vmmem process still consumes beyond its limit.
If the changes still not reflecting, try to restart your machine and also restart Docker Desktop.