WSL: WSL2 FS access to Windows on W11 is much slower than on Win10

Version

Microsoft Windows [Version 10.0.22000.1335]

WSL Version

  • WSL 2
  • WSL 1

Kernel Version

Linux version 5.15.79.1-microsoft-standard-WSL2 (oe-user@oe-host) (x86_64-msft-linux-gcc (GCC) 9.3.0, GNU ld (GNU Binutils) 2.34.0.20200220) #1 SMP Wed Nov 23 01:01:46 UTC 2022

Distro Version

Ubuntu 20.04

Other Software

python

Repro Steps

Ensure defender is disabled

PS C:\> Set-MpPreference -DisableRealtimeMonitoring $true
PS C:\> Get-MpPreference | select DisableRealtimeMonitoring

DisableRealtimeMonitoring
-------------------------
                     True

On ubuntu WSL measure performance with oneliner that writes one byte to a file, reads it back and obtains file info (stat). It does so 1000 times.

First, measure it on Windows 10 ([Version 10.0.19045.2364])

Win10

link@UNIT:~$ time python3 -c "for _ in range(1000): import os; f = open('./1.dat', 'w'); f.write('1'); f.close(); f = open('./1.dat', 'r'); f.read();  os.stat('./1.dat')"

real    0m0.053s
user    0m0.023s
sys     0m0.008s
link@UNIT:~$ cd /mnt/c/temp
link@UNIT:/mnt/c/temp$ time python3 -c "for _ in range(1000): import os; f = open('./1.dat', 'w'); f.write('1'); f.close(); f = open('./1.dat', 'r'); f.read();  os.stat('./1.dat')"

real    0m1.498s
user    0m0.115s
sys     0m0.115s

As you could see, everything is much slower on win FS, but still usable.

Now, lets go to Win11 ([Version 10.0.22000.1335])

link@WinDev2211Eval:~$ time python3 -c "for _ in range(1000): import os; f = open('./1.dat', 'w'); f.write('1'); f.close(); f = open('./1.dat', 'r'); f.read();  os.stat('./1.dat')"

real    0m0.054s
user    0m0.032s
sys     0m0.021s
link@WinDev2211Eval:~$ cd /mnt/c/temp
link@WinDev2211Eval:/mnt/c/temp$ time python3 -c "for _ in range(1000): import os; f = open('./1.dat', 'w'); f.write('1'); f.close(); f = open('./1.dat', 'r'); f.read();  os.stat('./1.dat')"

real    0m13.515s
user    0m0.172s
sys     0m0.895s

Here are 13 seconds. But user/sys time is low. On vmstat(8) output I see insanely high number of interrupts and context switches. So I assume each FS access leads to many interrupts processed on kernel thread, not accounted as process time because of that.

Lets now see syscall wallclock time:

link@WinDev2211Eval:/mnt/c/temp$ strace -c -w python3 -c "for _ in range(1000): import os; f = open('./1.dat', 'w'); f.write('1'); f.close(); f = open('./1.dat', 'r'); f.read();  os.stat('./1.dat')"

% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
 33.53    6.106872        2973      2054         2 openat
 15.76    2.870026        1384      2073           read
 15.20    2.767644         896      3087           fstat
 14.32    2.608359        1269      2055           close
  6.14    1.117568        1117      1000           write
  5.16    0.938890         821      1143        26 stat
  4.85    0.882534         218      4038      4032 ioctl
  4.83    0.879587         216      4065         3 lseek
# ... whatever
------ ----------- ----------- --------- --------- ----------------
100.00   18.212611                 19728      4066 total

6 seconds for 2000 openat(2) syscalls on “11th Gen Intel® Core™ i9-11950H @ 2.60GHz” (one year old CPU) a little but too much, especially when it was not so slow on W10

Expected Behavior

I expect to have 1 second for this oneliner on W11 as I had on W10

Actual Behavior

13 seconds for the same script on W11 what took 1 second on W10

Diagnostic Logs

No response

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 31
  • Comments: 20

Most upvoted comments

Come on, Microsoft!

Yes, since upgrading to win 11 I noticed that even typing is sometimes slow and laggy in my IntelliJ IDE when projects are open in WSL2,

Hi! Are there any updates on this task? This issue causes a lot of problems for those who work directly with WSL filesystem…

Anything related to WSL2 on IDEA / PyCharm is painfully slow to the levet that tool is not usable. It can’t read Python source / installed libraries and even having WSL mentioned somewhere in config file is making IDE slow (IDEA was refreshing it and and tool was hanging).

Knowing it, I wouldn’t upgrade to Windows 11. Please fix it.

wow, even on Win10, using the mounted /c, access is a hundred times as slow (100x) for me! (For you it was only 30x as slow.) I have an M2 device (3000MB/s), so my numbers looked like this for Win10 (I don’t have Win11).

But it seems openat takes the same share of the time on Win10. All of it just takes longer for you on Win11.

$ time python3 -c "for _ in range(1000): import os; f = open('./1.dat', 'w'); f.write('1'); f.close(); f = open('./1.dat', 'r'); f.read();  os.stat('./1.dat')"

