Skip to content

WSL2 Performance Tuning & Memory Optimization

Admin
October 1, 2026
5 min read
Intermediate
💻 Target OS: Windows 11 / Windows 10 (WSL2)

Before you begin

  • Applies to:Windows hosts running WSL 2.
  • Where to start:Start in Windows and review the existing per-user .wslconfig before editing it.
  • What you need:Have the host's available memory and CPU in mind. Save work in all WSL distributions before applying changes because these settings affect all of them.
Guide tools
Guide tools
0/0 Steps (0%)

By default, WSL 2 can use up to 50% of Windows memory for its utility VM. This guide sets global resource limits and optional networking and memory-reclamation settings. Mirrored networking requires Windows 11 version 22H2 or later and a current WSL release; check your version before enabling it.

Architecture: Windows Host to WSL2 Resource Allocation

Configuring global resource caps ensures your Windows host maintains low latency while your Linux environment runs at peak performance:


01

Open Global .wslconfig in Windows Profile

Configuration

The .wslconfig file governs global settings across all WSL 2 distributions for this Windows user. It resides in your Windows user profile. If it already exists, back it up and merge these settings into its existing sections rather than replacing unrelated values. Check that the intended distribution is version 2 before tuning it:

Terminal window
# Open or create .wslconfig directly from PowerShell
notepad "$env:USERPROFILE\.wslconfig"
# Check the WSL package version and which distributions use WSL 2
wsl --version
wsl --list --verbose
❯ Illustrative Output (Results Vary)

Opened Notepad for C:\Users<Username>.wslconfig. Confirm the target distribution uses VERSION 2 before applying these settings.


02

Define Memory, CPU, and Mirrored Network Limits

Tuning

Paste the settings that fit your machine into .wslconfig. The resource limits apply to every WSL 2 distribution for this Windows user. Mirrored networking changes how WSL connects to LANs and VPNs; use it only on supported Windows 11 systems. autoMemoryReclaim=gradual gradually releases cached Linux memory. sparseVhd=true marks newly created VHDs as sparse; it does not compact an existing distribution disk.

[wsl2]
# Cap memory allocation (e.g., 6GB on a 16GB machine, 16GB on a 32GB machine)
memory=8GB
# Limit CPU processors allocated to WSL2
processors=4
# Configure swap space on your fastest SSD
swap=4GB
# Windows 11 22H2 or later with a current WSL release
networkingMode=mirrored
dnsTunneling=true
firewall=true
autoProxy=true
[experimental]
# Gradually return Linux page-cache memory to Windows
autoMemoryReclaim=gradual
# Applies to newly created WSL VHDs; does not compact existing VHDs
sparseVhd=true

03

Shutdown & Restart WSL Hyper-V Subsystem

Activation

To commit the configuration changes, shut down the running Hyper-V microVM and restart WSL from PowerShell:

Terminal window
# This stops every running WSL distribution for this Windows user.
wsl --shutdown
# Relaunch your default distribution
wsl
❯ Illustrative Output (Results Vary)

[All WSL distributions stopped]
Launching default distribution…


04

Verify Updated Memory & Swap Caps

Verification

Inside your Ubuntu/Debian WSL terminal, verify that the kernel respects the updated memory cap:

Terminal window
free -h
❯ Illustrative Output (Results Vary)

total used free shared buff/cache available
Mem: 7.8Gi 1.2Gi 5.8Gi 12Mi 850Mi 6.4Gi
Swap: 4.0Gi 0B 4.0Gi

Comments