Skip to content

init: size hvsocket listener buffers so host-initiated connections avoid order-7 ring allocations - #41690

Open
Manthan Vasani (ManthanVasani) wants to merge 3 commits into
microsoft:masterfrom
ManthanVasani:hvsock-listener-buffer-size
Open

Manthan Vasani (ManthanVasani) wants to merge 3 commits into
microsoft:masterfrom
ManthanVasani:hvsock-listener-buffer-size

Conversation

@ManthanVasani

@ManthanVasani Manthan Vasani (ManthanVasani) commented Sep 24, 2026 •

Copy link
Copy Markdown

Summary of the Pull Request

Under guest memory fragmentation, new WSL sessions and Windows interop hang: page allocation failure: order:7 in vmbus_alloc_ring, then UtilAcceptVsock ... accept4 failed 110 (#40795). For a connection the host opens, hv_sock sizes both VMBus rings from the listening socket's buffers. Init's listeners, other than the Plan 9 server, set none, so they inherit net.core.wmem_default/rmem_default (212992), and every accepted connection needs one physically contiguous order-7 block. This PR sets SO_SNDBUF/SO_RCVBUF to 14336 (doubled by the kernel to 28672) on the listeners that accept control and stdio connections, except WSLC's thread forks (see Not changed). Each of those connections then needs an order-4 block, the same as a connection the guest opens.

PR Checklist

Detailed Description of the Pull Request / Additional comments

Root cause (kernel linux-msft-wsl-6.6.114.1; WSL line numbers are master 8a9533901ae5 before this change)

  • hvs_open_connection() sizes both rings of a host-initiated connection from the listener: max(sk_sndbuf, 6 pages), capped at 64 pages (hyperv_transport.c#L372-L381).
  • The 6-page default comes from hvs_sock_init() (#L453-L454). Since c0cfa2d8a788 ("vsock: add multi-transports support", v5.5) it runs only at connect() and for the accepted child, never on a listener. A listener keeps what sock_init_data() copied from wmem_default/rmem_default (sock.c#L3444-L3445).
  • UtilListenVsockAnyPort (util.cpp:1596) sets no buffer size. vmbus_alloc_ring() allocates both rings as one physically contiguous block with no smaller fallback (channel.c#L167-L192): 104 pages, order 7. If the allocation fails, the offer is dropped and the connection never reaches accept(), so a timed UtilAcceptVsock sets ETIMEDOUT (util.cpp:268) and logs accept4 failed 110 (:281).
  • On 6.18, VMBUS_RING_SIZE() adds a 4 KB header page only to rings under 32 KB (hyperv.h#L183-L189), so 212992 is order 7 there too.

Change

  • UtilListenVsockAnyPort takes an optional SocketBuffer, like UtilConnectVsock, and sets SO_SNDBUF/SO_RCVBUF before listen().
  • New LX_INIT_HVSOCKET_LISTEN_BUFFER_SIZE (14336) in lxinitshared.h, passed at:
    • the session leader (init.cpp:1232)
    • wsl.exe process stdio and control (init.cpp:1421)
    • the distro interop channel (config.cpp:906)
    • Linux-to-Windows interop stdio and control (binfmt.cpp:153)
    • stdio of processes started with CreateLinuxProcess (ProcessCreateProcessMessage, util.cpp:3456)
    • WSLC_ACCEPT, the stdio of processes WSLC starts in the VM's root namespace (WSLCInit.cpp:272)
    • WSLC_FORK process and pty forks (WSLCInit.cpp:569), which carry only control messages: every root-namespace process launch (WSLCVirtualMachine.cpp:836, pty :883), the port-relay setup (:1054) and the 9P mount setup (:1245)
  • Each connection these listeners accept needs 7 + 7 pages on 6.6 and 8 + 8 on 6.18: order 4 on both.

Not changed

  • The NAT localhost relay (main.cpp:1139), import/export (main.cpp:2529) and the WSLC port relay (WSLCInit.cpp:890), because they carry bulk data.
  • WSLC_FORK thread forks (WSLCInit.cpp:569). They include the relay to /var/run/docker.sock (DockerHTTPClient::ConnectSocket), which carries bulk Docker traffic such as images/load and container stdio (attach, exec), and the guest cannot tell that relay from the other thread forks by fork type, so all thread forks keep the default. Docker API calls, including container attach and exec, can therefore still need an order-7 ring.
  • The Plan 9 server, which sets its own size (plan9.cpp:318-320: 65536, doubled to 131072, order 6).

Why 14336: it is the value tested below. Any SocketBuffer up to 14336, or exactly 16384, is order 4 on both kernels. Values in between are order 5 on 6.18, which still adds the header page below 32 KB. Order 5 and above is also the range free page reporting works on: WSL boots the kernel with page_reporting.page_reporting_order (5 on the machine tested), and the reporting worker takes up to 32 not-yet-reported free blocks of that order or above off the free lists while it reports them to the host (page_reporting.c#L279, #L201). Order-4 blocks are never taken. I have not measured how much this matters.

Why in init: it works on the 6.6 and 6.18 kernels already shipped, and it leaves the bulk listeners alone. A kernel change would complement it: use the listener's buffers only when they were set explicitly, as before 5.5, or allocate a non-contiguous ring as proposed in #41634.

Related: #40519 (protects WSL's own processes under memory pressure) and #41252 (times out the create-process accepts, so leaked relays exit; #41242) are both merged and address the same hang. Neither changes the ring size.

Risks

  • Throughput. These rings shrink from 208 KB to 28 KB per direction (32 KB on 6.18). Upstream commit ac383f58f3c9 ("hv_sock: perf: Allow the socket buffer size options to influence the actual socket buffers") measured raw hv_sock with 64 KB writes at about 460-690 MB/s (Linux writer) and 615-680 MB/s (Windows writer) with 24-32 KB rings. With 128 KB rings it measured about 1,860 and 1,670 MB/s. Change default relay buffer size to 64KiB #41603 measured 613 MiB/s through the stdio relay with its 64 KiB buffer, which is already in the small-ring range, so the ring may become the bottleneck for bulk wsl.exe, interop or WSLC root-namespace process stdio. Measured (see Validation): on 2.7.3, which relays stdio in 4 KiB chunks, bulk data from Windows into Linux was about 18-24% slower with 28 KB rings, and Linux to Windows was within about 4% at the median. On 3.0.1, which has Change default relay buffer size to 64KiB #41603's 64 KiB relays, the loss is larger: with this PR's 32 KB rings, bulk stdio ran at 0.31-0.37 of the 208 KB speed from Windows to Linux and 0.57-0.59 from Linux to Windows (about 520-600 MiB/s, against 940-1,680 MiB/s). The fallback is 32768 (a 64 KB ring, order 5), which measured about 2,000 and 1,070 MB/s in the same commit, and on 3.0.1 0.54-0.58 of the 208 KB speed from Windows to Linux and 0.97-1.05 from Linux to Windows. From Linux to Windows, every size from 64 KB up ran at about the same speed (median 860-990 MiB/s), so something other than the ring, probably the Windows reader, limits that direction from 64 KB up and could hide a smaller ring effect there. I have field data for order-4 rings only (below), not for order 5.
  • If setsockopt fails, the listener is not created (so the session, interop call, CreateLinuxProcess call, or WSLC process launch, port relay or 9P mount fails), the same as in UtilConnectVsock. For these options, only an LSM or a cgroup setsockopt BPF program can make it fail. I can change this to log and continue if you prefer.
  • Order 4 is the smallest ring hv_sock requests, but the allocation can still fail. Order-4 9P client allocations failed during the 2.7.3 test, while none of the order-4 rings did. In 18 days of daily use on 3.0.1 with the same setting (see Validation), at least 25 order-4 hv_sock rings failed: 21 after the guest had run out of memory and swap, and 4 with swap free. One of those 4 was followed by an interop call failing with accept4 failed 110 after its 10-second accept timeout. No size the listener can request avoids the out-of-memory case, since order 4 is the smallest. This makes the failure much rarer, not impossible.

Validation Steps Performed

  • clang-format 19.1.7 with the repo's .clang-format makes no changes to the seven files.

  • Compiled the patched UtilListenVsockAnyPort on its own (g++ with stub macros, not the repo build) and ran it on 6.6.114.1. SO_SNDBUF/SO_RCVBUF read back doubled after listen(). The Plan 9 server's listener sets 65536, and every traced 9P ring is 131072, so the listener's setting does size these rings.

  • Same ring size without this build: net.core.wmem_default/rmem_default = 28672 on WSL 2.7.3.0 / kernel 6.6.114.1, with every vmbus_alloc_ring() traced by a kprobe.

    • Before the change: 1 of 41 rings at 212992 failed in about 6 minutes.
    • About 5.2 hours after, under fragmentation: 2,114 rings at 28672, none failed, and none were requested at 212992.
    • In the same period, 5 of 51 of the Plan 9 server's 131072 rings (order 6) failed, each within milliseconds of 28672 rings that succeeded.
    • A once-a-minute cmd.exe /c ver passed 294/294; for 84 of those runs, no free block of order 7 or larger existed.
    • The sysctl lowers every listener created after the change that sets no size of its own, including the bulk ones, so it covers more than the PR does. It mostly exercised binfmt.cpp:153. It did not exercise config.cpp:906, ProcessCreateProcessMessage or WSLC, which is not in 2.7.3.
  • Full build and CI: Azure Pipelines build 394557 of c1a655f61 merged into master 35052e9c1 succeeded: formatting and localization checks, x64 and arm64 builds, packaging, and the wsl1, wsl2 and wslc test sessions on rs_prerelease.

  • A kprobe trace with this build at default sysctls: not run yet.

  • Throughput on WSL 2.7.3.0 / kernel 6.6.114.1, emulated through net.core.wmem_default/rmem_default (the same listener sk_sndbuf/sk_rcvbuf this PR sets), with every run's ring sizes confirmed by the vmbus_alloc_ring() kprobe: 2 GiB per transfer, five runs of five rounds, sizes interleaved, each compared with the 208 KB run in the same round (median [range], n rounds):

    Path Direction 28 KB (this PR on 6.6) 64 KB (SocketBuffer 32768)
    wsl.exe stdin Windows to Linux 0.76 [0.68-0.78] n=8 0.96 [0.88-1.02] n=17
    interop stdout (a Windows process read by Linux) Windows to Linux 0.82 [0.70-1.01] n=8 1.00 [0.89-1.30] n=17
    wsl.exe stdout Linux to Windows 0.96 [0.84-1.14] n=9 1.03 [0.83-1.14] n=17
    interop stdin (Linux writing to a Windows process) Linux to Windows 1.02 [0.79-1.14] n=9 0.99 [0.80-1.24] n=18

    2.7.3 relays stdio in 4 KiB chunks, so these ratios understate the effect on a release with Change default relay buffer size to 64KiB #41603. The Linux-side writer and reader used on these paths, connected by a plain Linux pipe, ran at 776-1,054 MiB/s, against at most 549 MiB/s on any path. None of the 3,062 traced ring allocations failed. The 28 KB arm was in three of the five runs, and 31 of the 100 planned 208 KB runs were skipped because free order-7 blocks were scarce, so n varies.

  • Throughput on a release with Change default relay buffer size to 64KiB #41603 (first in 2.9.13 pre-release and 3.0.1 stable): WSL 3.0.1.0 / kernel 6.18.40.1, the same emulation and kprobe, 2 GiB per transfer, two runs of five rounds, sizes interleaved, each compared with the 208 KB run in the same round (median [range], n = 10 for every cell):

    Path Direction 32 KB (this PR on 6.18) 64 KB (SocketBuffer 32768) 128 KB
    wsl.exe stdin Windows to Linux 0.37 [0.32-0.82] 0.58 [0.49-1.22] 0.86 [0.75-1.50]
    interop stdout (a Windows process read by Linux) Windows to Linux 0.31 [0.19-0.35] 0.54 [0.43-0.69] 0.80 [0.65-0.91]
    wsl.exe stdout Linux to Windows 0.59 [0.46-0.71] 1.05 [0.86-1.19] 1.05 [0.93-1.15]
    interop stdin (Linux writing to a Windows process) Linux to Windows 0.57 [0.46-0.71] 0.97 [0.77-1.04] 1.03 [0.83-1.08]

    The 208 KB medians were 937-1,678 MiB/s and the 32 KB medians 516-603 MiB/s. The interop paths have no Linux pipe. The first run had load 3-7 on 12 CPUs, the second 0.2-2.3. In the second run's two rounds below load 0.6, the 32 KB ratios were 0.33-0.36 from Windows to Linux and 0.53-0.66 from Linux to Windows, so load does not explain the loss. The high ends of the wsl.exe stdin ranges come from one 208 KB run slowed by load (813 MiB/s) in the first run. All 168 runs' ring sizes were confirmed, none of the ring allocations failed, and no 208 KB run was skipped. WSLC root-namespace process stdio is not measured.

  • 18 days of daily use with the same emulation (net.core.wmem_default/rmem_default = 28672 from 2026-10-13, WSL 3.0.1.0, seven boots, kernel log of every boot). The kernel printed 157 page allocation failures and suppressed 3,695 more (warn_alloc ratelimit), so the counts below are lower bounds. The setting also shrank the listeners this PR leaves alone, and rings for connections the guest opens are order 4 as well, so these rings are not all from the listeners this PR changes. 25 printed failures were order-4 vmbus_alloc_ring rings (hvs_probe): 21 in the two periods when the guest ran out of memory and swap (OOM kills), and 4 with 2.3-4.0 GiB of swap free. There were 16 accept4 failed 110 timeouts: 15 in the two out-of-memory periods, and 1, from an interop call by wsl-pro-service, ten seconds after one of the 4 other failures (interop processes log only to their own stderr, so this count is also a lower bound). Order-6 hv_sock rings, the size the Plan 9 server sets, failed 58 times on 14 of the 18 days, none with swap full and 3 at or below the low watermark, so fragmentation alone fails order-6 rings here. The other 74 were 9P client allocations (67, order 4) and other callers (7).

  • 6.18, the same emulation on WSL 3.0.1.0 / kernel 6.18.40.1: a vsock listener reads SocketBuffer 14336 back as 28672, and with listener buffers of 28672 every traced ring was 32768 bytes (8 + 8 pages with the header page, order 4). Listener buffers of 32770, 65536 and 212992 traced as rings of 36864, 65536 and 212992, matching the source. None of the 672 traced ring allocations failed. The ring sizing in hvs_open_connection(), VMBUS_RING_SIZE() and vmbus_alloc_ring() is unchanged in 6.18.54.1 (WSL 3.0.3).

Copilot AI lite review requested due to automatic review settings September 24, 2026 01:45
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

A moderate concern remains about unmeasured throughput regression on bulk process I/O.

Review effort: Lite
Findings: None

What changed in this PR

This PR reduces HvSocket listener buffers to avoid order-7 ring allocation failures under guest memory fragmentation.

Changes:

  • Adds a shared listener buffer-size constant.
  • Configures send/receive buffers before listening.
  • Applies sizing to control, stdio, interop, and WSLC listeners.
  • Throughput impact for bulk process I/O remains unresolved.
File Summary
src/​shared/​inc/​lxinitshared.h Defines the listener buffer size.
src/​linux/​init/​WSLCInit.cpp Sizes WSLC accept listeners.
src/​linux/​init/​util.h Updates the listener API.
src/​linux/​init/​util.cpp Applies socket buffer options.
src/​linux/​init/​init.cpp Sizes session and stdio listeners.
src/​linux/​init/​config.cpp Sizes the interop listener.
src/​linux/​init/​binfmt.cpp Sizes Windows interop listeners.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@ManthanVasani

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

…oid order-7 ring allocations

hv_sock sizes the VMBus rings of a connection the host opens into the
guest from the listening socket's SO_SNDBUF/SO_RCVBUF. Since kernel 5.5
(c0cfa2d8a788, "vsock: add multi-transports support") a listener keeps
net.core.wmem_default/rmem_default (212992 by default), so every accepted
connection needs one physically contiguous order-7 block (52 + 52 pages).
When guest memory is fragmented that allocation fails, the offer is
dropped, and new sessions and interop hang ("UtilAcceptVsock ...
accept4 failed 110").

Add an optional SocketBuffer to UtilListenVsockAnyPort, like
UtilConnectVsock, and pass LX_INIT_HVSOCKET_LISTEN_BUFFER_SIZE (14336,
which the kernel doubles to 28672) at the listeners that accept control
and stdio connections. Their rings become 7 + 7 pages (8 + 8 on 6.18),
an order-4 allocation. Listeners that move bulk data (NAT localhost
relay, import/export, WSLC port relay, WSLC_FORK) and the Plan 9 server
are unchanged.

Related: microsoft#40795

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

WSLC_FORK Process/Pty listeners remain unsized and can still trigger order-7 ring allocations.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 High severity

Open (1)

Comment thread src/linux/init/WSLCInit.cpp Resolved
Copilot AI review requested due to automatic review settings September 24, 2026 02:56
@ManthanVasani
Manthan Vasani (ManthanVasani) marked this pull request as ready for review September 24, 2026 02:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

WSLC_FORK control listeners remain exposed to order-7 allocations; a naming nit also remains.

Review effort: Lite
Findings: 1 High severity

Open (1)

Copilot AI review requested due to automatic review settings September 24, 2026 03:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

Full build, throughput validation, and 6.18 testing remain pending for this socket-buffering change.

Review effort: Lite
Findings: None

Resolved since last review (1)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

It changes critical session and interop transport behavior without a full build or pending throughput and 6.18 validation.

Review effort: Balanced
Findings: None

@emersonbusson

EMERSON BUSSON (emersonbusson) commented Sep 25, 2026 •

Copy link
Copy Markdown

This is closely related to the order-7 VMBus ring allocation failure, and I am working on a complementary kernel-side upstream series. The series changes VMBus ring allocation to fall back through smaller page orders and hardens buffer ownership/cleanup when GPADL operations have uncertain outcomes. It is maintained separately from this WSL userspace change in the kernel fork.

The latest hosted run 36148296003 passed all six patch stages on x86_64 and arm64, the separate WSL backport build, and x86_64 KUnit 14/14. The hyperv-vmbus-buffer suite passed 10/10, including a new allocation callback test that injects failures above order zero, allocates and frees a real order-zero page, and verifies clean order-zero exhaustion. Arm64 KUnit was skipped. Artifacts bind the run to mainline base 93f51579e7df248780214094418f205253383cc5 and series commit dbec28671d5f7bb3c1017151574a7649019671aa.

The ordinary x86_64 Hyper-V runtime test covered normal GPADL create/teardown and UIO/ring mmap on an earlier series snapshot. The hosted injected tests do not prove live allocator fragmentation or host-response/rescind interleaving. SEV-SNP, TDX, and Arm CCA memory-transition tests also remain open. The kernel work may complement the listener-buffer reduction here; it does not replace the userspace change. I have not measured its effect on the throughput tradeoff discussed in this PR, and I am not claiming full CoCo qualification or universal support.

@chipsfromhell

Copy link
Copy Markdown

Hi, this is affecting my day-to-day WSL use too. On WSL 3.0.3 with kernel 6.18.54.1, intermittent UtilAcceptVsock:281: accept4 failed 110 errors have been blocking Windows process launches and automated maintenance.

I have captured page allocation failure: order:7 with vmbus_alloc_ring -> vmbus_open -> hvs_probe. In one failure snapshot, both DMA32 and Normal were above their high watermarks, but neither had any free 512 KiB or larger blocks. That seems consistent with the fragmentation mechanism described here, although I cannot tie every launch failure to a particular allocation failure.

I also tried a temporary 48-hour change to net.core.wmem_default and rmem_default, from 212992 to 28672. Newly created channels showed 28672 bytes of idle write capacity, and a 4 MiB binary stdin/stdout round trip passed with matching hashes and no slowdown in that small check. Allocation warnings continued during the trial, so I cannot call it a fix. The original defaults have since been restored. This was the broader sysctl approximation, not a build of this PR, and it was not a bulk-throughput benchmark.

Could a maintainer trigger the pending CI build and advise what further validation would be most useful? I would appreciate getting this tested properly, as the intermittent failures are a recurring hindrance. Thanks for working on it.

@SapphireHotS

Copy link
Copy Markdown

Field report in favour of this per-listener approach over the global sysctl workaround from #40795.

Environment: WSL 3.0.3.0, kernel 6.18.54.1-microsoft-standard-WSL2, Windows 11 26200.9711, Ubuntu 24.04, memory=10GB, swap=8GB, autoMemoryReclaim=gradual, networkingMode=mirrored, Docker Desktop with WSL integration.

Still reproduces on 3.0.3. The relay leak from #41242 is gone (0 orphaned Relay processes after 90 min; 18 on 2.7.14), but new sessions still fail with Wsl/Service/WSAETIMEDOUT, 12 times in the first 90 minutes of this boot, same signature:

kworker/0:2: page allocation failure: order:7, mode:0xdc0(GFP_KERNEL|__GFP_ZERO)
Workqueue: hv_pri_chan vmbus_add_channel_work
 vmbus_alloc_ring+0x78/0xd0
 vmbus_open+0x29/0x80
 hvs_probe+0x1f6/0x4c0
WSL (21495 - SessionLeader) ERROR: UtilAcceptVsock:281: accept4 failed 110

with 5.7 GB MemAvailable and no free block of order >= 7 in either zone. The unmovable pages here are mostly slab (SReclaimable 2.09 GB, SUnreclaim 0.38 GB of a 9.7 GB guest).

The global sysctl workaround breaks Docker Desktop. sysctl -w net.core.wmem_default=28672 net.core.rmem_default=28672 made sessions reliable (0 failures over several hours), but the defaults are kernel-wide, so dockerd in the docker-desktop distro gets them too. With ~45 bridge networks its netlink dumps overflow:

failed to add interface veth...: no buffer space available
Error initializing network controller: list bridge addresses failed: no buffer space available

and after a restart Docker Desktop sits on "waiting for the Docker API: context deadline exceeded" until both values are set back to 212992. Sizing only WSL's own listeners, as this PR does, avoids that, which is why I would like to see it merged.

Happy to test a build on this machine if that helps.

Resolve the conflict in UtilListenVsockAnyPort with the EINTR retry on
listen(): the listener's send and receive buffers are set first, then
listen() runs with the retry.
Copilot AI balanced review requested due to automatic review settings October 31, 2026 20:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Reported 18–24% stdio throughput losses warrant maintainer review of the reliability/performance tradeoff, with full-build validation and representative benchmarks for current 64 KiB relays and WSLC still pending.

No open issues 🎉

Review effort: Balanced

@ManthanVasani

Copy link
Copy Markdown
Author

Ben Hillis (@benhillis) Feng Wang (@chemwolf6922), could you please start the pipelines (/azp run) on this PR and review it?

The hang this PR mitigates still affects 3.0.3, the current stable release:

The global net.core.wmem_default/rmem_default workaround is not a safe substitute: those defaults are kernel-wide, and on SapphireHotS's machine (about 45 Docker bridge networks) it broke Docker Desktop. This PR sets the buffers only on WSL's own control and stdio listeners. SapphireHotS has offered to test a build.

Thank you.

@basvanbeeknl

Copy link
Copy Markdown

Another field report in favour of this per-listener approach, from a machine already running the global sysctl workaround.

Environment: WSL 3.0.1.0, kernel 6.18.40.1-microsoft-standard-WSL2, Ubuntu with systemd, Docker Engine inside WSL, uptime 8 days, many parallel terminal sessions.

Workaround in place: net.core.rmem_default=65536 and net.core.wmem_default=65536 via kernelCommandLine in .wslconfig, confirmed live on the running VM. We could not go lower globally: 14336 broke networked containers (no buffer space available on netlink) and 32768 stopped dockerd from starting. That is why a per-listener fix like this one matters to us.

What still happened: with order 6 and order 7 both empty in the Normal zone

Node 0, zone   Normal   2003   3361   1345    290      4      0      0      0      0      0      0

an interop call (cmd.exe from WSL) still failed with:

<3>WSL (802843 - ) ERROR: UtilAcceptVsock:281: accept4 failed 110

dmesg on that boot holds 49 page allocation failure lines. Dropping the page cache and compacting brought order 7 back from 0 to 184 free blocks, but with this many sessions it drains again.

So the global 65536 narrows the window but does not close it, and it cannot go lower without breaking Docker. Shrinking only init's listeners, as this PR does, is the fix we need. Would be great to see this reviewed.

@AnugrahWidya

Copy link
Copy Markdown

same here on a second machine, also running the global 65536 workaround (rmem_default/wmem_default via kernelCommandLine in .wslconfig).

WSL 2.7.8.0, kernel 6.18.33.1, docker engine 29.9.2 inside wsl, 16 GB ram. about 6h uptime.

no accept4 failed 110 yet this boot, but order 7 is already down to 1 free block:

Node 0, zone   Normal  75875  44435  10715   2718    868    349     88      1      0      0      0

and one hv_sock ring already failed at order 6, around 4h20m in:

kworker/0:2: page allocation failure: order:6, mode:0xdc0(GFP_KERNEL|__GFP_ZERO)
Workqueue: hv_pri_chan vmbus_add_channel_work
 vmbus_alloc_ring+0x78/0xd0
 vmbus_open+0x29/0x80
 hvs_probe+0x1f4/0x4c0

i think that's the plan 9 ring, since the other listeners only get 64 KB rings with this sysctl.

so the global setting helps for now, but not much room left after a few hours. would be nice to get this per listener fix merged.

@doublefx

Copy link
Copy Markdown

I would also benefit from the per-listener approach here. I run long-lived development agents in Ubuntu 24.04 on WSL2, with Windows interop and Docker Desktop. My setup has previously hit new-session/interop hangs with the accept4 failed 110 / VMBus allocation-failure pattern tracked in #40795.

On 15 November, my running kernel is 6.18.33.2-microsoft-standard-WSL2, and the read-only checks show:

net.core.rmem_default = 65536
net.core.wmem_default = 65536
vm.compaction_proactiveness = 20
vm.watermark_boost_factor = 15000

Those are mitigations, not a validation of this PR. My interop check currently succeeds; I have not built or tested this patch and am not claiming a new failure under today's settings.

I also reproduced a contributing Docker behaviour independently on 14 November: after booting without Docker, compaction was 20 and watermark boost 15000. Starting Docker Desktop 4.99 changed both to 0, and a targeted kernel trace captured initd-services writing 0 to the compaction handler. The watermark write was not separately traced. That is tracked separately in docker/desktop-feedback#809; I now use a narrow guard to restore the two zeroed values.

The listener-specific change is valuable because it avoids relying on smaller kernel-wide socket defaults shared with Docker, and I understand it does not fix every VMBus ring allocation.

Is an official candidate build available, or can the required CI/maintainer validation be identified so a build can be offered for controlled testing? I would need a maintenance window before testing a replacement WSL build; I do not want to interrupt the active workloads to apply an unvalidated patch.

@nicezic

Copy link
Copy Markdown

📌 Still reproduces on WSL 3.0.5.0 / kernel 6.18.58.1, and freeing memory did not help

Two points the earlier field reports (all ≤ 3.0.3) do not cover:

  1. ✅ Newer release: same failure on WSL 3.0.5.0 / 6.18.58.1-microsoft-standard-WSL2.
  2. 🧹 Releasing memory does not restore order-7: after 1.4 GiB of tmpfs was freed, order-7 ring allocations kept failing.

🔁 What happens

flowchart TD
    A["Host opens connection<br/>(terminal tab, interop)"] --> C{"512 KiB contiguous<br/>(order-7) free?"}
    C -- yes --> G["✅ session opens"]
    C -- no --> D["order:7 alloc failure<br/>offer dropped"]
    D --> F["accept4 failed 110<br/>⏱️ 10–30 s hang"]
Loading

🖥️ Environment

Windows 11, build 10.0.26300.9974
WSL / kernel 3.0.5.0 / 6.18.58.1
Guest Ubuntu + systemd, native Docker Engine 29.9.3 (no Docker Desktop)
.wslconfig memory=14GB, swap=8GB, processors=10, networkingMode=mirrored, autoMemoryReclaim=gradual
Kernel page_reporting.page_reporting_order=5, net.core.wmem_default=212992 (no sysctl workaround)

📊 Observations (VM up since 11-11 17:36, ~8 days)

  • ⏱️ A Windows Terminal WSL tab stalled ~30 s: order:7 failure at 09:47:09 → UtilAcceptVsock:281: accept4 failed 110 at 09:47:43.
  • 🔂 Launching cmd.exe from WSL reproduced it, with a ~10 s interop timeout.
  • 📈 The first failure came ~2 h after boot. Today's dmesg window alone has 27 failures (09:47–11:44). The journal has 6 accept4 failed 110 entries, one from a systemd service that calls a Windows binary.
  • 💾 MemAvailable was ~9–10 GiB throughout, so this is fragmentation, not exhaustion.

🧹 Freeing memory did not help

Time Event
09:47 ❌ order-7 failures begin
10:52 🧹 /tmp tmpfs freed: 1.4 GiB → 33 MiB
11:40–11:44 ❌ 4 more order-7 failures

After the cleanup, /proc/buddyinfo still showed only 9 free order-7 blocks in Normal. On a long-running VM, releasing memory in bulk does not reliably rebuild order-7 blocks. Asking for less, as this PR does by sizing the listener rings to order-4, avoids the problem instead of waiting for compaction.

👍 +1 for running the pipelines and getting this reviewed.

Drafted with Claude Code from local logs on the affected machine.

@chemwolf6922

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@emersonbusson

EMERSON BUSSON (emersonbusson) commented Nov 24, 2026 •

Copy link
Copy Markdown

This PR is a solid userspace mitigation for existing kernels (bringing host-opened listener rings down from order-7 to order-4). As noted in the description and comments above, high-order contiguous allocations (including order-4 listeners and order-6 Plan 9 rings) can still fail once buddy fragmentation sets in.

As a complementary kernel-side fix, I just sent v3 of the upstream VMBus series to linux-hyperv:

What changed between v2 and v3 (addressing maintainer feedback)

Wei Liu and Michael Kelley rightly pushed back on v2: it had ballooned to 14 patches (+4,515 / -427 lines) mixing VMBus ring allocation, unrelated hv_netvsc fixes, and a large KUnit test suite, with overly long AI-style commit descriptions that made review expensive.

For v3, I stripped the series down and reworked it around their feedback:

  1. Scope and size: Reduced to 3 focused VMBus-only patches (+271 / -327, net -56 lines):
    • Encapsulate buffer and GPADL teardown/leak state in struct vmbus_buffer.
    • Switch vmbus_alloc_ring() from contiguous alloc_pages_exact() to order-0 alloc_pages_bulk_array() + vmap() (updating uio_hv_generic mmap handling accordingly), removing the need for high-order contiguous ring blocks completely.
    • Switch vmbus_requestor metadata allocation to kvcalloc().
  2. Subsystem split & KUnit removal: Dropped the large KUnit suite from the submission and split the independent hv_netvsc fixes (DMA partial-map unwind, RNDIS request lifetime/HALT DMA leak, send-completion requestor validation, XDP unreg guard, atomic ethtool counters, and kvzalloc_obj()) into small net/net-next follow-ups held until v3 review settles.
  3. Review fixes: Kept the hv_netvsc revoke-failure guard so a failed revoke packet does not trigger a protocol-violating GPADL teardown, freed buffer->chunks on the GPADL leak path, fixed 32-bit i << PAGE_SHIFT shift width, and rewrote the cover letter and commit logs concisely around the actual failure mode.

Quick WSL2 6.18.64.1 backport note

I also backported this onto linux-msft-wsl-6.18.64.1 (including adapting drivers/hv/dxgkrnl/ to struct vmbus_buffer) and am running it live on WSL2 (6.18.64.1-microsoft-standard-WSL2+) with /dev/dxg active:

Across ~106–121 VMBus channels (357–363 vmbus/hv_ringbuffer vmalloc entries) and heavy guest memory/swap pressure, there have been zero page allocation failure or accept4 failed 110 events.

Having PR #41690 in WSL init still helps users on unpatched kernels right away, while the VMBus order-0 ring change removes the contiguous-order ceiling on the kernel side.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants