Last Updated on 2021-08-31 by Clay
WSL (Windows subsystem for Linux) is a Linux system on Windows, It's very suitable for those who use Windows as a daily use device but need to use Linux occasionally.
WSL-2 will be released in November 2020 and will be added to the official version of Windows, but it is already possible to upgrade the Windows version in the developer's plan and use early.
The differences between WSL and WSL-2 should be as follows according to the official announcement:
Functions | WSL 1 | WSL2 |
---|---|---|
Integration between Windows and Linux | O | O |
Fast boot time | O | O |
Low resource usage | O | O |
Run with the latest version of VMware and VirtualBox | O | O |
Managed VM | X | O |
Complete Linux core | X | O |
Complete system call compatibility | X | O |
Performance between OS file systems | O | X |
One of the most amazing is the complete Linux kernel and system call compatibility. I remember that when I used WSL, there were indeed some instructions and environment that couldn't run in WSL.
Now it seems that I am afraid that the original problems no longer exist.
Of course, WSL-2 does not completely beat WSL. It is said that the cross-system performance is relatively poor (?) But I am not sure what the means.
The topic is far off, the most important thing is that when I ran the program in the WSL-2 environment today, the memory suddenly overflow (Out Of Memory, OOM). I checked at it with htop
command and found that the memory was only 7.77 GB.
This is a very strange problem, because there should be 128 GB of memory on my device.
Write configuration file to allocate memory
In advance, I have only tested the following solutions in WSL-2 to be OK, but I am not sure about WSL.
First, close all open WSL-2 and open CMD, enter the following command:
wsl --shutdown
Then, we can solve this problem by writing a configuration file.
Put the following settings into C:\Users\<your_user_name>\.wslconfig. Remember DON'T ADD THE EXTENSION AT THE END.
The settings in .wslconfig are as follows:
[wsl2]
memory=120GB # Limits VM memory in WSL 2 to 128 GB
Save and quit, restart WSL-2, you can use htop
command to check, it should reflect the whole memory for you.