real    0m0.075s
user    0m0.047s
sys     0m0.028s

$ cd /mnt/c/temp

$ time python3 -c "for _ in range(1000): import os; f = open('./1.dat', 'w'); f.write('1'); f.close(); f = open('./1.dat', 'r'); f.read();  os.stat('./1.dat')"

real    0m6.991s
user    0m0.235s
sys     0m0.607s

$ strace -c -w python3 -c "for _ in range(1000): import os; f = open('./1.dat', 'w'); f.write('1'); f.close(); f = open('./1.dat', 'r'); f.read();  os.stat('./1.dat')"
% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
 38.33    2.850289        1390      2050         4 openat
 21.06    1.566075         371      4212        26 newfstatat
 15.33    1.140052         556      2049           close
 15.03    1.117715         541      2064           read
  6.02    0.448019         448      1000           write
  2.16    0.160561          39      4059         3 lseek
  2.00    0.148785          36      4035      4029 ioctl
 # ... skipped these
------ ----------- ----------- --------- --------- ----------------
100.00    7.436441         378     19625      4065 total

Maybe you can do an strace for your Win10 too, to also have those numbers.

For me on Windows 11 file access gets slower and slower until it completely hangs…

https://github.com/microsoft/WSL/issues/9654

@rynex-zv - must be a Windows 11 issue, because I have no such experience on Windows 10. No slowdown whatsoever.

Or some of your drivers are conflicting with each other.

I have this issue on windows 10

Hi there! I have Win11 and i just installed WSL 2

PS C:\WINDOWS\system32> wsl --version
WSL version: 1.0.3.0
Kernel version: 5.15.79.1
WSLg version: 1.0.47
MSRDC version: 1.2.3575
Direct3D version: 1.606.4
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.22621.1105
PS C:\WINDOWS\system32> wsl -l -v
  NAME      STATE           VERSION
* Ubuntu    Stopped         2

When the Ubuntu is running, my explorer and other programs get super slow (Animation , opening files || apps …) not only in the Linux Directory but also in other Drivers! Windows is on samsung SSD 2TB Ubuntu is located on another SSD M.2 2TB I had the Task Manager running to see if it is a Hardwere thing, and it isn’t. (2% used)

GPU                 RTX-2070S gaming 8G
Processor	Intel(R) Core(TM) i7-9700K CPU @ 3.60GHz   3.60 GHz
Installed RAM	32.0 GB (31.8 GB usable)
System type	64-bit operating system, x64-based processor
Edition	        Windows 11 Pro
Version	        22H2
Installed on	‎1/‎21/‎2023
OS build	         22621.1105
Experience	Windows Feature Experience Pack 1000.22638.1000.0

https://youtrack.jetbrains.com/issue/IDEA-293604/IntelliJ-is-slow-hanging-when-working-with-WSL-filesystem The discussion on JetBrains issues tracker. There are conversations about adding exclusions to Windows Defender helps.

 Add-MpPreference -ExclusionPath "$Env:PROGRAMFILES\JetBrains","$Env:APPDATA\JetBrains","$Env:LOCALAPPDATA\JetBrains","\\wsl$\Ubuntu","\\wsl.localhost\Ubuntu","\\wsl$\Ubuntu-20.04","\\wsl.localhost\Ubuntu-20.04","\\wsl$\podman-machine-default","\\wsl.localhost\podman-machine-default","\\wsl$\docker-desktop","\\wsl.localhost\docker-desktop","\\wsl$\docker-desktop-data","\\wsl.localhost\docker-desktop-data"

I don’t think this is recommended.

Here is Win10.

win10$ time python3 -c "for _ in range(1000): import os; f = open('./1.dat', 'w'); f.write('1'); f.close(); f = open('./1.dat', 'r'); f.read();  os.stat('./1.dat')"

real    0m0.033s <--- awesome! 
user    0m0.027s
sys     0m0.000s
win10$ cd /mnt/c/temp
win10$ time python3 -c "for _ in range(1000): import os; f = open('./1.dat', 'w'); f.write('1'); f.close(); f = open('./1.dat', 'r'); f.read();  os.stat('./1.dat')"

real    0m1.121s <--- Not perfect, but not terrible either
user    0m0.056s
sys     0m0.111s
win10$ strace -c -w  python3 -c "for _ in range(1000): import os; f = open('./1.dat', 'w'); f.write('1'); f.close(); f = open('./1.dat', 'r'); f.read();  os.stat('./1.dat')"
% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
 34.99    0.716022         350      2042         3 openat
 16.52    0.338074         110      3060           fstat
 14.95    0.305986         149      2043           read
 13.56    0.277428         135      2042           close
  6.51    0.133324         133      1000           write
  6.32    0.129261         117      1103        16 stat
  3.71    0.075993          18      4024      4018 ioctl
  3.32    0.067891          16      4037         3 lseek

Everything is good on Linux. Win has ~ 1 second, which is much slower, but not a big issue. The heaviest call is openat(2) again

I can live with Win10 performance, but not with Win11