Content Insights Tip #69 | Limit WSL host usage

Content Insights logo

If you’re like me, you enjoy using Windows Subsystem for Linux (WSL) for frontend development. It’s a fantastic tool but can sometimes impact your machine’s performance. Fortunately, there’s a way to manage this by limiting the resources WSL uses on your host system. Here’s a quick guide on configuring WSL to work more efficiently.

Steps to limit WSL resource usage

  1. Navigate to your user profile folder
    Open File Explorer and type %UserProfile% in the address bar.

  2. Create a New Configuration File
    In your user profile directory, create a file named .wslconfig.

  3. Add Basic Configuration
    At the top of this file, add: [wsl2]
    This only applies for WSL 2

  4. Set Resource Limits
    To limit memory usage, for example, add: memory=4GB
    This will cap WSL's memory usage to 4GB, reducing the load on your host machine.

  5. Save and restart WSL
    Save the .wslconfig file, then restart WSL for changes to take effect. You can do this by running wsl --shutdown to close all distributions or wsl --terminate <distroName> to target a specific one.

  6. Wait for Boot Completion
    Once restarted, give WSL a moment to fully boot. Your new settings should be active.


More About .wslconfig

The .wslconfig file is a global configuration for all WSL 2 distributions and must be created in your %UserProfile% directory (typically, C:\Users\<YourUserName>). It only affects distributions running as WSL 2 and has no impact on WSL 1.

Note: Configuring global settings in .wslconfig requires WSL 2 on Windows Build 19041 or later. Remember to run wsl --shutdown before restarting for changes to apply.

For further configuration options, refer to the Microsoft Documentation on WSL Advanced Settings.

By customizing WSL's resource usage, you can keep your development environment leaner and faster—happy coding!