WSL: WSL2 Slowing down over time

Please fill out the below information:

  • Your Windows build number: (Type ver at a Windows Command Prompt) Microsoft Windows [Version 10.0.18980.1]

  • What you’re doing and what’s happening: (Copy&paste the full set of specific command-line steps necessary to reproduce the behavior, and their output. Include screen shots if that helps demonstrate the problem.)

As the lifetime of a WSL2 install goes on, it slows down more and more, especially when left open. Opening “Ubuntu” in the standard shell takes 15 seconds before it gives me a valid prompt. Entering a command and having it finish (ex: cd ~) takes around 3 seconds before I get a prompt back.

Having to type multiple successive commands makes this much more apparent. For example, editing a file in vim, existing, waiting 4 seconds for the prompt to come back, then editing another file, exiting, waiting 4 seconds… it adds up.

This does not seem to be tied to machine uptime. A freshly rebooted machine has the same slowdown as a machine left on overnight. Sometimes terminating an instance from Powershell helps, but not always.

As another test, I installed a second version of Ubuntu using LxRunOffline. The new distro drops to a prompt almost immediately and has no slow-down.

  • What’s wrong / what should be happening instead:

The WSL2 environments should not slow down over time.

I expect shells to invoke quicker, and commands to execute faster. It should not take nearly 4 seconds to just cd ~. My actual install of Ubuntu (and the newer, secondary WSL2 install of Ubuntu even) responds nearly instantly.

  • Strace of the failing command, if applicable: (If some_command is failing, then run strace -o some_command.strace -f some_command some_args, and link the contents of some_command.strace in a gist here).

N/A

wsl.zip

See our contributing instructions for assistance.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 20
  • Comments: 41

Most upvoted comments

@fmoliveira I’m glad it was helpful. Right now access to /mnt folders in WSL2 is too slow and by default at launch the entire Windows PATH is added to the Linux $PATH so any Linux binary that scans $PATH will make things unbearably slow. #5159

The best for now is using appendWindowsPath=false and adding folders to the $PATH manually. For example for VSCode you only need: export PATH=$PATH:"/mnt/c/Users/onoma/AppData/Local/Programs/Microsoft VS Code/bin" replacing onoma with your Windows username.

Can you try this? Create a file /etc/wsl.conf with this content. Then wsl.exe --shutdown and start the terminal again. Is it slow yet?

Same issue here. Running webpack-dev-server in WSL 2 is painful. I have 512GB SSD, 16GB of RAM and CPU i7 8th gen @ 1.8 GHz.

@decentraliser @therealkenc

This definitely does the trick! thanks!

I’m not sure whether this issue was closed with the proper suggested solution. The OP stated that WSL2 becomes “slow over time”. Using a partition, which is not mounted into Windows, is not about “slowing down over time” – this is immediately slow. It’s a different problem.

I’m using WSL 2 on Windows 10 Enterprise (version 20H2, build 19042.2006) for about 1 month, and it was fast in the beginning, once I started editing and using files only in my Ubuntu home directory (not /mnt/), but it has become slow and regularly unresponsive in the last few days. I have to reboot my notebook (Intel i5 @ 2.6 GHz, 500 GiB SSD, 32 GiB RAM) to make WSL 2 recover.

There is something else broken with WSL 2.

