Using WSL

WSL files in Windows:

\\wsl$

Reduce RAM usage by WSL2

WSL2 can consume huge amounts of RAM and not releasing it, even if it does not execute any task. In order to limit memory consumption by WSL2:

  • create a file with name .wslconfig in your user’s home directory
  • add the following content to the .wslconfig file:
[wsl2]
memory=10Gb
swap=0

memory=10Gb means that 10Gb of RAM are assigned to the WSL2 VM. WSL2 will not use more than that. swap=0 means that the swap file is not used.

Reference: WSL 2 Settings

With the setting above, WSL2 can still use almost 10Gb of RAM with no active tasks, but never more than 10Gb.

If you run some RAM consuming tasks in WSL2, for example, you test some functionality in the environment created by a set of docker containers, you may experience Out of memory errors, if you use all 10Gb of memory allocated to WSL2.