Change the Default Memory Limit of WSL2
I was running a Go program in WSL2, and it stalled at 12GB of memory usage (my machine has 24GB total). No error, no panic, just silence.
~ Run go test ./
=== RUN TestDBMetaphysicsProblem
--- PASS: TestDBMetaphysicsProblem (10.94s)
=== RUN TestDBSequentialOP
FAIL github.com/therainisme/mlsm 182.824s
Turns out WSL2 caps memory at half of your Windows memory by default. Source: https://learn.microsoft.com/en-us/windows/wsl/wsl-config#main-wsl-settings
Configure the Memory Limit
Create a .wslconfig file in your user directory (usually C:\users\YourUsername) with the following content:
[wsl2]
memory=16GB
After saving, restart WSL2 with wsl --shutdown. Then run free inside WSL2 to verify:
~ free
total used free shared buff/cache available
Mem: 16381032 909836 14426152 980 1045044 15175252
Swap: 4194304 87336 4106968
Memory is now 16GB. The Go program that eats memory can finally finish running.