Limiting WSL 2 RAM And CPU - gecko-8/devwiki GitHub Wiki
- At the root of your C: drive (or whatever drive Windows boots from) add a .wslconfig file.
- Edit the file to contain the following (setting whatever RAM and CPU limits you want):
[wsl2] memory=4GB # Limits VM memory in WSL 2 to 4 GB processors=2 # Makes the WSL 2 VM use two virtual processors
- Restart WSL from an admin PowerShell with the command:
NOTE: If running Docker, you will likely get an error asking to restart Docker.Restart-Service LxssManager
Sources
https://medium.com/@lewwybogus/how-to-stop-wsl2-from-hogging-all-your-ram-with-docker-d7846b9c5b37