If you’re running Visual Studio Code with WSL 2, you’ll find you get the best performance if your files are within the WSL filesystem. (I’ve written about this separately.)
You might still experience VS Code grinding to a halt, attempting to access files however. One symptom at this point is that if you run df
or ls /mnt
within WSL, this will hang. You may not even be able to exit with Ctrl-C or kill -9
.
It seems that an I/0 lockup can occur with network/remote shares. One of the easiest ways to diagnose this is to strace df
. This will show you the problematic share causing the hang. E.g.:
[rob@PC:/]$ strace df
execve("/usr/bin/df", ["df"], 0x7fffd3bb8800 /* 34 vars */) = 0
brk(NULL) = 0x55c6c8ef8000
...
newfstatat(AT_FDCWD, "/mnt/w", {st_mode=S_IFDIR|0544, st_size=4096, …}, 0) = 0
In my case I had the Windows W: drive connected to another Linux machine via, using SSHFS-Win. I don’t ever need to access this drive in WSL, but it’s available because I’m using automount.
To keep automount enabled, but exclude one network drive, for example:
- Create an empty directory, which we’ll mount as a dummy:
mkdir /mnt/empty
- Ensure
fstab
mounting is enabled. In/etc/wsl.conf
, in the[automount]
section, you need a line:mountFsTab=true
- Then in
/etc/fstab
, mount the folder that would normally be linked to the Windows drive to the empty folder instead. E.g.:/mnt/emptyW /mnt/w none bind 0 0
- Restart WSL at a Windows command/terminal prompt:
wsl --shutdown & wsl
The directory in question, that previously would have shown the contents of the remote folder, should now be empty.
If you have more than one such folder, you may need to repeat the steps, starting with strace df
. For me, this restored VS Code’s filesystem performance.