Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

If you thought electron apps used a lot of memory, this thing will surprise you [0]:

With WSL2, apps will now use either 50% or 8GB of your available memory.

Happy coding!

[0]: https://github.com/microsoft/WSL/issues/4166



    PS C:\Users\2ion> cat .\.wslconfig
    [wsl2]
    memory=6G
    processors=4
These settings are being respected, as far as I can tell. Since when is it not common sense to assign a reasonable amount to a VM? The only thing that does not seem to work well at the moment is a "memory balloon" RAM allocation scheme. WSL2 is a VM, not a shared memory container. They could do better, but RAM is pretty cheap nowadays and WSLg is IMO the much more productive feature.

See https://docs.microsoft.com/en-us/windows/wsl/wsl-config#conf....


A single (idle) SQL Server Docker container shouldn't be using 5 GB of ram


SQL Server by design grabs as much RAM as it can, as aggressively and preemptively as it can, because it assumes it's the most important process running on the machine. Which is almost always the case in production environments, and a reasonable default behaviour as a result. If that's not the case, you can easily set resource limits at the application, container, and/or VM level.

(This comment coming from someone who used to have to support running small backup MSSQL instances on Windows 8 tablets.)


Yep this. SQL Server using RAM is by design. If it's using too much because you're using it for dev work then you can simply limit the amount it can access. RAM is there to be used!


It's a perfectly fine design so long as there's one, and only one, program that is maximizing its RAM usage. When you have many programs (e.g. the browser, Teams, slack, every single electron app), then you get loads of contention.


> (This comment coming from someone who used to have to support running small backup MSSQL instances on Windows 8 tablets.)

Can I ask what the use case was? Was it just in case the primary DB server died and they wanted a battery powered backup?


Can't speak for OP but here in Africa I've worked on a two unrelated projects where poor internet connectivity meant it made sense to have a local SQL Express running on a users device, which a service would then try to regularly synchronize with the central server. Makes sense when you are capturing documentation and can make all the decisions in disconnected operation.


WSL2 runs in a vm which is integrated with windows, so it actually dynamically requests memory from windows as required. It also can release memory back to windows and is basically is represented on the windows side as a windows process.

Unfortunately like a process there is no way for windows to request memory back from linux (besides killing the entire thing). So its up to the linux kernel to decide what to release back.

What that configuration does is limit the maximum amount of memory it can request (what the linux kernel sees as the total system memory). The reason you need to set a limit right now is that the linux kernel will pretty quickly request most of your windows memory to use as page cache if you don't limit it.

Microsoft is working to allow the linux kernel to use the windows page cache instead of maintaining a separate one.

https://github.com/microsoft/WSL/issues/4166#issuecomment-64...


> Microsoft is working to integrate the linux disk cache with the windows disk cache to avoid this issue

... since july 2019, a locked discussion, a lot of dupes, and no progress to report thus far.


It sounds like a very complicated topic, it's crossing multiple isolation boundaries, and pretty risky to implement, too. A bug can be maximally critical.


> Unfortunately like a process there is no way for windows to request memory back from linux (besides killing the entire thing).

I have long thought it would make sense to add a way for the OS to ask processes to relinquish memory that they can do without. A lot of processes have memory that they use for caching which can safely be dropped but doing so when the memory is not needed elsewhere unnecessarily limits performance.


That would require the application to support it. Like, "got anything you can dealloc?" "Oh shoot, now you mention it..."

What exists already in the Windows VMM, and I assume other OSes VMMs, is a distinction between allocated and committed. That's likely to be the best that's realistically achievable. The win VMM also has a last-accessed strategy for paging to disk, and de-duplication of shared pages.


Did you try setting a RAM limit in .wslconfig ?

https://docs.microsoft.com/en-us/windows/wsl/wsl-config#conf...


Also, looking forward for that new gvim 8GB memory footprint new feature!


Are you sure? I watched the conference and this uses the RDP framework behind the scenes, integrating with Wayland. Why would it consume much more than running natively?


Its not the gui part, its just a full VM.


Oh, I use WSL2 every day and that's not true. I uses dynamic memory and shares with the host. No blocked off 8GB or RAM or anything like that.


wsl2 is such a downgrade from wsl1


+1 If I wanted a VM, I would run a VM. Looks like this is WSL2 only :/


If you want a GUI in WSL1, VcXsrv still works.


It's not perfect: I run IntelliJ in Arch WSL1 and 1) it crashes every time it opens a .md file athough I have (LIBGL_ALWAYS_INDIRECT=1). I have to put -Dsun.java2d.opengl=false -Dsun.java2d.d3d=false in idea64.vmoptions and disable the markdown plugin (maybe only 1 of them is enough) 2) In Windows, IntelliJ automatically saves files when it loses focus. I have to remember to Ctrl-S all the times with IntelliJ in WSL1 3) IntelliJ can't detect where there's a change in the file system. I have to Reload All from Disk all the times.


First I've heard this. I've used neither. What is the major harm of WSL2?


At least for me, WSL1 had pretty good performance on the Windows file system. On WSL2 accessing the Windows file system is pretty slow.

You can read about it here: https://github.com/microsoft/WSL/issues/4197


But compute in general performs better and all non-windows io is way faster.


WSL2 essentially invalidates one of the primary design criteria of the NT kernel, which is that the kernel itself should be able to service any number of "personalities" to provide userspace compatibility with other operating systems.

In practice, this turns out to have meant DOS, OS/2, and a barebones POSIX workalike. Modern Linux is too huge and provides useful APIs that go against the grain of modern NT, so applications are slow in WSL1 and there are too many impedance mismatches to paper over to make the investment worth the effort.


Sure, but I upload my experiments to a Linux cluster and only use my machine for development. Windows IO performance is more important to me than compute.


That's been going on for a few months already, I have a single Docker image running in WSL2 running SQL Server and it's using 5 GB of memory while idle.


Maybe unrelated but I think it is a Hyper-v (w10) issue, not a WSL one. At least same thing happened to me some days ago on one VM running on Hyper-v, it went crazy and consume all my 32gb of ram. It seems to be fixed after reducing the number of cores available to it.


Maybe it's what it's doing for me but I run it for days at a time and it's only taking 2GB.


I'm curious why the parent comment doesn't have an upvote or downvote button.


It was probably in a cool-off period. HN has a bunch of anti-flamewar features that temporarily discourage voting under specific circumstances.


At least the WSL apps share resources.


    PS C:\Users\1_player> cat .\.wslconfig
    [wsl2]
    memory=32GB
Eh, who cares.


I'll gladly accept your machine as a gift to me!

Btw, notebooks have soldiered ram.


Not all notebooks. I updated my ThinkPad from 16GB to 32GB RAM.


It's not exactly wsl is it? Linux considers free memory useless and uses it as cache.

https://www.linuxatemyram.com/

Weird that i didn't knew this. Couple of years ago i wasted some time to get more "free" memory on my server. Lol


That's not really an issue under normal usage; unused memory _is_ useless. The problem is that in this case Linux has to share memory with another OS.


Except that the cache needs to be intelligently shared or split between operating systems, and it's not. Or at least not well, as of 20H2.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: