Tuesday, April 29, 2025How to limit WSL memory usage
Keven Client A. Cataluña @LinkedIn
Introduction

This guide demonstrates how to limit WSL memory usage by configuring the .wslconfig file, restarting the WSL service, and verifying the memory allocation before and after the change.

Steps1. Create .wslconfig file with the following configuration
C:\Users\Development\.wslconfig
    [wsl2]
memory=4GB
  
2. Restart the WSL service from PowerShell (Run as Administrator)
    Restart-Service LxssManager
  
3. Verify the memory usage
Before
    free --human
  
                    total        used        free      shared  buff/cache   available
  Mem:          7.6Gi       1.7Gi       3.6Gi       0.0Ki       2.3Gi       5.7Gi
  Swap:         2.0Gi       1.0Mi       2.0Gi
  
After
    free --human
  
                    total        used        free      shared  buff/cache   available
  Mem:          3.8Gi       105Mi       3.6Gi       0.0Ki       168Mi       3.5Gi
  Swap:         1.0Gi          0B       1.0Gi