WSL Containers: support persistent sysctl configuration (e.g. vm.max_map_count)
I am using the latest WSL preview version:
WSL version: 2.9.3.0
Kernel version: 6.18.35.2-1
WSL Containers runs in a dedicated session VM where kernel parameters can be modified interactively:
wslc system session shell
/usr/sbin/sysctl -w vm.max_map_count=262144
or like this
wslc system session run /usr/sbin/sysctl -w vm.max_map_count=262144
However, the session is ephemeral. After the session is terminated and restarted, the value is reset to the default (65530).
This prevents running workloads such as Elasticsearch or OpenSearch without executing an initialization command after every new session.
It would be useful to support persistent kernel parameters, for example in settings.yaml:
session:
sysctl:
vm.max_map_count: 262144
or any equivalent mechanism executed when a new session is created.
I tried using the .wslconfig file with:
[wsl2]
kernelCommandLine="sysctl.vm.max_map_count=262144"
but it doesn't affect the wslc session configuration (only the WSL distributions)
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'.
Confirmed the same behaviour on 2.9.4.0 — the wslc session VM is ephemeral, so wslc system session run sysctl -w ... works but resets on the next session. The .wslconfig [wsl2] kernelCommandLine path only affects WSL distros, not the wslc session VM, so it can't help here.
Until persistent session config lands, the least-brittle workaround I've used for Elasticsearch/OpenSearch-type workloads is to fold the sysctl into your startup wrapper so it runs on every session boot:
# bootstrap.ps1 — run once per session, before starting your workload
wslc system session run /usr/sbin/sysctl -w vm.max_map_count=262144
wslc run -d --name es ... docker.elastic.co/elasticsearch/elasticsearch:8.x
Not elegant, but it survives the session being recreated. A settings.yaml session.sysctl block (like your proposal) would be the clean fix — worth keeping the request open and referencing it from the Docker --sysctl-analogue discussions, since the Docker flag itself also doesn't exist on wslc run yet (see the capabilities gaps tracked in #41181).