mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 19:11:53 +07:00
[GH-ISSUE #6378] AmneziaWG: would an opt-in kernel-module datapath be considered? #4329
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#4329
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @YoungReckless4 on GitHub (Aug 31, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/6378
PR #6105's update from 2026-08-21 explains why the DKMS module was dropped in favour of embedding
amneziawg-goover gVisor, and the reasoning is sound. I'd like to ask whether an opt-inkernel datapath, off by default, would be considered — because two of the three premises have moved
since that decision, and I have measurements.
I'm not asking you to take a large patch sight-unseen. I have a working implementation running in
production, but I'd rather hear whether there's any appetite before proposing anything.
What has changed
The protocol lag is closed. The PR notes the 3.1 parameter set landed in
amneziawg-go/amneziawg-tools"well before the kernel module + DKMS package caught up". The kernel module is nowat
v3.1.20260828and supports the full 3.1 set. I verified this on a live interface —awg showreports
s3,s4,content padding addition,random trailers: on,disable cookies: on, andawg-quick strip | awg setconfacceptsH1..H4 = 1..4as the panel's own client emitters writethem:
(values above are illustrative, not from a live deployment)
The throughput tradeoff does not hold for a bulk-transfer profile. The PR says the gap was
measured and "judged acceptable for this protocol's realistic usage pattern (many lower-throughput,
latency-bound connections, not sustained bulk transfer)". That is a fair call for the common case,
but it is the wrong side of the tradeoff for anyone whose users actually pull large files.
Measured on the same host, same inbound, same clients, same port and the same 3.1 parameters — only
the datapath differs (1 vCPU QEMU, Debian 13, kernel 7.1.11-x64v3-xanmod1):
amneziawg-go+ gVisor)Single-stream on the embedded path sat at 50–86 Mbit/s while the core was 80% idle, so it is not
simply CPU-bound — the userspace path costs both throughput and headroom.
What it would cost, honestly
Your installer-fragility argument is the one I'd defend rather than dispute — I hit it directly:
LLVM=1and it faileduntil
clang/lld/llvmwere installed;setup_udp_tunnel_sock/udp_tunnel_sock_releaseto takestruct sock *,so the module needs a four-call source patch to build at all;
Secure Boot remains a hard stop. All of that argues for keeping the embedded path as the default and
gating the kernel one behind a host-readiness check that refuses to enable it when the module,
tools or nftables are missing.
The second cost is structural: a kernel interface never reaches Xray, so per-client traffic
accounting, traffic limits and the IP limit all need a parallel path (per-peer counters from
awg show dump, limits enforced by removing the peer, andlimitIpreinterpreted as endpointroaming since there is no access log). That is real ongoing maintenance surface, and it is the part
I'd expect you to weigh most heavily.
The question
Would you consider an opt-in, off-by-default kernel datapath with a preflight gate, or is the
single-implementation simplicity worth more than the throughput to you? Either answer is useful —
if it's no, I'll keep it in a fork and stop there.
Separately, #6376 fixes a bug found while measuring this: the default MTU does not account for S4, so inbounds generated with S4 ≥ 21 fragment every full-size packet.
@github-actions[bot] commented on GitHub (Aug 31, 2026):
Whether to accept an opt-in kernel datapath is a maintainer call, not one I can make — so rather than guess at the answer, I checked your three premises against the tip of
mainand pulled out the constraints any such patch would have to satisfy. Two of them hold, one is weaker than it looks, and there is one confound in your measurement plus one cost bigger than the one you flagged.Where the tree actually stands
The kernel/DKMS path is gone, not deprecated.
internal/amneziawgis protocol shape only now (types.go:9: "narrowed to protocol-shape-only after the kernel-module (DKMS) + awg-quick"),internal/amneziawgnet/netstack.go:1-11owns the datapath, and there is noawg-quick/awg showshell-out anywhere outside doc comments. That landed in #6105 (merged 2026-08-24) and shipped in v3.7.0 (2026-08-24), so the code you would be adding back has exactly one release of distance from it.Premise 1 (protocol lag closed) — true, but not load-bearing
Your quote is accurate; it is from the #6105 body verbatim. But that argument only reopens the kernel option, it does not put pressure on the embedded one, because the panel no longer depends on anything installed on the host:
and the docs already say so —
docs/content/docs/en/config/amneziawg.mdx:66-70: "There is no host-side version requirement — the panel ships its own pinnedamneziawg-go, not whatever happens to be installed on the system." So "the module caught up" is a feasibility argument, not a necessity one. It is the weakest of your three.One small correction: the panel's emitters never write
H1..H4 = 1..4.generateHRanges(internal/amneziawg/params.go:112-127) starts atconst lo = 5— "values 1-4 are reserved for vanilla WireGuard message types" — andamneziawg.mdx:49documents the same rule.Premise 2 (throughput) — real, but there are now three numbers and they disagree
Nobody disputed the gap; #6105's own body calls it "a real, substantial gap on a single saturating stream". What is new is that your ratio is nothing like the PR's. Both, as measured:
I am not going to invent a reason for the disagreement. One documented difference is worth knowing though: the PR's embedded figure explicitly excludes the relay hop — "this number is the core tunnel datapath only (no SOCKS5-relay hop, which is the harder, more representative number but strictly lower)" — whereas yours necessarily includes it, since on
mainthere is no way to bypass it.The confound I would want removed before this decides anything
At the tip, every generated inbound gets
RandomTrailers = true(internal/amneziawg/params.go:94) together with very wide H ranges:generateHRangessplits the space belowawgHMax = 2147483647into four bands of(2147483647-5+1)/4 = 536870910and picks a random sub-range of at leasthMinWidth = 1000in each (params.go:14-19,112-127) — so a single generated H range can span up to ~12.5% of the uint32 space.In #6303 that exact combination was traced to
amneziawg-go's own receive-path classifier misclassifying full-size transport packets as handshakes, costing a proportional share of throughput. I could not readamneziawg-go's source from this checkout, so I am citing that analysis rather than confirming it — but if it holds, it is a property of the userspace implementation specifically. The kernel module is an independent implementation of the same classifier and would not necessarily pay it.That matters for your A/B: with the panel's generated defaults left in place on both sides, part of what you measured as "kernel vs. userspace datapath" may be a defect in the current default parameters that is being fixed independently (your own #6376 on the S4/MTU half, #6303 on the
RandomTrailers/H-range half). Re-running the same bench withRandomTrailersoff and narrow H ranges on both sides would separate the two, and if the gap collapses, the whole proposal costs a lot less to decline.The structural cost, corrected and enlarged
You have the shape of it right, and it is the part I would also weigh heaviest — but the mechanism is not what you described, and it reaches further than accounting.
The identity that makes all of this work is the SOCKS5 auth username, not a log:
SocksInboundSettings(relay.go:46) emits one account per client email, andinjectAmneziawgnetSocks(internal/web/service/xray.go:701-712) creates that inbound per enabled AmneziaWG inbound.The
limitIppoint specifically: there is no access log to reinterpret away from anymore.internal/web/job/check_client_ip_job.go:30-33— "The per-client IPs come from the core's online-stats API; no access log is involved" — andcollectFromOnlineAPIskips the run outright when that API is unavailable (:96-99, "there is no access-log fallback"). So a kernel interface would be displacing a gRPC online-stats path, not a log parser, and the same displacement also takes out sniffing, the Routing-page integration and the per-inbound online-client counts, which today are free for exactly the same reason (amneziawg.mdx:17-21).The constraint your write-up does not mention: multi-node
Every state-changing inbound op dispatches through
internal/web/runtime, and the AmneziaWG apply isruntime/local.go:58-93— it runs on whichever node holds the inbound. Server settings are a per-inbound JSON blob synced to nodes, so auseKernelDatapathbit stored inServerSettingswould be a cluster-wide flag landing on nodes whose host readiness differs; a node without the module would silently serve a dead inbound. A preflight gate would have to be a per-node capability, negotiated at sync time, not a per-inbound setting — which is a materially bigger change than the gate you described, and worth costing before anyone says yes.What I could not settle
Whether the throughput gap survives once the
RandomTrailers/H-range and S4/MTU defaults are corrected. One re-run of your own bench with those neutralised on both datapaths would settle it, and it is the single number that would most change how this proposal reads.Nothing here commits the project either way — that remains a maintainer decision, and this thread is the right place for it.
Verdict: Feature request
This reply was generated automatically; a maintainer may follow up.
@YoungReckless4 commented on GitHub (Aug 31, 2026):
Correction to the throughput figures above — the kernel row understated the result.
The 190 Mbit/s I quoted was the peak of a short run that ended before the transfer had
saturated the link. A sustained single-stream download of a 4 GB file — roughly a minute
of continuous transfer — ran at the client's full line rate:
483 Mbit/s through the tunnel, 501 Mbit/s on the host NIC at ~48k pps, with the single core
still 66% idle and softirq at 11.7%. That is the client's 500 Mbit line, not a server
limit — on the kernel path the datapath was not the bottleneck at all.
Against 124.6 Mbit/s peak on the embedded path for the same client, same line, same inbound
and the same 3.1 parameters, the gap is closer to 4x than the 1.5x implied above.
My earlier figure was wrong because I armed the sampler near the end of that transfer, saw
throughput fall away a few seconds later, and read it as rate limiting when the file had
simply finished downloading.
The installer-fragility and parallel-accounting costs described above are unchanged, and
remain the real trade-off to weigh.
@oracle-impl commented on GitHub (Sep 1, 2026):
+1
@YoungReckless4 commented on GitHub (Sep 1, 2026):
Controlled measurements, and two corrections to what I wrote above
This supersedes both the throughput table in the issue body (124.6 / 190.1 Mbit/s) and my earlier correction comment (483 Mbit/s). Those came from sampler windows that were not aligned to the transfers. The series below was taken with the sampler armed before each run started, on the same host, inbound, client, file and mirror, changing one thing at a time.
Two factual corrections first
H1..H4 = 1..4. They do not:generateHRangesfloors at 5 (const lo = 5, "values 1-4 are reserved for vanilla WireGuard message types"). I had that backwards.limitIpas needing to be "reinterpreted as endpoint roaming since there is no access log". The bot's correction above is right: per-client IPs come from the core's online-stats API, and identity comes from the per-client SOCKS5 account, not from a log.Host
1 vCPU (QEMU Virtual CPU 2.5+), 1.1 GB RAM, Debian 13, kernel 7.1.11-x64v3-xanmod1. RTT to the client ~53 ms, to the mirror 36 ms. One AmneziaWG inbound, 7 clients, MTU 1420 set explicitly, S4 = 12, H1..H4 empty, RandomTrailers on, DisableCookies on.
That last line matters: neither cause diagnosed in #6303 applies here. H1..H4 are empty, so they are not written to UAPI at all and amneziawg-go uses its single-value defaults, which gives the
DeterminePacketTypeAndPaddingmisclassification from amnezia-vpn/amneziawg-go#183 nothing to match against. And with an explicit MTU of 1420 and S4 = 12 a full-size packet is 1492 bytes on the wire, under 1500, so the fragmentation from #6376 is not in play either. Whatever is measured below is a residual after both of those are excluded.Method
Client: one download of
debian-13.6.0-amd64-DVD-1.isofrom cdimage.debian.org (redirected to umu.se), one browser download, single TCP connection, roughly 60 to 130 s of transfer per run. Server:/proc/net/devsampled every 2 s. Reported figure iseth0 tx, because the embedded path has no kernel interface to sample. In kernel modeeth0 txtrackedawg1 txto within about 4% (encapsulation overhead), so it slightly flatters every row equally. All figures recomputed from the raw logs, mean over samples above 20 Mbit/s.Between runs only the panel binary changed, plus deleting the kernel interface so the embedded device could bind the port:
tunQueueDepth1024)tunQueueDepth8192, nothing else changedTCPSendBufferSizeRangeOption/TCPReceiveBufferSizeRangeOption4 MB default, 16 MB max,TCPModerateReceiveBufferOptionon, queue back at 1024B, C and D are indistinguishable. The client's own readout during A was 500 Mbit/s, which is that line's rate.
Where the drop happens, measured from the server itself
With the embedded build running, three
curlruns of the same URL from the host, 15 s each:--socks5 127.0.0.1:65101 --proxy-user <email>:<pass>(credentials frombin/config.json), no tunnelXray and the SOCKS5 relay hop are not the ceiling. The drop is entirely inside the gVisor + amneziawg-go path. This is the part I would most like others to reproduce, because it takes three commands and no client: it tells you whether your own ceiling is the link, Xray, or the tunnel.
What this rules out on this host, and what it does not settle
Ruled out: CPU (the single core was never below 50% idle in any embedded run),
tunQueueDepthfor a single stream, TCP buffer sizing, CUBIC vs Reno (tried earlier, no change), the H-range classifier, MTU/S4, Xray, the relay.Not settled: the mechanism. I have named three causes over the course of this thread and been wrong each time, so I am not offering a fourth. The shape of the data (a hard ceiling with the core mostly idle) says the path is blocking on something rather than computing, and that is as far as the evidence goes.
Scope. Single stream only. #6330 targets 20 to 28 concurrent flows and measured
SlowStartRetransmitsthere; run C does not test that claim and should not be read as evidence about it. The diagnosis in #6303 and the fixes in #6330 are @kuzzrus's work, and this residual is separate from what they found.How this bears on the question in the issue
In #6105 the maintainer wrote: "Userspace netstack vs. kernel module is the only trade-off that would change my mind here." The number given in reply, on real hardware, was 296 Mbit/s up and 640 Mbit/s down for the embedded path against 414.69 MB/s for the kernel module on the same box, "roughly 5-10x below the kernel module's own ceiling", and explicitly "the core tunnel datapath only (no SOCKS5-relay hop, which is the harder, more representative number but strictly lower)".
The ratio here is 7.8x, inside that range, with the relay hop included and separately shown not to be the bottleneck. What differs is the absolute number. 640 Mbit/s on real hardware was reasonably judged not a practical bottleneck; 57 Mbit/s on a 1 vCPU VPS is one, for any client on a faster line than that. The ratio looks hardware-independent across these two measurements; whether the absolute figure lands somewhere tolerable depends entirely on the host, and a single-vCPU VPS is a common host for this panel.
The costs listed in the body are unchanged: DKMS fragility, a parallel accounting path outside Xray, and the multi-node point the bot raised, that readiness would have to be a per-node capability rather than a per-inbound setting. Nothing here asks for a decision. It is the measurement the original question was missing.
One request. If anyone has an embedded AmneziaWG inbound on a multi-core box, the three server-side commands above take a few minutes and would show whether the absolute ceiling scales with cores. That is the one number this thread still lacks.