Solution:
Root Cause: Uncapped WSL2 Linux Kernel Page Cache Retention
By default, WSL2 allocates up to 50% of total host RAM (or 80% on older Windows builds) to its lightweight utility virtual machine. As containers process data or access files, the Linux kernel inside WSL2 caches these operations in memory to boost I/O performance. However, Hyper-V does not automatically release this cached memory back to the Windows host OS, causing the
vmmem or
vmmemWSL process to hold onto gigabytes of RAM permanently until the subsystem shuts down.
Diagnostic Verification:
Open Windows Task Manager -> Details tab -> check Memory (Active Private Working Set) for vmmem or vmmemWSL.Inside WSL2 terminal, run free -h to inspect total vs. cached memory (buff/cache).Step-by-Step Fix:
1Limit WSL2 Memory Allocation via .wslconfig:
Press Win + R, type %USERPROFILE%, and press Enter.Create or edit the file named .wslconfig in a text editor.Add the following configuration block to cap memory and enable dropcache: ini
[wsl2]
memory=4GB # Adjust cap based on host RAM (e.g., 4GB for 16GB total RAM)
processors=2
swap=2GB
[experimental]
autoMemoryReclaim=dropcache # Automatically reclaims cached memory (WSL 2.0+)
2Restart the WSL2 Subsystem:
Open Windows PowerShell as Administrator.Terminate all running WSL instances: wsl --shutdownRestart Docker Desktop.3Verify Limits in Official Documentation:
For advanced configuration keys, consult the Microsoft Official WSL Documentation.Prevention & Long-Term Monitoring:
Manually purge Linux page cache inside WSL2 if needed without shutting down: echo 3 | sudo tee /proc/sys/vm/drop_caches.