WSL2 Performance, Compatibility, and Full Linux Kernel
Yes, Windows Subsystem for Linux 2 (WSL2) brings significant performance improvements, broader application compatibility, and runs a real, full Linux kernel inside a lightweight virtual machine. This architecture change from WSL1 (a translation layer) to WSL2 (a virtualized kernel) resolves many of the file I/O and system call limitations that held WSL1 back.
Background: From WSL1 to WSL2
WSL1 was released in 2016 as a compatibility layer that translated Linux system calls into Windows kernel calls. It booted instantly, used minimal memory, and allowed direct access to Windows files, but it had fundamental issues: some system calls weren’t implemented, and file operations on Windows drives (like /mnt/c) were notoriously slow because of the translation overhead. Many applications that relied on kernel features—such as Docker, FUSE filesystems, or certain networking tools—simply didn’t work.
WSL2, first available in 2020, replaced the translation layer with a genuine Linux kernel running in a Hyper-V virtual machine. The kernel is built by Microsoft from the official Linux source tree, with minor modifications for integration. This means nearly all system calls are handled natively, so applications that worked on a standard Linux distribution now work in WSL2 without modification.
How WSL2’s Architecture Works
WSL2 uses a lightweight utility VM that runs the Linux kernel in the background. This VM is managed by Windows, starts in about 1-2 seconds, and shares memory dynamically with the host. The kernel is stored as a file on your system (typically vmlinux), and you can update it through Windows Update or manually.
Key components of WSL2:
- Virtual Machine Platform: a Windows feature that provides the Hyper-V hypervisor layer WSL2 needs.
- Linux kernel: a custom-built kernel with WSL-specific patches for better integration, such as improved memory reclaim and faster startup.
- 9P file server: the protocol used to share files between Windows and Linux. It’s functional but slower than native file systems on both sides.
- Localhost forwarding: lets you access Linux services from Windows via
localhost(e.g., a web server running on port 3000 in WSL2 is reachable atlocalhost:3000in your browser).
Performance Gains and Trade-offs
The most noticeable improvement is in disk I/O. WSL1’s file operations on Windows drives were painfully slow—often 5-10x slower than native Linux. WSL2, because it runs a real kernel with ext4, performs much better when you keep files inside the Linux filesystem (e.g., /home/). For example, running git status on a large repository stored in WSL2’s ext4 is nearly instant, whereas WSL1 could take seconds.
However, there are trade-offs:
- Cross-OS file access is slower: If you work on files in
/mnt/c/(Windows drives), performance is worse than WSL1 because of the 9P protocol overhead. For best speed, keep your project files in the Linux filesystem. - Memory usage: WSL2 reserves memory for the VM, which can be as high as 50% of your total RAM by default. You can limit this with a
.wslconfigfile. - Startup time: The VM takes a few seconds to boot, whereas WSL1 started instantly. This is negligible for most users.
- Networking differences: WSL2 uses a NAT-based network, so the IP address of the Linux instance is not the same as your Windows host. This can complicate connecting to devices on your LAN, though localhost forwarding works for most cases.
Compatibility: What Works and What Doesn’t
WSL2’s full kernel means that almost all user-space applications work out of the box. This includes:
- Docker Desktop (which can run in WSL2 backend)
- FUSE filesystems (e.g.,
sshfs) - Systemd (if enabled via
wsl.conf) - Kernel modules (though you may need to compile them)
- GUI applications via WSLg (available on Windows 11 and recent Windows 10 builds)
Still, there are limitations:
- Not all hardware is accessible: You cannot directly access USB devices without usbipd-win, and some hardware-specific features (like GPU compute) require special support.
- Kernel modules are limited: The default kernel has many modules enabled, but if you need a specific driver, you may need to build your own kernel.
- Systemd is optional: Before Windows 11, systemd was not enabled by default; you had to install it manually. Now it’s a toggle in
wsl.conf. - 32-bit binaries: WSL2 is 64-bit only; 32-bit executables won’t run.
How to Choose Between WSL1 and WSL2
Microsoft allows you to set the default version per distribution. You can check with wsl --list --verbose and change with wsl --set-version <distro> 2 or wsl --set-default-version 2.
Choose WSL2 if:
- You need Docker, FUSE, or other kernel-dependent tools.
- You want better performance for Linux-native file operations.
- You’re running a modern Linux distribution that expects a full kernel.
Choose WSL1 if:
- You primarily work with files on Windows drives and need fast cross-OS access.
- Your machine doesn’t support Hyper-V (e.g., some older CPUs, or Windows 10 Home without the required features).
- You need to access hardware directly (e.g., serial ports) without extra setup.
Common Problems and Fixes
Here are a few issues you might encounter with WSL2 and how to resolve them:
- High memory usage: Edit
.wslconfigin your Windows user folder to setmemory=4GBor similar. - Slow file access on /mnt/c: Move your project files to the Linux filesystem, or use WSL1 for that specific workload.
- Network connection refused: If a service in WSL2 isn’t reachable, check if it’s listening on
0.0.0.0(not just127.0.0.1). - VM won’t start: Ensure the Virtual Machine Platform feature is enabled, and that your CPU supports virtualization (check with
systeminfo). - Kernel update issues: Run
wsl --updateto manually trigger a kernel update.
Frequently Asked Questions
Is WSL2 a full Linux kernel? Yes, it’s a real Linux kernel built from the official source, running in a lightweight VM. It’s not a stripped-down version; it includes most modules and drivers you’d find in a standard distribution kernel.
Can I run Docker in WSL2? Yes, Docker Desktop can use WSL2 as its backend, or you can install Docker Engine directly inside a WSL2 distribution. This is one of the main reasons people switch to WSL2.
Why is my code running slower in WSL2 than native Linux? The VM adds a small overhead, and cross-OS file access is especially slow. For CPU-bound tasks, the difference is minimal; for disk-heavy tasks, keep files in the Linux filesystem.
Does WSL2 support systemd? Yes, since Windows 11 and recent Windows 10 versions, you can enable systemd by adding [boot] systemd=true to /etc/wsl.conf.
Can I access my Windows files from WSL2? Yes, they are mounted under /mnt/c (and other drives). However, for best performance, avoid heavy I/O there.
How do I update the WSL2 kernel? Use wsl --update from PowerShell or Command Prompt. Windows Update also installs kernel updates automatically.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.