Skip to content

feat(linux): try to set rmem_max and wmem_max on startup - #10349

Merged
thomaseizinger merged 15 commits into
mainfrom
fix/increase-gateway-buffer-size
Sep 17, 2025
Merged

thomaseizinger merged 15 commits into
mainfrom
fix/increase-gateway-buffer-size

Conversation

@thomaseizinger

@thomaseizinger thomaseizinger commented Sep 15, 2025 •

Copy link
Copy Markdown
Member

The default send and receive buffer sizes on Linux are too small (only ~200 KB). Checking nstat after an iperf run revealed that the number of dropped packets in the first interval directly correlates with the number of receive buffer errors reported by nstat.

We already try to increase the send and receive buffer sizes for our UDP socket but unfortunately, we cannot increase them beyond what the system limits them to. To workaround this, we try to set rmem_max and wmem_max during startup of the Linux headless client and Gateway. This behaviour can be disabled by setting FIREZONE_NO_INC_BUF=true.

This doesn't work in Docker unfortunately, so we set the values manually in the CI perf tests and verify after the test that we didn't encounter any send and receive buffer errors.

It is yet to be determined how we should deal with this problem for all the GUI clients. See #10350 as an issue tracking that.

Unfortunately, this doesn't fix all packet drops during the first iperf interval. With this PR, we now see packet drops on the interface itself.

@vercel

vercel Bot commented Sep 15, 2025 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
firezone Ready Ready Preview Comment Sep 17, 2025 10:52pm

@thomaseizinger thomaseizinger changed the title feat(gateway): try to set rmem_max and wmem_max on startup feat(linux): try to set rmem_max and wmem_max on startup Sep 15, 2025
@thomaseizinger
thomaseizinger marked this pull request as ready for review September 15, 2025 01:17

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.

Pull Request Overview

This PR implements automatic tuning of Linux kernel UDP buffer sizes on startup to improve network performance. The default Linux send and receive buffer sizes are too small (~200KB), causing packet drops that correlate with receive buffer errors.

Key changes:

  • Automatically sets net.core.rmem_max and net.core.wmem_max kernel parameters on startup for Linux headless client and Gateway
  • Increases buffer sizes from 1MB/10MB to 16MB/128MB for send/receive respectively
  • Adds FIREZONE_NO_INC_BUF environment variable to disable this behavior

Reviewed Changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
rust/headless-client/src/main.rs Adds buffer size tuning logic and CLI option to headless client
rust/gateway/src/main.rs Adds buffer size tuning logic and CLI option to Gateway
rust/connlib/socket-factory/src/lib.rs Increases default buffer size constants
rust/headless-client/Cargo.toml Adds socket-factory dependency
website/src/app/kb/deploy/gateways/readme.mdx Updates documentation with new buffer tuning behavior
.github/workflows/ci.yml Updates CI to manually set buffer sizes and check for UDP errors

Comment thread rust/headless-client/src/main.rs Resolved
Comment thread rust/gateway/src/main.rs Resolved
@thomaseizinger
thomaseizinger force-pushed the fix/increase-gateway-buffer-size branch from 4cb5011 to c8453f0 Compare September 15, 2025 02:15
Comment thread .github/workflows/ci.yml Outdated

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I've guarded this on TCP tests because only those have flow-control.

@klochowicz klochowicz 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.

looks good, just a couple of nitpicks.

Comment thread rust/gateway/src/main.rs Resolved
Comment thread rust/gateway/src/main.rs Outdated

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.

I find it way easier to parse & think about flags when they're formed in positive way, like even as as an end user I'd rather configure INCREASE_BUFFER=0 or TELEMETRY=false (btw: does clap parse true and false from these well? ). some goes for code, it's easier to read.

then again, you're just conforming to existing convention here, so feel free to ignore this comment. :)

Comment thread rust/headless-client/src/main.rs Outdated
Comment on lines 228 to 233

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.

perhaps extract common function?

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.

I would add a warning that nowother processes on the system can request larger buffers as well, which can have an impact on overall performance if they do.

(perhaps redundant if we applied the suggestion above)

@jamilbk jamilbk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just want to verify since this is a somewhat substantial system-wide change there won't be any undesired side effects that might cause an issue?

@thomaseizinger

Copy link
Copy Markdown
Member Author

Just want to verify since this is a somewhat substantial system-wide change there won't be any undesired side effects that might cause an issue?

To be honest, the only thing I can say here is "time will tell"? It is only changing the max values, not the default so unless a program is requesting larger buffers, there should be no difference.

@thomaseizinger
thomaseizinger force-pushed the fix/increase-gateway-buffer-size branch from c7eb7d1 to 3171079 Compare September 17, 2025 22:51
@thomaseizinger
thomaseizinger added this pull request to the merge queue Sep 17, 2025
Merged via the queue into main with commit 3e6094a Sep 17, 2025

This branch was successfully deployed

1 active deployment
Preview — 3171079d Deployed Sep 17, 2025 by vercel[bot]
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.

5 participants