Currently Available: Need a skilled Software Developer for your next project?
Categories
Uncategorized

How to Limit WSL2 Resource Usage with .wslconfig

The WSL2 virtual machine (Vmmem process) can consume a significant amount of system memory and CPU. You can set resource limits by creating a .wslconfig file in your Windows user profile.

1. Locate Your User Profile Folder

Open the Windows File Explorer. In the address bar, type %UserProfile% and press Enter. This will navigate to your user folder (e.g., C:\Users\YourName).

2. Create the .wslconfig File

In your user folder, create a new file named exactly .wslconfig.

Note: Ensure the file does not have a .txt extension. If you can't see file extensions, go to the "View" menu in File Explorer and check the box for "File name extensions".

3. Add Configuration Settings

Open the .wslconfig file with a text editor and add your desired limits. Below is an example configuration you can adjust based on your system's hardware.

[wsl2]
# Sets the maximum RAM WSL2 can use.
memory=8GB

# Sets the maximum number of CPU cores WSL2 can use.
processors=4

# Helps WSL2 return unused memory back to Windows.
autoMemoryReclaim=gradual
  • memory: Set this to a specific value, for example, 4GB, 8GB, or 16GB.
  • processors: Set this to the number of CPU cores you want to allocate.

4. Apply the Changes

These settings only take effect after WSL is fully restarted.

  1. Open PowerShell or Command Prompt.
  2. Run the shutdown command:
    wsl --shutdown

The next time WSL starts, it will use the new resource limits defined in your .wslconfig file.

What I'm building

Delegate tasks. Get software.

Give Vroni a GitHub issue, bug report, spec, or rough idea. It reads the repo, plans the change, writes code, runs checks, and works toward a review-ready pull request.

Take a look at vroni.com

Subscribe to my newsletter

Get new posts when I publish them.

I respect your privacy. Unsubscribe at any time.

Leave a Reply

Your email address will not be published. Required fields are marked *