Hacker News new | ask | show | jobs
by sedatk 2042 days ago
I agree with the sentiment but, some scenarios have become orders of magnitude more complicated on WSL2 like connecting to a daemon on Windows or vice versa. I understand clear cut security boundaries and separate network interfaces, but it's extremely hard to get them running smoothly now. Everything was on localhost on WSL1.

Memory usage has also gone bonkers with the VM approach, causing unnecessary overhead for casual users who don't need performance.

7 comments

> some scenarios have become orders of magnitude more complicated on WSL2 like connecting to a daemon on Windows or vice versa

This is about my only issue with WSL2, but it's a big one. Perhaps worse than this being a problem is that Microsoft don't seem to be providing any solutions - there are various GitHub issues about it, with non-Microsoft ransoms being the ones providing workarounds (but these depend on your environment - I haven't found any way to get this working myself!).

WSL1 was very ambitious. AFAIK, the main reason for shelving it's approach was filesystem performance. While it was indeed slower than native/VM, I personally never found it troublesome outside of artificial benchmarking. For the vast majority of use cases, WSL1 worked well, with Docker being the only real thing missing, IMO.

Running an npm install for an app of moderate complexity on WSL1 was such a painful experience that it turned me off of using the service for work dev entirely. Now with WSL2 it's much better, and I use it daily to the point where I have done away with my dual boot. (I still keep around a Linux notebook for edge cases.)

Obviously this is only re: fs perf, I can't speak to your other issues which do seem quite challenging. But I can definitely understand why they would have seen fs perf as a priority.

FYI to any WSL2 users, in it's migrated configuration the WSL VM can request as much RAM as it needs, but has no means to free this back. There's an option to use .wslconfig to specify a limit.

https://github.com/microsoft/WSL/issues/4166

My problem was that the ram was never released back when I didn't use it anymore and it started to kill windows itself. Had to hard limit it from the link you provided.
Does "wsl --shutdown" work?
Yes
WSL1 hasn't gone away for those who prefer it. But we're talking about an extra gigabyte. It's still cheaper than a full VM.
It's even cheaper to only use what you need with msys2!

bash inside mintty gives me all I need, with minimal overhead.

Eventually, I'd like to see bash inside Windows Terminal made easily available - complete that with busybox, and you cover 90% of the Linux usecases without having to download anything (a bit like how starting Terminal.app offers most of what you need on MacOS)

Add an option to install packages using msys2/pacman for the power users, and I believe most people would not waste time (or disk space, or ram) playing with WSL1 or WSL2 just to run the one thing they may need.

What makes you think the overhead between Cygwin/msys2 and WSL 1 would really be so great? They are both just translation layers after all.
WSL1 tries to do too much. WSL2 tries to do even more.

msys2 mostly cares about running your textmode software.

For example, someone talked about processes. Here's all that I see in msys2:

# ps xwau

      PID    PPID    PGID     WINPID   TTY         UID    STIME COMMAND

      480     479     480      18796  pty1      197611 14:13:13 /usr/bin/bash

      479       1     479      16872  ?         197611 14:13:12 /usr/bin/mintty

     1118     480    1118      16496  pty1      197611 17:00:32 /usr/bin/ps
Most of the time, I don't need to access Windows processes - and if I do, data can be exchanged through a file.
WSL1 also doesn't show windows proceses in 'ps', only the WSL processes. For example:

    shawnz@ShawnsPC:/mnt/c/Users/shawn$ ps xwau
    USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
    root         1  0.0  0.0   8936   184 ?        Ssl  Nov17   0:00 /init
    root         6  0.0  0.0   8936    96 tty1     Ss   Nov17   0:00 /init
    shawnz       7  0.0  0.0  18588  2708 tty1     S    Nov17   0:00 -bash
    shawnz     252  0.0  0.0  18880  1984 tty1     R    18:04   0:00 ps xwau
But in your example, I can already see you have a init system and multiple users - neither of which will be needed in most cases.
main draw for wsl2 for my team was IO performance. how is git on huge projects under msys2?
It's clear that they are not enthusiastic about delivering new features to WSL1. Consider how WSL2 now exclusively features CUDA support, Wayland support, loop mounts, Docker, etc.
Docker support is precisely the sort of feature that would have required significantly more work to support in WSL1 than WSL2.
Yes, admittedly loop mounts and Docker were an easy add for WSL 2 and would have been significantly more complicated for WSL 1.
Docker can also make use of Windows containers, and that is probably easier when everything is running on top of Hyper-V, as type 1 hypervisor.
Docker works fine with WSL1, I don't think I can use WSL2 at work as we're waiting on the next LTS version of Windows.
Docker can't be hosted on WSL1. You can use the Docker client on WSL1 to communicate with a Docker host running on WSL2 or Hyper-V, though (which is how Docker Desktop works)
I think WSL1 is there for transitional purposes and will be thrown away eventually. It was already incomplete, it didn't support forwarding any ICMP packets other than ping, so traceroute didn't work for example. I don't expect it to stay as an option for long.
At work we develop on Windows virtual machines, and WSL1 won't run on a VM. Fortunately WSL2 does, so at least I can enjoy Linux tooling I sorely missed.
Interesting, I would expect the opposite problem since WSL1 doesn't use virtualisation in any way. Do you have more details about the error you experienced?
Unfortunately I tried WSL1, didn't work, and left it at that for months. When WSL2 was out, it just worked and I had forgotten by then what kind of error WSL1 gave me.

I can only recall it was a dialog box, not a crash, and that it had to do about virtualization.

In WSL 2 the nameserver is the Windows host OS. That's how you get the IP of the host if that's what you're talking about.

    export WINHOST=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}')
