Ask HN: WSL2 users how you are handling the RAM usage?
It's so annoying really no matter the ram you give it just eats all of it, when i run my projects locally hot reloading becomes so so slow. I dont know why microsoft recommends it and it unbelievebly unusable. Also the problem has been around since the creation of wsl why microsoft didnt find a solution yet ?
13 comments
[ 3.2 ms ] story [ 46.2 ms ] threadI really wish I could just run proper Linux on the metal. Docker under emulation is such a disaster! I don't understand how it's the norm.
I know some people think WSL2 is the bee’s knees but I just tried to install it on a brand new ‘gaming computer’ with 64MB RAM and Windows 11 and… it didn’t work at all.
It's quite possible that a normal distro under some other hypervisor would work much better for me.
Not too surprising to be honest
I know people who swear WSL2 was an improvement over WSL1 but I'd say WSL1 worked 100% of the time when I tried it and I've never had WSL2 work correctly. Contrast that to booting up a VM in Hyper-V where it might take me two tries to make a perfect install.
By design it will end up using all the allocated ram for caches and linux programs.
If you really need to free ram for windows apps you can flush caches by running below as root
echo 1 >> /proc/sys/vm/drop_caches
As far as I know, the high memory usage of WSL2 is due Linux using as much spare RAM as possible for caching and WSL2 having to allocate memory for this cache. Both Linux and Windows memory ballooning under KVM/QEMU manages dynamically manage memory and work around memory caching.
I suspect the issue with WSL2 allocated memory being quickly consumed by cache could be currently a limitation of the Hyper-V hypervisor or the WSL2 kernel.
I just set it to 12 GB max, since I have 32 GBs of RAM, and it works just great.