Description
openedon Nov 20, 2019
Is your feature request related to a problem? Please describe.
I occasionally have workloads that consume large amounts of disk space for temporary use in /tmp
. For example, transcoding large video files or processing large datasets exported from a database. Since WSL2 stores its filesystem on a .vhdx
, that file grows when the dataset is processed and never releases that space. Also, it doesn't appear to re-use released disk space in the .vhdx
when files are deleted... it seems to prefer to grow the file rather than re-use existing empty space. (I haven't explicitly tested that theory, but my workload deletes temporary files as they are used and I never had enough of them existing simultaneously to reach 250GB, but the size of the .vhdx
eventually expanded to that size.
When I'm done with that workload, I have to:
wsl --shutdown
optimize-vhd -Path .\ext4.vhdx -Mode full
This is annoying since it basically means that my system backups include a huge .vhdx
file that is mostly empty. Also, until about 2 weeks ago, it was consuming the entire remainder of my system disk. I had only 50GB free, which was enough to handle the workload, but since it continued to grow even after files were removed, that didn't matter. (I figured it was time to upgrade the disk size anyway)
Describe the solution you'd like
Automatic compaction of the .vhdx
, or a way to do so while WSL2 is still running so that I can schedule it for frequent cleanups.
Describe alternatives you've considered
- Going back to WSL1 since it uses the host filesystem and is faster accessing that than WSL2. However, this alternative makes docker less useful. Docker on WSL2 is actually almost perfect; not so much on WSL1.
- Exporting/Importing WSL 2 to move it to another disk. Not even sure if this is possible, but if it is,
it would probably be fine for my desktop, but not really an option for my laptop. Not really worth the time either since that entire process would probably take about 30 minutes, but compacting is usually under 3.