Because the Linux VM in WSL 2 is a "different" computer, mostly, according to Windows, there may be firewall trouble, I suppose.
Windows itself is a different computer, because Hyper-V is a type 1 hypervisor.
> connecting to a daemon in Windows

That doesn't seem impossible to implement. Can't you connect to some port on your gateway to access the host? Even if you currently can't, it still seems pretty easy to implement in the grand scale of things, than trying to make WSL1 work.

I'd imagine it is in some todo list somewhere in Microsoft

I apologize if I'm missing something here, but if casual users don't care about performance, what's the overhead here?
Example: on WSL1 I could cheaply run Linux CS labwork including valgrind checks etc. - with less resources and much snappier than with VirtualBox VMs

I'm not confident about diving into WSL2.

I've had surprisingly good results running that sort of thing under WSL2. Pure CPU workloads actually work pretty well, and in my experience valgrind has mostly been CPU intensive?
IIRC WSL 2 use 50% of your memory in Windows, or 8GB (whichever is smaller) by default.
I have 32 GB. Hardware is cheap for Windows. imo That's one of its main perks vs Apple
Is that an upper bound? My Ubuntu 20.04 console sessions on WSL2 consume a couple tens of Mb.
The individual process inside the vm might not consume much, but the vm itself might reserve some GBs of memory. Try looking at how much memory `vmmem` process used in task manager.
Also:

https://www.reddit.com/r/bashonubuntuonwindows/comments/d8x7...

"So, I was copying a 8GB file to my Debian home folder using Windows Explorer, via $wsl network. The copy process made my CPU's fan runs like a jetplane, and it stop copying when at 95%, then I opened up Task Manager and saw this.

even after it finish copying, Vmmem process still hold 13GB RAM and not release any. Why? I have to shutdown WSL after copy a big file?

Answer:

Very normal but annoying issue. ... The only solutions are:

a) a kernel change by MS to limit the amount WSL2 can cache b) disable to caching ( nocache ) c) Put a limit on the WSL hyper-v VM

Not sure what or how MS will try to solve this issue... WSL1 did not have this issue, because it shared the main system memory, because it was just a layer around the NT kernel."

Check the other comments on the link? Solution c) is already there?
I can't find that process in my system, nor a significant difference in physical RAM usage before and after starting Ubuntu in WSL2. Digging a little it seems like memory is dynamically allocated and reclaimed when freed. I'm not defending WSL2, just trying to understand how is it supposed to consume 8GB of my 16Gb of RAM.

https://devblogs.microsoft.com/commandline/memory-reclaim-in...

Look for a 'vmmemory' entry in your process list, it'll likely be in the hundreds of megs, if not a gig or so.
I don't have that process while running WSL2 in my machine. I have vm-agent and vm-agent-daemon, but I'm using a virtual desktop, so this might or not be related to WSL2. Both of these processes consume less than 10 Mb combined. In my other comment [0] I referenced a link from Microsoft that says RAM is dynamically allocated and reclaimed when freed.

0. https://news.ycombinator.com/item?id=25161769

This hasn't been my experience, but sure, even if memory consumption is higher, for most applications where Windows users are going to use WSL, additional memory is incredibly cheap compared to the dev overhead of trying to boot into a Linux environment and switching back and forth.
Memory and cpu limits are configurable for wsl. You can cap your vm to whatever portion of your machine that you want.