IntroductionBy now, everyone that is working long enough with WSL (a.k.a WSLinux ?) complaint at least once about a specific pain point: Filesystem performance.
Microsoft acknowledged it several times already, and while they're aware of the problem they also know this is complicated to address as WSL is not virtualized.
I do strongly recommend to watch (again) the Channel9 video on the Filesystem implementation (here's the blog post too).
Please note that some limitations described in the video and/or the blog post are since then been addressed. But the "logic" remains.
So while a real solution will be implemented in the future by Microsoft, here is a quick "hack" that could help on certain projects.
Our workspace is $HOMEas usual, I will target the most used directory:
I blogged about it, on different ways you can have $HOME mounted/linked to a directory in Windows space (latest one even using Azure cloud shell), other persons blogged about it (Brian looking at you), so it's only normal I continue on this trend.
The ideaOk, I will try to make some sense of this crazy mind I have and the "neuronal junction" that lead me to this workaround:
WSL FS (VolFS) is "slow" > WSL Interop (DrvFS) is also "slow".
Both of these FS write on the disk directly, so the next idea that was triggered is: what if I tried to write to the RAM instead? Would that be faster?
I mean, there's a lot of "in Memory" technologies now, so it might be possible to emulate it at a very small scale.
Therefore I tried some TMPFS filesystem, but while a bit faster, I really thought it could be better somehow.
Prerequisites: Windows sideAfter some research and with the goal in mind to, somehow, create a "Disk in RAM" (well, it has a name, Ramdisk, duh), I found a small, but powerful, freeware that was doing exactly what I had in mind. I present you: ImDisk
Once you installed the ImDisk toolkit, you can configure it by launching the Ramdisk configuration application.
I will not share all the results with the different settings that I did, however I do encourage you to perform a fine tuning in order to find the settings that would be the best for your system.
So the following configuration is what works best for me for an "overall" usage:
- I created a 4Go "static disk" (the dynamic option will affect the performance) and decided to not add the Windows TEMP directory in this drive.
For a "persistent" setup, I choose also to have the drive mounted at Startup.
- In the advanced tab, I picked 2KB cluster (block) size (but the difference with 4 and 8 is really small).
The important setting that had more an impact on performance is the AWE that needs to be enabled.
- Finally, and this one is really important to be explained, I choose to copy the data of a specific directory.
Please note that, a RamDisk is volatile and will be erased upon restart.
So ensure that you don't keep important files and, just as a small safety net, enable the auto-sync upon reboot (however sometimes it doesn't work, so back to not save any imporant data)
Everything is now prepared on Windows side, so let's mount all this in WSL and see the behavior.
My $HOME in RAM
As I will mount on top of my original $HOME directory, I just copied over the basic files:
Finally, here are very basic tests of creation of small files and a big file.
Without further due, here are the tests results:
while the multiple small files does not bring a real advantage (actually the DrvFS is even a bit faster when I tested it, so props to Microsoft here), the "big" advantage is shown for the bigger files.
I do encourage, if you managed to not get bored by now, to have maybe more complete tests which are (surely) out of my league.
Once again, I hope this will at least help or even better give an idea to someone and I'm really looking forward to read anyone's blog on this topic. So please share it and tag me @nunixtech
>>> Nunix Out <<<