Make sure you are not using /mnt/* folders. With WSL2 the user needs to use the /home/username folder if they truly wants to speed up things. You still can access the files via \\wsl$ on File Explorer.

See the difference: https://vxlabs.com/2019/12/06/wsl2-io-measurements/

Think I have the same problem here: trying to run my angular project in WSL2 and have several issues:

  1. git status is slow and slower then in WSL1 distribution.
  2. vmmem process is eating more and more memory: for example it already took 2Gb, tho there was nothing “running” in there: just a fresh system with everything installed. After wls shutdown: 500mb, run ng serve and its already 800, BUT:
  3. ng serve just does nothing. It stays in “running” condition, without any output. I’ve tried to wait for even 10 minutes…
  4. If I type just ng: everything hangs and after ~30 seconds “help” commands for ng appear.

So conclusion: for now I just can’t use WSL2 distribution for anything. Have to stay with WSL1 and will look at this thread for example.

I have a similar issue with WSL2. I have to reboot a few times a day if I want my terminal to become usable again.

I am using the terminal a lot: webpack dev server, a python server running, docker with a few containers, a few services forwarded from a kubernetes cluster to my localhost (kubectl port-forward), and vim for code editing.

It is slowed down as well when I use VSCode (remotely connected to wsl)

Make sure you are not using /mnt/* folders. With WSL2 the user needs to use the /home/username folder if they truly wants to speed up things. You still can access the files via \\wsl$ on File Explorer. See the difference: https://vxlabs.com/2019/12/06/wsl2-io-measurements/

This was it! So: in case I use /mnt/* - everything slows down. Also about memory: if I understood correctly WSL2 is kind of small subset of HyperV and by default it’s given 80% of your RAM; so it (Linux VM) will occupy all the ram it can. Lets see how it feels during the actual active work. Thanks again.

any way to keep using /mnt/* with performance? Everything I use on WSL is on /mnt/*, it is more practical to access my files from windows and its applications (like IntelliJ and VSCode/VS) and I have control over where I have git files for example, so I don’t clutter my SSD with those.

Make sure you are not using /mnt/* folders. With WSL2 the user needs to use the /home/username folder if they truly wants to speed up things. You still can access the files via \\wsl$ on File Explorer.

See the difference: https://vxlabs.com/2019/12/06/wsl2-io-measurements/

This was it! So: in case I use /mnt/* - everything slows down. Also about memory: if I understood correctly WSL2 is kind of small subset of HyperV and by default it’s given 80% of your RAM; so it (Linux VM) will occupy all the ram it can. Lets see how it feels during the actual active work. Thanks again.

Same problem with vuejs hot reload, using vs code, it was totally fine with WSL1 but it is 10 times slower and freezes from times to times with WSL2

I do notice very significant memory leaks with WSL2 over time, and this may result in some weird swapping behavior that I can’t identify (can’t see into hyperv mmu). I have 64gb of ram, and after a few days, all 64gb are gobbled up by vmmem process in Task Manager.

I started WSL this morning, and it’s taken 14GB of ram, but within the vm guest it only uses 1gb.

Could this be related?

I am working with WSL about 2 years and all the time live with this issue - WSL starting to work slowly over the time. The only thing that helps me is to restart WSL(wsl --restart) when it starts to work slow. I am doing it like once per day or two days. Especially after waking up my PC after hibernation.

This is definitely a real thing. I was noticing this today and I timed a refactor command I’d been developing which seemed to be getting slower and slower.

Run after noticing slow down

real    6m51.373s
user    0m21.999s
sys     0m3.586s

After running wsl --shutdown and restarting my session

real    0m42.377s
user    0m34.388s
sys     0m14.403s

This is on Windows 10 fully patched as of today:

wsl --status
Default Distribution: Ubuntu
Default Version: 2

Windows Subsystem for Linux was last updated on 30/08/2022
WSL automatic updates are on.

Kernel version: 5.10.102.1

For me this is still happening in 2022. So far adding this to the wslconfig helped:

[interop]
appendWindowsPath=false

@onomatopellan Understood! I’ve added it manually and it worked great! Thanks so much for the super clear explanation! I’m coming back from Mac after being away from Windows for over 2 years and I’m loving WSL2!

@onomatopellan

Can you try this? Create a file /etc/wsl.conf with this content. Then wsl.exe --shutdown and start the terminal again. Is it slow yet?

This solution worked great for me! Thanks so much for sharing! The only downside I’ve faced so far is that I cannot use code . to open the current folder in VS Code, so, I have to use the editor to browse folders in my WSL setup which is not as practical as browsing the file system. But it’s manageable!

For historic reasons, I also had this problem and WSL2 became unusable after only a few minutes after booting it. Restarting it helped but after 3-5 minutes of usage, it was just impossible to type any command. Typing top would take over 30 seconds and I couldn’t get top to open after one minute of wait. Then I would run wsl --shutdown and start it again, only to get stuck with the same problem. I’ve used the solution above and I’ve been running for over 2 hours with no problems.

I’m wondering what in the Windows path may be causing this disruption? Any clue how I could help narrowing it?

Thanks again!

This definitely does the trick! thanks!

Thank you so much for the solution! After searching on google for hours and this fixed everything for me! 🎉

I almost uninstall my WSL2 😂

Hello guys I found a possible reason for the problem, in my case I have installed NVM (Node Version Manager) in WSL and when I comment the following lines in .zshrc

# export NVM_DIR = "$ HOME / .nvm"
# [-s "$ NVM_DIR / nvm.sh"] && \. "$ NVM_DIR / nvm.sh" # This loads nvm
# [-s "$ NVM_DIR / bash_completion"] && \. "$ NVM_DIR / bash_completion" # This loads nvm bash_completion

wsl starts instantly

To continue using NVM I found a possible solution here: https://www.growingwiththeweb.com/2018/01/slow-nvm-init.html

I am running an angular development environment and I am dealing with 5 minute HOT reload times on the compile. This is unusable. Can we hear back from Microsoft about this!?!

Has anyone found a solution to this issue? I’ve had the same experience of slowly decreasing performance. Fresh installs run super fast, but after a few weeks become unusable (20 seconds to cd), very disappointing as I have enjoyed using WSL2 so far.

If anyone is interested, I just had this issue and it’s due to WSL’s ipv4 and ipv6 setting (need to disable “Large send offload” for both) in control panel. Here’s a link to a the fix that got me right: https://townsyio.medium.com/wsl2-how-to-fix-download-speed-3edb0c348e29

WSL restart definitely helps, there seem to be something going on with memory, when you look before and after the restart mem consumption is very different. Not sure if its pure consumption or something like memory fragmentation, but as @egracens says before and after wsl --restart can be night and day.

For reference my use is writing code, mainly golang and Visual Studio Code.

Gotcha! Thanks for the tip.

Not only does my WSL2 slow down over time (Installed on Samsung Evo 970 nvme), but on a fresh installation PC, my Explorer no longer takes 1-3 seconds to come up. As soon as I put WSL on there, Explorer and all other apps just give the 1sec+ delay and randomly freeze.

Fresh install+ O365 + VMWare workstation + Visual Studio 2k22 + Patched current as of today work fine. Add WSL2 to the mix and all of a sudden app lag comes right back. I have a 10th gen i7 + 32GB quad channel + 1TB nvme.

It’s quicker to just put Linux or WSL on a WinVM in VMWare and boot it - takes less time than to open a WSL2 prompt. I’m not expecting a miracle, just adding my two cents.

Same here. and appendWindowsPath = false doesn’t turn off /mnt/c/. Is that normal?

@decentraliser @therealkenc

This definitely does the trick! thanks!

I’m not sure whether this issue was closed with the proper suggested solution. The OP stated that WSL2 becomes “slow over time”. Using a partition, which is not mounted into Windows, is not about “slowing down over time” – this is immediately slow. It’s a different problem.

I’m using WSL 2 on Windows 10 Enterprise (version 20H2, build 19042.2006) for about 1 month, and it was fast in the beginning, once I started editing and using files only in my Ubuntu home directory (not /mnt/), but it has become slow and regularly unresponsive in the last few days. I have to reboot my notebook (Intel i5 @ 2.6 GHz, 500 GiB SSD, 32 GiB RAM) to make WSL 2 recover.

There is something else broken with WSL 2.

@bittner I am running into the same problem…

@bittner I’ve recently started running into the same problem (maybe in last month or so, never noticed before).

I am using Docker with WSL + Oh My ZSH, and it is super slow, in the terminal I only use the G disk, the other disks that I have I don’t have to have it mounted, I mean if this slows down my terminal.

A git status or any command like ls under my directory takes like 20 seconds delay. I mean I do ls it shows me the directories and then it takes about 20 seconds delay to get the cursor back to the terminal.

If I add appendWindowsPath=false; docker, wsl and code commands stop working. And I haven’t really seen any speed increase.

This definitely does the trick! thanks!

Interesting fix. The solution for me ended up being two fold: 1) lazy loading of nvm and 2) letting all of my x11 server apps (vcxsrv) through the windows firewall. Bloody annoying but it worked.

Same issue, WSL start time is extremely slow (up to a minute), and vim takes 10-15 seconds to open a file. Wildly awful.

Relatedly, the Vmmem process is taking 1.4gb of ram.

Edit: commenting out nvm does speed up start time but I need nvm, and it doesn’t help with vim.

I’m having the same issue. Running two docker images, an angular instance, two WSL connections through Visual Studio Code and running XDebug makes everything freeze. Couldn’t even type in the WSL 2 terminal anymore

Especially when running the Angular ng serve command, everything just froze.

And we’re back to boot times taking in the area of 15+ seconds. I’m also seeing now “System Interrupts” taking 100% CPU randomly. RAM usage seems fine.

OK, things are better for the most part. Start times are still getting slower, so the time between invoking bash from anything (Hyper, Windows Terminal, or even directly) is slow to start. Once I’m in everything seems to be manageable.

I just installed the latest Fast Ring install, so that may be due to some of the WSL2 improvements.

Moving to an SSD may have helped, time will tell. I will run this for a bit and see, since it really felt that the older the instance was the worse it got (as opposed something like just larger directories, WSL2 is indeed way faster with I/O even when it was slowing down).

I backed up my WSL instance by a simple rsync of my home directory, and after re-installing Windows and switching back to WSL2 I rsynced everything back.

Possibly. I have 20GB of RAM (don’t ask), and I do not see that as the main problem. System Interrupts and Vmmem can randomly peg my CPU at 100% though, which locks a lot of things up.

I don’t seem to run out of memory though.

Mechanical, at least for now. This weekend I plan on moving the OS partition to an SSD (I was just using Windows for gaming so proper Ubuntu currently had my SSD drives). It is a 7200 RPM drive at least.

Correct, that’s the distro’s vhdx file. It’s your distro installed on a mechanical HDD or in an SSD?

Where does WSL2 store it’s default drives? I don’t actually see a VM in Hyper-V for WSL2.

I did find what I think is it’s drive under %USERPROFILE%\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\ext4.vhdx, so I compacted that. It dropped about 1GB in size. If this isn’t the correct drive, let me know and I’ll try a different one.

Booting up the default Ubuntu is about twice as quick now (6-7 seconds), but still nowhere near as quick as the fresh install (1-2 seconds).

As another test, I installed a second version of Ubuntu using LxRunOffline. The new distro drops to a prompt almost immediately and has no slow-down.

That’s interesting. HDD or SSD? Since WSL2 uses a vhdx file as storage the problem could be a fragmented virtual disk. Look for the vhdx that contains the distro and try using the COMPACT option from Diskpart to see if that helps.