microsoft / WSL

Issues found on WSL

Home Page:https://docs.microsoft.com/windows/wsl

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Memory/Cpu limit for each distribution

kingsimba opened this issue · comments

I have Docker Desktop installed, and it includes two Linux distribution docker-desktop and docker-desktop-data.

With wsl --list, I can see totally 3 distributions.

C:\>wsl --list
Windows Subsystem for Linux Distributions:
Ubuntu-20.04 (Default)
docker-desktop-data
docker-desktop

I have 16G physical memory, and like to give Ubuntu-20.04 8G. But if I do it in .wslconfig, all 3 distributions are affected.
There are totally 24G committed(over-committed). After a while, when I compile some programs and do some developing work, the computer is extremely slow, with lots of page faults.

There should be an option to set the resource limit of each distribution.

This is an interesting suggestion, would be much easier to add a setting to allow a single per-distro limit. Would that be good enough for you?

Sorry. What you mean by "a single per-distro limit"? I'm thinking about something like:

# .wslconfig
[wsl2]
"Ubuntu-20.04".memory=8GB 
"Ubuntu-20.04".processors=8
docker-desktop.memory=2GB
docker-desktop.processors=2

@kingsimba Did you find any solution for this? I also need this.

@kingsimba Did you find any solution for this? I also need this.

No. I brought more DDR4s. Luckily, they are very cheap nowadays.

@kingsimba Thanks for your reply! I think that will be my solution too. So now I face another issue with trying to convince my client that they need to buy more RAM for their laptops... xD

commented

This is an interesting suggestion, would be much easier to add a setting to allow a single per-distro limit. Would that be good enough for you?

@benhillis could you explain this?

As for original request, it could be expanded beyond just cpu/memory.

New (hidden) settings allow configuring networking (bridging, DHCP, MAC). What if I want distros on different vSwitch, or having static MAC but have 2 VMs (distros) running at the same time?

IMHO, I would love for something like this (using sample from docs):

# Settings apply across all Linux distros running on WSL 2
[wsl2]

[global]
# Limits VM memory to use no more than 4 GB, this can be set as whole numbers using GB or MB
memory=4GB 

# Sets the VM to use two virtual processors
processors=2

# Specify a custom Linux kernel to use with your installed distros. The default kernel used can be found at https://github.com/microsoft/WSL2-Linux-Kernel
kernel=C:\\temp\\myCustomKernel

# Sets additional kernel parameters, in this case enabling older Linux base images such as Centos 6
kernelCommandLine = vsyscall=emulate

# Sets amount of swap storage space to 8GB, default is 25% of available RAM
swap=8GB

# Sets swapfile path location, default is %USERPROFILE%\AppData\Local\Temp\swap.vhdx
swapfile=C:\\temp\\wsl-swap.vhdx

# Disable page reporting so WSL retains all allocated memory claimed from Windows and releases none back when free
pageReporting=false

# Turn off default connection to bind WSL 2 localhost to Windows localhost
localhostforwarding=true

# Disables nested virtualization
nestedVirtualization=false

# Turns on output console showing contents of dmesg when opening a WSL 2 distro for debugging
debugConsole=true

[Ubuntu]
processors=4
macAddress=aa-bb-cc11-22-33

[ArchWSL]
memory=2GB
macAddress=aa-bb-cc11-22-44

Ubuntu section would override globals for just distro named Ubuntu

ArchWSL section would override globals for just distro named ArchWSL.

Globals would apply to all.

So in order of applying settings:
WSL2 built-in defaults
.wslconfig [global] (will override built-in)
[DistroName] (if set, would override both built-in and global)

I need this too.

I need config resources per distributions.

Can it be a feature request?

Shouldn't these limits go into wsl.conf in the distro?

commented

I don't mind any way it's done, as long as it's done per distro/instance.

But as I always see it, despite official description in the docs that simplifies it to "wslconfig is global, wsl conf is per distro", wsl.conf actually has settings that are OS specific, and is read by WSL OS on boot, while wslconfig has settings that are VM specific (eg virtual hardware like CPU, RAM, NIC, ...) and are read by the WSL as subsystem, before distro is run.

It would also allow for VM RAM (for example) to be set before we install and run distro, otherwise if you have 8GB global, VM will still need to boot once with 8GB before you're able to set it to 2GB in wsl.conf, then force WSL2 shutdown and restart.

wslconfig with both global and per distro "virtual hardware" settings just seems like a better (cleaner) solution.

For starters it would be a plus if we got another input from devs

Any update on this? Would love to set memory limits on a per distribution basis.

Any update on this? Would love to set memory limits on a per distribution basis.

Same here. Trying to setup OpenShift Local, which requires 10 GB of memory. As others, I only have 16 GB total. So I would be over committed if I needed to run a second distro.

Same here ... I think the issue is particularly relevant with docker desktop. The memory just jumps to unnecessary levels whenever I start it.
If I shut it down and run echo "sync && echo 3 > /proc/sys/vm/drop_caches" | sudo sh from the ubuntu vm, I can reclaim most of it.
Basically using docker in wsl2 with another distro is just a pain.

After failing to search for the solution to limit memory to the docker desktop, I thought running DD in a different distro and limiting its memory would work, but seems like that will also not work.
Any other solution to limit per distro memory, or limit the DD memory altogether?

C'mon.

Shouldn't these limits go into wsl.conf in the distro?

They should. But is it possible to do that right now?

Hey guys, same problem here, any update?

Honestly, I'm surprised that this feature does not exist, this should be a basic thing to have.

wsl is an amazing feature, I want to set up one master 8GB and 2 nodes 4GB for practicing, but I can not do that now. I want this feature.

To configure the individual distros memory limits would be important. I'm working on SolidCP Web hosting control panel. If one could limit the distros resources one could use WSL to provide Linux container hosting on Windows

One can run each wsl distro under a separate local user, and so each wsl distro can have it's own .wslconfig, but like this probably each running instance uses it's own loaded kernel and the memroy the kernel uses is not shared