How to solve WSL memory 100% occupancy problem.
There is a resource-related problem with WSL of MS Windows OS. Not only does it occupy 100% of the memory, but it seems to continue to demand more than that. Because of this, the PC falls into a memory depletion state.
This problem seems to be especially experienced by people who use docker-wsl, and there are many related reports.
There is no solution at this time, and it can be mitigated by limiting memory usage through settings as follows.
The method is as follows.
c:\Users\<User Name> or c:\User\<User Name>
Create a .wslconfig file in the above path and add the settings below. You have to add "[wsl2]" as well.
[wsl2]
kernel=C:\\temp\\myCustomKernel
memory=4GB # Limits VM memory in WSL 2 to 4 GB
processors=2 # Makes the WSL 2 VM use two virtual processors
You can also write a swap file by adding swap=4GB here.
Microsoft recommends setting it to a smaller one between 50% of the total memory and 8GB.