This content originally appeared on DEV Community and was authored by Sarah Siqueira
As a WordPress developer, I used XAMPP for a long time, but for lots of reasons, some of which you can see in this other article: Why I changed from XAMPP to Docker, I decided to move to a Docker environment.
Turns out, the besides the learning curve to handle with Docker, and all other stuff, other problem came up. My poor Windows machine has become sluggish as it struggles to run other processes like Firefox and VS Code. It was basically impossible to work.
I opened up Task Manager while WSL 2 was running and noticed that the process named vmmem was absorbing a sizable chunk of my memory and slowing down my machine, turning impossible any other task.
What's it vmmem?
vmmem is a process that represents all the resources consumed by your Linux VM while WSL is running. According to Microsoft’s documentation, the amount of RAM that gets allocated to WSL depends on your Windows build number. On machines running build 20175 or higher, RAM is limited to either 50% of your total memory or 8GB, whichever happens to be smaller. On builds older than 20175, WSL could consume up to 80% of your host RAM.
While working on this article, I’m running a Windows 10 build 19044, so my WSL reserves 80% of my host RAM (8 GB). Fortunately, we can customize WSL 2 to limit the number of CPU cores, memory usage, swap space, and more. A big thanks to all the ones who replied in this GitHub issue pointing out how this can be done.
Workaround
To solve this, I follow the steps according to the Microsoft documentation.
Create a .wslconfig file
You need to create a .wslconfig file under your Windows user profile directory (C:\Users\YourUsername.wslconfig). On launch, WSL will read this file if it exists and configure itself accordingly. In this file, you can tell WSL 2 how much RAM, swap space, CPU cores, and other resources it should allocate.
I focused only on limiting memory usage, but you can configure any other options that you want, refer to the Microsoft docs for more options. The .wslconfig I am currently using is below (I don’t have a lot of RAM to work with):
[wsl2]
memory=2GB
With just two lines, now I am able to run Docker on a machine with just 8 GB RAM. After restarting and launching docker-compose up
again, my environment works perfectly without slowing down my machine. Checking the Task Manager, vmmem does not consume more than 2 GB anymore.
This content originally appeared on DEV Community and was authored by Sarah Siqueira
Sarah Siqueira | Sciencx (2023-05-15T13:59:01+00:00) Limiting Docker Memory Usage on Windows. Retrieved from https://www.scien.cx/2023/05/15/limiting-docker-memory-usage-on-windows/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.