How to Limit WSL 2 RAM, CPU using .wslconfig

WSL 2 makes it easy to run Linux directly inside Windows, but if you use it for development, Docker, databases, builds, or other heavy workloads, you may notice that WSL can consume a significant amount of your system resources.

Fortunately, WSL 2 allows you to control how much RAM and CPU it can use through a simple configuration file called .wslconfig.

Below are the steps to configure it.

1. Make Sure You Are Using WSL 2

The .wslconfig resource settings discussed in this guide apply to distributions running on WSL 2.

Open PowerShell and run:

wsl --list --verbose

You should see something similar to:

  NAME      STATE           VERSION
* Ubuntu    Running         2

Check the VERSION column.

If it shows:

2

your distribution is running on WSL 2.

You can also check your installed WSL version with:

wsl --version

2. Create the .wslconfig File

The .wslconfig file belongs inside your Windows user directory:

C:\Users\<username>\.wslconfig

Instead of opening a text editor, you can create the file directly from PowerShell.

For example:

@"
[wsl2]
memory=8GB
processors=4
"@ | Set-Content "$env:USERPROFILE\.wslconfig"

This creates a .wslconfig file containing:

[wsl2]
memory=8GB
processors=4

The values above are only an example. You can change them depending on how many resources you want to give WSL.

3. Limit WSL RAM Usage

The memory setting defines the maximum amount of RAM available to WSL 2.

For example:

memory=8GB

This means WSL can use up to approximately 8 GB of RAM.

You can choose another value:

memory=4GB

or:

memory=12GB

depending on your machine and workload.

For example, a complete configuration with an 8 GB limit would look like:

[wsl2]
memory=8GB

This is useful if WSL, Docker, or development tools are consuming too much memory and causing Windows itself to become slow.

4. Limit the Number of CPU Processors

You can also control how many logical processors WSL is allowed to use.

For example:

processors=4

This limits WSL to four logical processors.

A configuration containing both RAM and CPU limits would look like:

[wsl2]
memory=8GB
processors=4

You could use:

processors=2

for a smaller workload, or increase it if you regularly perform heavier tasks such as compiling applications or running multiple containers.

The correct number depends on the CPU available on your computer.

5. Check Your Configuration

You can display the current .wslconfig directly from PowerShell:

Get-Content "$env:USERPROFILE\.wslconfig"

You should see something similar to:

[wsl2]
memory=8GB
processors=4

If you want to completely replace the configuration later, simply run the Set-Content command again with your new values.

For example:

@"
[wsl2]
memory=12GB
processors=6
"@ | Set-Content "$env:USERPROFILE\.wslconfig"

This replaces the previous configuration.

6. Restart WSL

Changing .wslconfig does not immediately modify a WSL instance that is already running.

First, shut down WSL:

wsl --shutdown

Then start it again:

wsl

Your new resource limits should now be applied.

A quick workflow after modifying .wslconfig is:

Get-Content "$env:USERPROFILE\.wslconfig"
wsl --shutdown
wsl

7. Verify the RAM Limit

After entering WSL again, check the available memory:

free -h

You should see output similar to:

               total        used        free
Mem: 7.7Gi 1.2Gi 5.8Gi

The exact numbers may not be identical to the value in .wslconfig, but the total memory should approximately reflect the limit you configured.

8. Verify the CPU Limit

To check how many processors WSL can use:

nproc

If your configuration contains:

processors=4

the command should return:

4

You can also see more detailed CPU information with:

lscpu

Quick Summary

Create or replace the configuration:

@"
[wsl2]
memory=8GB
processors=4
"@ | Set-Content "$env:USERPROFILE\.wslconfig"

Restart WSL:

wsl --shutdown
wsl

Check RAM:

free -h

Check CPU:

nproc

With .wslconfig, you can keep WSL 2 from consuming more system resources than you want while still giving your Linux development environment enough RAM and CPU for everyday work.

Book a Free Consultation

Haven’t found the right solution yet?
Tell us about your needs, and let’s discuss the best solution together.