In this simple tutorial, I will be explaining how to configure your windows subsystem for Linux efficiently and optimize your WSL performance when you're running applications through them.
Why WSL firstly?
- Everyone has widespread access to windows but they may or maynot be savvy enough to run their favorite flavour of linux due to various constraints
- WSL2 really makes life easy for those devs who can't access linux through a cloud provider or locally run it on their devices.
- WSL has support for various distros like Debian, Arch and Ubuntu.
Now coming to the interesting part, windows has all access to the CPU and memory resources in your device and it is built in a way which will optimize the resource utilization but how do you limit your linux subsystem, let us say you'd like to manipulate the configuration to suit your needs the best, then you should follow these steps.
Step one:
Shut your current running instance of WSL using this command
wsl --shutdown
Run this command through powershell as administrator
Step Two:
Create a configuration file for WSL on your user profile directory
notepad "$env:USERPROFILE\.wslconfig"
Step Three:
This is the most important step in this project, so please follow carefully
The following parameters define their corresponding resources:
- CPU = > cores dedicated to WSL
- Memory = > RAM allocated to WSL
- AutoMount = > Mount your default NTFS drive to your subsystem
- Boot => defines your booting options for services
- Kernel = > Custom kernel for linux
- LocalhostForwarding = > for port-forwarding your applications running on localhost
My configuration for CPU and memory:
[wsl2]
memory=9GB
processors=4
This is how you can configure your resources for WSL ๐. Feel free to leave some comments down belowโฌ๏ธ.
You can read this document for the reference
Top comments (2)
Short and precise tutorial, though having some insight into the implementations of the other parameters would be helpful.
I would add
in case someone has problems with download speeds within WSL