Your Windows 11 laptop has 8 or 16 GB of RAM, Task Manager shows vmmemWSL holding several gigabytes, and closing Ubuntu did nothing. This guide shows how to tell reclaimable Linux page cache from a real workload leak, set a durable memory and swap cap in .wslconfig, add idle-based reclaim on supported builds, and verify that Windows actually gets the memory back. The goal is a configuration you set once, not another wsl --shutdown ritual every afternoon.
Table of Contents
- Why vmmemWSL Holds RAM After Processes Exit
- Measure the VM from Both Sides
- Read the free Command Correctly
- Build a Durable .wslconfig
- Set the Memory and Swap Caps
- Choose an autoMemoryReclaim Mode
- Decide on vmIdleTimeout
- Apply the Settings and Verify the Cap
- If Memory Still Grows, Find the Culprit
- Roll Back Safely and Recheck Support
- Conclusion
Why vmmemWSL Holds RAM After Processes Exit
WSL 2 runs a real Linux kernel inside a lightweight utility virtual machine (VM). That VM is what Task Manager reports as vmmemWSL on current Windows 11 builds, or Vmmem on older ones. The .wslconfig file controls the VM-wide memory ceiling, swap file, and idle behavior.
Inside the VM, Linux behaves like Linux: it uses spare RAM as page cache to speed up file reads and writes. The free(1) manual defines buff/cache as page cache and slabs, and available as the estimate of memory available to start new applications without swapping. A large buff/cache value is normal and reclaimable.
The problem is ownership. Linux can evict cache when applications need memory, but Windows cannot directly reclaim those cached pages from the VM. Docker's WSL 2 backend guide describes this exact pattern after container image builds: the Linux page cache holds large amounts of RAM, and Windows does not get it back until WSL reclaims it. Microsoft added autoMemoryReclaim to close that gap.
The default limits make this worse on a small laptop. Microsoft's .wslconfig reference sets the default memory cap at 50% of host RAM and the default swap at 25% of host RAM rounded up to the nearest GB. On an 8 GB laptop, that is a 4 GB RAM cap plus a 2 GB swap file. Windows and the VM can end up competing for the same physical memory.
Not every high vmmemWSL number is a leak:
| What you see | What it usually means | What to do |
|---|---|---|
free -h shows high buff/cache and high available | Reclaimable page cache | Let automatic reclaim work; set a sensible cap |
free -h shows high used and low available | Real memory pressure from processes | Find the top RSS process |
| One process's RSS climbs continuously while idle | Likely workload leak | Restart or update it; cap the container |
A complete WSL 2 high memory usage fix distinguishes these cases before changing settings.
Measure the VM from Both Sides
Start with Windows, because that is where the performance pain shows up.
- Press
Ctrl+Shift+Escto open Task Manager. - On the Processes tab, sort by Memory.
- Find
vmmemWSLorVmmemand record its current Memory value. - Open the Performance tab and record Available and In use under Memory.
For a repeatable number, use PowerShell:
Get-Process vmmemWSL, vmmem -ErrorAction SilentlyContinue | Select-Object ProcessName, @{n='WorkingSetGB';e={[math]::Round($_.WorkingSet64/1GB,2)}} Now measure inside Linux:
free -h ps -eo pid,ppid,comm,rss,%mem --sort=-rss | head -n 15 The ps(1) manual documents --sort and the RSS format specifier, so you can rank processes by resident memory instead of guessing. RSS is shown in KiB and includes shared pages, so use it to identify the biggest processes, not to add up an exact total.
Read the free Command Correctly
Here is a typical WSL 2 reading:
total used free shared buff/cache available Mem: 7.8Gi 1.2Gi 4.9Gi 12Mi 1.7Gi 6.2Gi Swap: 2.0Gi 0B 2.0Gi | Column | What it means | How to use it |
|---|---|---|
total | RAM visible to the Linux VM | Compare with your .wslconfig cap |
used | Memory not available for new work | High values mean real pressure |
free | Completely unused RAM | Low values are normal on Linux |
buff/cache | Page cache and reclaimable slabs | High values are usually fine |
available | Estimate for new applications without swapping | Read this first |
The free(1) manual explains that available accounts for page cache and for reclaimable slabs that may not actually be reclaimed because items are in use. If available is high, Linux can satisfy new allocations by evicting cache; you are not about to run out of memory. If available is low and used is high, a process is genuinely holding memory.
The two views can disagree. Linux may report plenty of available memory while Windows still shows a large vmmemWSL, because Windows has not received the cached pages back yet. That disagreement is the cache case, and it is what the rest of this tutorial addresses.
Before you edit the configuration file, confirm that your distro is actually running WSL 2 and that the Store version is installed. This guide to enabling WSL in Windows 11 covers that check, the WSL 1 versus WSL 2 difference, and where .wslconfig resource limits fit.
Build a Durable .wslconfig
.wslconfig is a plain INI-style file stored in %UserProfile%. It applies globally to all WSL 2 distributions. Microsoft also recommends the WSL Settings app for most changes; it reads the same configuration, but the file is easier to back up and keep with your dotfiles.
Back up any existing file first:
$cfg = "$env:USERPROFILE\.wslconfig" if (Test-Path $cfg) { Copy-Item $cfg "$cfg.bak" } notepad $cfg If Notepad asks to create the file, choose Yes. Save it as .wslconfig, not .wslconfig.txt. A malformed or misnamed file is ignored, and WSL starts with its defaults.
A balanced starting configuration looks like this:
[wsl2] memory=6GB swap=2GB vmIdleTimeout=60000 [experimental] autoMemoryReclaim=gradual Set the Memory and Swap Caps
memory is a ceiling, not a reservation. The VM can grow up to that limit, but it does not need to use all of it. Start conservatively and leave Windows enough room to breathe:
| Host RAM | Start with memory= | Start with swap= |
|---|---|---|
| 8 GB | 3GB | 1GB |
| 12 GB | 4GB | 2GB |
| 16 GB | 6GB | 2GB |
These are deliberately below Microsoft's 50% default. On an 8 GB laptop, a 4 GB WSL cap plus a 2 GB swap file is a lot of commitment for a machine that also has to run Windows, a browser, and an IDE. If a build gets OOM-killed, raise memory by 1 GB rather than adding a large swap file.
Swap is disk-backed RAM. It can prevent the Linux out-of-memory killer from terminating a process, but it is not a performance upgrade. A 1–2 GB swap file is enough for most laptop build workloads. If the swap file is constantly active, the VM needs more RAM or a smaller workload, not more swap. Setting swap=0 is allowed but leaves no safety buffer.
Choose an autoMemoryReclaim Mode
autoMemoryReclaim is documented under [experimental], even though current builds enable dropCache by default. It accepts three values:
| Value | Behavior | Best for |
|---|---|---|
disabled | No automatic cache reclaim | Troubleshooting only |
gradual | Waits for idle CPU, then reclaims cache slowly | IDE work and repeated builds |
dropCache | Reclaims cached memory immediately | Maximum free RAM, at the cost of cache misses |
Microsoft's September 2023 WSL update explains that gradual waits for five minutes of continuously low CPU usage, then releases cached memory a portion at a time, aiming to clear a full cache over about 30 minutes. It uses the kernel's cgroup memory.reclaim interface to do this.
The May 2024 WSL update moved automatic memory reclaim to the default setting, dropCache. So on a current Store build, cache reclaim may already be working. Adding gradual makes reclaim gentler, not stronger. Use it if dropCache makes repeated builds slow because the cache keeps getting thrown away; if you want the most aggressive reclaim, leave the default alone.
There is an important limitation: autoMemoryReclaim only targets cached pages. It cannot shrink a running JVM, container, or language server that is actually using memory. The memory cap and process check still matter.
If wsl --version reports a build older than 2.0.0, remove the [experimental] block and rely on the memory cap plus vmIdleTimeout. Update WSL when you can.
Decide on vmIdleTimeout
vmIdleTimeout is the number of milliseconds the VM stays idle before it shuts down. The documented default is 60000, or one minute. Lowering it to 30000 returns all VM memory sooner, but the next wsl command pays a cold-start cost. Do not set it to a few seconds if you rely on background services, and remember that it only helps when no distribution is keeping the VM busy.
Think of the two settings as different tools: autoMemoryReclaim handles cache while the VM is still running, and vmIdleTimeout handles full cleanup after you are done.
Apply the Settings and Verify the Cap
Save the file, then restart the WSL VM. Microsoft's WSL command reference documents wsl --shutdown as terminating all running distributions and the WSL 2 VM, so save your work first:
wsl --shutdown wsl --list --running When wsl --list --running reports no running distributions, start WSL again:
wsl free -h The total line should now be roughly your new cap, allowing for GB versus GiB rounding. If it still shows the old value, check these in order:
- The file is at
C:\Users\<you>\.wslconfig. - The filename is not
.wslconfig.txt. - You ran
wsl --shutdownafter saving. - Your WSL version supports the keys you added.
In Task Manager, vmmemWSL should fall after the shutdown and then grow only toward the new cap under load. Now rerun the workload that caused the problem and compare:
- Record the peak
vmmemWSLvalue during the build. - Record
free -himmediately after the build. - Close the IDE, containers, and build watchers.
- Wait 5–10 minutes without running CPU-heavy tasks, then check again.
- If you use
gradual, allow up to 30 minutes for the cache to be fully reclaimed.
Do not test idle reclaim with a busy terminal. autoMemoryReclaim watches CPU idle, not whether a terminal window is open. A running test watcher or language server can keep the VM busy and prevent reclaim from starting.
If Memory Still Grows, Find the Culprit
If vmmemWSL keeps climbing after the cap is applied, stop tuning and identify the process:
ps -eo pid,ppid,comm,rss,%mem --sort=-rss | head -n 20 Look for node, java, python, containerd, dockerd, vscode-server, language servers, and test watchers. These are common sources of real memory growth inside WSL.
If Docker is running, check container usage:
docker stats --no-stream Docker's stats reference shows each container's memory usage and limit, and notes that on Linux the CLI subtracts cache from the reported memory usage. That makes MEM USAGE a better signal than vmmemWSL when you are trying to decide whether a container is actually holding memory.
Use these rules to interpret what you find:
- A process's RSS climbs continuously while idle. That is a workload leak, not WSL cache. Restart or update the process, reduce its worker count, or give the container a memory limit.
- No process is large,
availableis high, butvmmemWSLstays high. Cache is not being reclaimed. Check thatautoMemoryReclaimis not set todisabled, update WSL, and confirm the VM is actually idle. -
availableis low and no single process is leaking. The cap may be too tight for the workload. Raisememoryby 1 GB or reduce build parallelism. Do not remove the cap entirely on an 8 GB laptop. -
vmmemWSLis far above the cap. The configuration probably did not apply. Recheck the file path, extension, and shutdown step.
Docker Desktop runs in its own WSL distribution, so a running container can keep the shared VM busy even when your Ubuntu terminal is closed. That is another reason closing a terminal window is not a reliable memory test.
Roll Back Safely and Recheck Support
If the new limits cause OOM kills or slow builds, restore the backup:
Copy-Item "$env:USERPROFILE\.wslconfig.bak" "$env:USERPROFILE\.wslconfig" -Force wsl --shutdown If you did not make a backup, delete the file:
Remove-Item "$env:USERPROFILE\.wslconfig" wsl --shutdown WSL starts normally without the file and uses its defaults: a 50% memory cap, a 25% swap file, a 60-second VM idle timeout, and dropCache automatic reclaim on current builds. That is a safe fallback, even if it is not the configuration you want on a small laptop.
After Windows or Microsoft Store updates, recheck the tooling:
wsl --version wsl --update If wsl --version is not recognized, you are on the older inbox build and need to update WSL before expecting the experimental keys to work. Keep your final .wslconfig in your dotfiles or a note, and re-read the current WSL reference after major updates; experimental settings can move, change defaults, or become unnecessary.
Conclusion
High vmmemWSL memory is usually one of three things: reclaimable Linux page cache, a real workload that is still running, or a genuine process leak. Measure with Task Manager, free -h, and ps before changing anything. Then set a memory cap that leaves Windows headroom, add a small swap buffer, keep vmIdleTimeout sane, and use autoMemoryReclaim=gradual on supported builds if you want gentler cache reclaim than the default dropCache. Apply the configuration with wsl --shutdown, verify it after an idle period, and keep the backup handy. That is a durable WSL 2 high memory usage fix that does not depend on remembering to shut the VM down every day.