Configure Windows WSL
Matthias Baldi, 10/17/2020
en
Since the new version of WSL is out (2.0) you can do much more things with it and it got an important feature: Containers. I used Docker Desktop asap with the WSL but I detected soon an issue which I did not have with the old versions. With Docker Desktop and the “classic” HyperV VM it was possible to adjust the memory and CPU pretty easy, because it was a VM. In the new setup this is not possible over the Docker Desktop settings, so you have to find an other way, because the “Vmmem” process will use a lot of memory when you start containers. And it will not give it back… until you restart the WSL service. And this can hurt pretty hard on 8GB-16GB devices.
I found out the the WSL 2.0 possibly has some issues with the memory consumption - not only with containers. But even if there are bugs, you have a possibility to configure the limits.
You can create a configuration file:
notepad %UserProfile%\.wslconfig
Then you can fill the following configuration:
[wsl2]
memory=2GB
processors=2
swap=0
localhostForwarding=true
The first three configuration entries are clear. There you can adjust the memory and cpu consumption and you can configure if the WSL should start swapping whe it got not enough memory. The last entry is to configure localhost connections. It has nothing to do with performance or limiting the WSL.
Hope this information helps to improve your notebook/pc speed.
Happy coding, happy Docker 🐳