WSL2 stands for Windows Subsytem for Linux, version 2. It lets one use a Linux environment on a Windows machine without the burden of using double boot or explicit virtual machine setup.
This is a great tool, but one might experience very low performance under some situations. The good news is that it is probably due to some obscure WSL2 setup or usage rule, but it is not always much documented or easy to find the solutions.
Here are two such classical limitations and their workaround:
- file access performance: be sure to use the native WSL2 Linux filesystem, not the mounted Windows filesystem. For example, when starting an Ubuntu 22.04 LTS subsystem, your default directory looks like /mnt/c/Users/login. It corresponds to your Windows user directory, thus on the Windows filesystem. Use the Linux command cd to use your Linux home directory, located on the Linux filesystem. It often looks like /home/login. With an intensive file IO Python deep learning training, I experienced 10-50 times speed increase.
- available memory: by default, WSL2 is limited to 50% of the hosts machine’s RAM, lower than the amount that was authorized with previous versions. If this is not sufficient for an application, one may want to increase the maximum RAM available to WSL2.