3 Gotchas with WSL 2 around Disk Space, Memory Usage and Performance

preview_player
Показать описание
We'll identify and fix a few WSL 2 issues that'll likely cause you issues over time.

Hit the subscribe button to receive more videos like this!

---

Timestamps:

0:00 What we'll cover in this video
0:30 Combating poor file performance in WSL 2 when accessing mounted drives
2:38 Ensuring WSL 2 doesn't use up to 80% of your system's memory
6:17 Clearing out WSL 2's memory usage on demand with a Bash alias
8:21 Reclaiming disk space that WSL 2's VM won't free up by default
10:12 Be careful because WSL 2 won't auto-mount your external drives
12:56 How to shrink your WSL 2 VM to reclaim disk space in PowerShell
18:10 An alternative to the Optimize-VHD command on Windows 10 Home
19:10 Recap and hopefully Microsoft fixes these issues in future WSL 2 patches

Reference links:

---

Follow along?

Рекомендации по теме
Комментарии
Автор

THANK YOU! I just found out about the WSL2 memory usage that crippling my laptop. I didn't even know that the WSL2 has some storage reclaiming problem. Thank you, once again.

secondculs
Автор

I have been using wsl since version 1 but man you have done lot of research and your knowledge is astonishing.

iamworstgamer
Автор

Excellent work with this video Nick. Really useful, especially how to reduce the amount of memory WSL2 uses!

bensmith
Автор

Here's the timestamps:

0:30 Combating poor file performance in WSL 2 when accessing mounted drives
2:38 Ensuring WSL 2 doesn't use up to 80% of your system's memory
6:17 Clearing out WSL 2's memory usage on demand with a Bash alias
8:21 Reclaiming disk space that WSL 2's VM won't free up by default
10:12 Be careful because WSL 2 won't auto-mount your external drives
12:56 How to shrink your WSL 2 VM to reclaim disk space in PowerShell
18:10 An alternative to the Optimize-VHD command on Windows 10 Home
19:10 Recap and hopefully Microsoft fixes these issues in future WSL 2 patches

NickJanetakis
Автор

Thanks for the video Nick. In my case, the vhdx are located in



Debian is located in distro, data are located in...data :)

nikos.andreou
Автор

This helped a lot, my system memory was being pegged.

RobertJohnTaylor
Автор

I ran across this virtual disk bloating issue myself and although I use Windows 10 Pro I don't have the optimize-vhd program. I read somewhere it's because my Windows doesn't use hyper visor or whatever.. anyways.. I found the alternative way that you are showing at the end but I ran into another problem: even though I detached the vdisk after compacting I couldn't access the disk anymore. Windows said it's in use. Luckily this was not a big deal for me because there was no important data on the virtual disk. I uninstalled and reinstalled the Linux distro. I found that a slightly different method works fine. First you check if the distro in question is running with "wsl.exe --list --verbose" If it is running terminate it like this "wsl.exe --terminate Ubuntu" (name of your distro of course) then start diskpart and enter the select command like in your example but do not attach the disk. Just enter "compact vdisk" and that's it. For me this works great, just in case someone else has the same problem, that I had.

pxlbltz
Автор

First of all, thanks for the video.

Unfortunately both tasks:
1. optimize-vhd -Path .\ext4.vhdx -Mode full
and
2. diskpart
select vdisk file="C:\...\ext4.vhdx"
compact vdisk

Did not work for me.
Altough the progress bar is visible and in both approaches, it finishes at ~30% with sucess / no error
The blocked memory on my C drive is not gained back.

Maybe someone had the same issues and could help.

I have w11 pro and use wsl2 my ssd is 2tb so:
wsl2 is taking
virtual: 1024 GB
physical: 960 GB
even tough its actual size is just 29GB

LDS-Hellgineer
Автор

Thanks for the detailed tutorial.
Any ideas on how to get WSL2 connect to the internet with VPN turned on, on Windows?

nikhilranka
Автор

Hey! The video was informative, thank you very much.
I want to say that this video does not have the ability to turn on subtitles. English can be difficult for me and I often turn on automatic subtitles.

Other videos on the channel do not have this problem. Not sure what could be the matter? Maybe something is disabled in the video settings?

MalkizChannel
Автор

FIrst of all, thank you for you information, it's what I've been looking for! been bugged with this space issue for a whole day! cuz I'm new to ubuntu system.

Some quick question:
Does the method reclaim all of the space before the packages installation in miniconda virtual environment?
Because I noticed that before the packages installation in the venv, the disk was around 28 GB. However after I removeed that venv with "conda remove -n PACKAGE_NAME --all", "conda clean --all", “sudo apt clean”, "sudo apt autoremove", and then finally your method, the disk was back only to 24 GB.

I wonder if it's the method to not reclaim all of the space in the first place or might just be some other problem?

nervous
Автор

Thanks for the heads up, Nick. For some reason I haven’t been able to upgrade Windows 10 to 2004 here in Australia, even though I bought a brand new copy.

OtRatsaphong
Автор

you can download the wsl 2.2.1 prerelease finally! Not sure if the disk space fix is in. So far the memory usage has been fine. The tunneling and mem usage is a great fix/improvement.
fixes this stuff:
Enable DNS tunneling by default
Integrate DNS tunneling with Linux native Docker
Change the default reclamation mode to drop cache
Fix hang when the guest crashes during distro initialization

scuzzyhoulihan
Автор

I give wsl all my ram, but I have a Task Scheduler script that drops cache every 5 mins. I did have the alias, but I chose to automated it.

while-loop
Автор

I am not able to find alias file in your repo

divyamsharma
Автор

So if I understand correctly, wsl2 takes up space pointing to where the ext4.vhdx file is located. Is that correct?
anyway, Excellent video!

hirisraharjo
Автор

You should probably reclaim disk space from your docker and docker-data distros as well.

Archil
Автор

Hi Nick, Thank you for this wonderful tutorial. Lately, I came across similar problems and tried to reclaim space using the command you provided. I am running windows home machine. However, when i try to run 'attach vdisk readonly'. i get the following errror that says Diskpart has encountered an error. The process cannot access the file because it is being used by another process. and Then I checked by system event log for more info, and the error was related to hyper-v-storage which says Failed to map guest I/O buffer for write access with status 0xC000012D. Device name = . Any help would be appreciated. Thanks

yubikhadka
Автор

I had trouble finding the vhdx file (I installed using Chocolaty). Turns out it was located at "C:\Users\All

alecclews
Автор

awesome video. I have one question. Can I use windows resources on demand with wsl2? If I am running a wsl2 for development with 4 gb of ram but some scripts require more ram. But if i set it in wslconfig it will restrict the ram. I can define config inside the wsl2 distro but it has to be on demand. I don't want to define it again and again.

iamworstgamer