Ask HN: WSL2 users how you are handling the RAM usage?

8 points by izwasm ↗ HN
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 ] thread
Yeah there seems to be a memory leak in Hyper-V somewhere. Spinning up Docker containers on-demand (like for a local GitHub runner, for example) instantly gobbles up the whole allotment and, on defaults, makes my 32GB work computer totally unusable.

I 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.

Whenever I’ve wanted to run Docker on a Windows machine I just install Linux under virtualization and then install Docker under Linux. It works, which is more than I can say for the alternatives.

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.

WSL2 is the only VM I can run at work without seeking some kind of special permission, unfortunately.

It's quite possible that a normal distro under some other hypervisor would work much better for me.

> 64MB RAM and Windows 11 and… it didn’t work at all

Not too surprising to be honest

It's weird.

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.

I swear it's improvement. Switched from wsl1 long time ago - 3 or 4 years I guess. Using Wsl1 for very specific task of doing socket forwarding from host OS, the rest happens in WSL2. Simple thing like using namespaces or not so simple like mounting loopback file with BTRFS not possible in WSL1 by design. Not even mentioning recent systemd support.
I've read a github thread about the issue the maintainer said that a change should be made in the linux kernel itself.
What's your specific use case? I haven't noticed any problems, but my usage is pretty light, with python scripts and some docker containers.
What do you mean by "light" how much percent of RAM does it consume according to the total you gave it in the .wslconfig ? It must be around 100%, cause there is a bug, and actually wether i use docker or not its still high, i've tried to contribute to cal.com, i've ran the clone locally and hot reloading has been sooo slow. I hope they find a fix so soon
You specify the wsl2 ram limit in the config file.

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

By default WSL2 should only be using 8GB ram or 50%, which ever is lower.

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 believe there was a configuration file for that.

I just set it to 12 GB max, since I have 32 GBs of RAM, and it works just great.