This guide demonstrates how to limit WSL memory usage by configuring the .wslconfig
file, restarting the WSL service, and verifying the memory allocation before and after the change.
.wslconfig
file with the following configuration [wsl2]
memory=4GB
Restart-Service LxssManager
free --human
total used free shared buff/cache available
Mem: 7.6Gi 1.7Gi 3.6Gi 0.0Ki 2.3Gi 5.7Gi
Swap: 2.0Gi 1.0Mi 2.0Gi
free --human
total used free shared buff/cache available
Mem: 3.8Gi 105Mi 3.6Gi 0.0Ki 168Mi 3.5Gi
Swap: 1.0Gi 0B 1.0Gi