WSL icon indicating copy to clipboard operation
WSL copied to clipboard

SWAP in wsl-container

Open andrew-r0wdy opened this issue 3 months ago • 2 comments

Is your feature request related to a problem? Please describe.

WSLC creates a separate swap.vhdx for every WSLC session, and the swap size is currently tied directly to the session's configured memory size. There is no user-facing option to disable or configure this swap.

This is problematic for workloads where swap is undesirable or unnecessary, such as Docker/container workloads where predictable memory usage and strict memory limits are preferred. Even when swap is not needed, WSLC still creates and enables it automatically.

This behavior is also different from regular WSL2, where swap can be explicitly disabled with swap=0 in .wslconfig.

Describe the solution you'd like

Please provide a WSLC configuration option to control the session swap size (settings.yaml), for example:

session:
  ...
  swapSize: 0

OR turn off it by default.

Describe alternatives you've considered.

Maybe you'll provide a WA, like swapoff -a , cuz I tried, but it required superuser permission (though I did from root user):

root@8aa0065a7778:/app# swapoff -a
swapoff: Not superuser.

Additional context

The relevant session storage is located under:

%LOCALAPPDATA%\wslc\sessions\<session>\

I think it can expand dynamically, please correct me if I'm wrong.

Image
root@8aa0065a7778:/app# swapon -s
Filename                                Type            Size            Used            Priority
/dev/sdd                                partition       33515516        0               -2

andrew-r0wdy avatar Aug 25 '26 20:08 andrew-r0wdy

Logs are required for review from WSL team

If this a feature request, please reply with '/feature'. If this is a question, reply with '/question'. Otherwise, please attach logs by following the instructions below, your issue will not be reviewed unless they are added. These logs will help us understand what is going on in your machine.

How to collect WSL logs

Download and execute collect-wsl-logs.ps1 in an administrative powershell prompt:

Invoke-WebRequest -UseBasicParsing "https://raw.githubusercontent.com/microsoft/WSL/master/diagnostics/collect-wsl-logs.ps1" -OutFile collect-wsl-logs.ps1
Set-ExecutionPolicy Bypass -Scope Process -Force
.\collect-wsl-logs.ps1

The script will output the path of the log file once done.

If this is a networking issue, please use .\collect-wsl-logs.ps1 -LogProfile networking instead, following the instructions in Collect WSL logs for networking issues

Once completed please upload the output files to this GitHub issue.

See Collect WSL logs (recommended method).

If you choose to email these logs instead of attaching them to the bug, please send them to [email protected] with the GitHub issue number in the subject, and include a link to your GitHub issue comment in the message body, and reply with '/emailed-logs'.

github-actions[bot] avatar Aug 25 '26 20:08 github-actions[bot]

Hi @andrew-r0wdy,

The reason WSLC/WSL2 sessions freeze or suffer severe I/O penalties under memory pressure is because the default stock swap is attached with the lowest kernel priority (Priority -2 on /dev/sdd / /dev/sdc), hitting dynamic .vhdx storage on NTFS at random 4K write speeds (~63–85 MB/s).

Immediate Workaround / Architectural Solution: Kernel Swap Priority Preemption

The Linux kernel strictly allocates swap pages to the swap device with the highest priority value first. You don't necessarily have to disable swap entirely to prevent disk freezing; you can preempt the slow disk swap by injecting high-priority memory tiers:

  1. Tier 0 (Priority 100): In-RAM compressed block device (zram0 with swapon -p 100).
  2. Tier 1 (Priority 50): Fast PCIe cache backed by idle GPU memory (VRAM).
  3. Tier 2 (Priority -2): Stock WSL disk swap (only as an emergency overflow safety net).

We built and open-sourced an implementation for this called RamShared (MIT). It exposes idle GPU VRAM via NBD/ublk at 6.07 GiB/s (6,211 MiB/s) over PCIe directly into WSL2, absorbing container memory spikes in microseconds and completely preventing the host SSD from thrashing.

Hope this architectural workaround helps while upstream configuration options are being evaluated!

emersonbusson avatar Aug 26 '26 02:08 emersonbusson