Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory/Cpu limit for each distribution #8570

Open
kingsimba opened this issue Jul 1, 2022 · 20 comments
Open

Memory/Cpu limit for each distribution #8570

kingsimba opened this issue Jul 1, 2022 · 20 comments
Labels

Comments

@kingsimba
Copy link

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.

@benhillis
Copy link
Member

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?

@kingsimba
Copy link
Author

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

@EloB
Copy link

EloB commented Aug 30, 2022

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

@kingsimba
Copy link
Author

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

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

@EloB
Copy link

EloB commented Sep 7, 2022

@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

@luxzg
Copy link

luxzg commented Nov 24, 2022

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)

@Cosss7
Copy link

Cosss7 commented Dec 15, 2022

I need this too.

I need config resources per distributions.

Can it be a feature request?

@jazdw
Copy link

jazdw commented Dec 21, 2022

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

@luxzg
Copy link

luxzg commented Dec 21, 2022

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

@kliyer-ai
Copy link

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

@PStoner3
Copy link

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.

@tafia
Copy link

tafia commented May 26, 2023

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.

@orpic
Copy link

orpic commented Jul 15, 2023

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?

@RenanGalvao
Copy link

C'mon.

@paramsiddharth
Copy link

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

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

@Pablo-Conte
Copy link

Hey guys, same problem here, any update?

@zuyan9
Copy link

zuyan9 commented Jan 5, 2024

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

@phamnhuvu-dev
Copy link

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.

@simonegli8
Copy link

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

@simonegli8
Copy link

simonegli8 commented Apr 12, 2024

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 memory the kernel uses is not shared

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests