Skip to content

Conversation

@RubenKelevra
Copy link
Contributor

@RubenKelevra RubenKelevra commented Aug 16, 2025

Set net.ipv4.tcp_thin_linear_timeouts=1 to switch retransmission timeout (RTO) backoff from exponential to linear for 'thin' TCP flows. This reduces tail latency for API-style connections that typically have very few packets in flight, improving recovery from sporadic loss without changing anything for larger TCP transfers.

Kernel definition: A flow is considered thin when tp->packets_out < 4 and while not in the initial slow start.

See tcp_stream_is_thin(tp) in include/net/tcp.h.

Summary by CodeRabbit

  • New Features
    • Enabled a system-level TCP option that applies linear timeout behavior for “thin” TCP streams, improving handling of low-throughput connections.
  • Documentation
    • Added descriptive configuration comments documenting the new TCP behavior for easier maintenance and clarity.

@coderabbitai
Copy link

coderabbitai bot commented Aug 16, 2025

📝 Walkthrough

Walkthrough

Adds a sysctl configuration block enabling thin TCP linear timeouts by inserting net.ipv4.tcp_thin_linear_timeouts = 1 (with explanatory comments) into the network sysctl file; no existing lines were removed or modified.

Changes

Cohort / File(s) Summary of Changes
Sysctl network tuning
buildroot-external/rootfs-overlay/usr/lib/sysctl.d/20-network.conf
Inserted comments and the setting net.ipv4.tcp_thin_linear_timeouts = 1 after net.core.wmem_max = 4194304; no other lines changed or removed.

Sequence Diagram(s)

Not applicable — configuration-only change; no control-flow or runtime interaction modifications to diagram.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge Base: Disabled due to data retention organization setting

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between f20619e and 1dd4d61.

📒 Files selected for processing (1)
  • buildroot-external/rootfs-overlay/usr/lib/sysctl.d/20-network.conf (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • buildroot-external/rootfs-overlay/usr/lib/sysctl.d/20-network.conf
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
buildroot-external/rootfs-overlay/usr/lib/sysctl.d/25-thin-tcp.conf (2)

1-2: Enrich the comment with context and a reference to the kernel definition

Helps future maintainers understand scope (“thin” = packets_out < 4) and rationale at a glance.

Apply this diff to expand the header comment:

-# Enable linear timeouts for thin TCP streams
+# Enable linear RTO backoff for "thin" TCP streams.
+# "Thin" per kernel: tp->packets_out < 4 and not in initial slow start.
+# Ref: tcp_stream_is_thin(tp) in include/net/tcp.h
+# Rationale: reduce tail latency for API-style connections after sporadic loss.
 net.ipv4.tcp_thin_linear_timeouts = 1

2-2: Optional: Consider also enabling tcp_thin_dupack for thin flows

If your goal is to further improve recovery on thin flows, enabling fast retransmit after 1 dup-ack for thin streams (tcp_thin_dupack) can help on high-loss/latency links. It’s a broader behavior change; evaluate carefully before adopting.

Potential addition:

 net.ipv4.tcp_thin_linear_timeouts = 1
+net.ipv4.tcp_thin_dupack = 1
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 06b55a6 and a2919bd.

📒 Files selected for processing (1)
  • buildroot-external/rootfs-overlay/usr/lib/sysctl.d/25-thin-tcp.conf (1 hunks)
🔇 Additional comments (2)
buildroot-external/rootfs-overlay/usr/lib/sysctl.d/25-thin-tcp.conf (2)

2-2: LGTM: Enabling linear RTO for thin TCP flows is reasonable and low-risk

This aligns with the stated objective and should help reduce tail latency on API-style connections with very small inflight windows. Syntax and placement under /usr/lib/sysctl.d are correct for systemd-sysctl.


2-2: Confirm kernel config and no duplicate overrides

  • Verified no other occurrences of net.ipv4.tcp_thin_linear_timeouts outside of
    buildroot-external/rootfs-overlay/usr/lib/sysctl.d/25-thin-tcp.conf:2.
  • No CONFIG_TCP_THIN_LINEAR_TIMEOUTS references found in this repo; please ensure your kernel build enables this option so the sysctl takes effect.

@RubenKelevra RubenKelevra force-pushed the feat/thin-tcp-linear-rto branch from a2919bd to d0a3d8a Compare August 16, 2025 18:42
@RubenKelevra
Copy link
Contributor Author

The first suggestion by code rabbit makes sense, I've added more details to the file's comment.

The second suggestion doesn't make any sense, because this option was removed from the Linux-Kernel 4.11 - commit 4a7f600944114.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
buildroot-external/rootfs-overlay/usr/lib/sysctl.d/25-thin-tcp.conf (2)

1-4: Good rationale; add the canonical source link and a brief scope note.

Inline the exact kernel link for traceability and clarify that non-thin flows remain unchanged.

 # Ref: tcp_stream_is_thin(tp) in include/net/tcp.h
+# Link: https://github.com/torvalds/linux/blob/90d970cade8e67e20b09bbfdc2f0b52064322921/include/net/tcp.h#L2231
 # Rationale: reduce tail latency for API-style connections after sporadic loss.
+# Note: Non-thin flows retain the default exponential RTO backoff; this only affects streams where tcp_stream_is_thin(tp) is true.

1-7: Optional: Consider enabling tcp_thin_dupack for even faster loss recovery on thin flows.

This complements linear RTO by retransmitting on the first dupack for thin streams, which can further reduce tail latency for sparse API-style exchanges. Caveat: slightly more sensitive to reordering on certain networks.

 # Rationale: reduce tail latency for API-style connections after sporadic loss.
+# Optional: Retransmit on first dupack for thin streams (can further reduce tail latency).
+# Caveat: More sensitive to reordering on some links.
+# See: net.ipv4.tcp_thin_dupack (Documentation/networking/ip-sysctl)
 
 net.ipv4.tcp_thin_linear_timeouts = 1
+## Uncomment to enable more aggressive dupack behavior for thin streams
+# net.ipv4.tcp_thin_dupack = 1
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between a2919bd and d0a3d8a.

📒 Files selected for processing (1)
  • buildroot-external/rootfs-overlay/usr/lib/sysctl.d/25-thin-tcp.conf (1 hunks)
🔇 Additional comments (1)
buildroot-external/rootfs-overlay/usr/lib/sysctl.d/25-thin-tcp.conf (1)

6-6: LGTM: Enable linear RTO for thin streams – Verified no other instances of net.ipv4.tcp_thin_linear_timeouts or other thin-TCP settings across the repo; this is a safe, scoped tuning.

Set net.ipv4.tcp_thin_linear_timeouts=1 to switch retransmission
timeout (RTO) backoff from exponential to linear for 'thin' TCP flows.
This reduces tail latency for API-style connections that typically have
very few packets in flight, improving recovery from sporadic loss without
changing anything for larger TCP transfers.

Kernel definition: A flow is considered thin when 'tp->packets_out < 4'
and while not in the initial slow start.

See tcp_stream_is_thin(tp) in include/net/tcp.h.
@RubenKelevra RubenKelevra force-pushed the feat/thin-tcp-linear-rto branch from d0a3d8a to f20619e Compare August 16, 2025 20:36
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
buildroot-external/rootfs-overlay/usr/lib/sysctl.d/20-network.conf (1)

9-13: Tighten wording and add a permalink to the kernel helper for future maintainers

Minor doc nit: the helper checks “not in slow start” (not specifically “initial”). Including a stable permalink makes the intent auditable later.

-# "Thin" per kernel: tp->packets_out < 4 and not in initial slow start.
-# Ref: tcp_stream_is_thin(tp) in include/net/tcp.h
-# Rationale: reduce tail latency for API-style connections after sporadic loss.
+# "Thin" per kernel: tp->packets_out < 4 and not in slow start.
+# Ref: tcp_stream_is_thin(tp) in include/net/tcp.h:
+# https://github.com/torvalds/linux/blob/90d970cade8e67e20b09bbfdc2f0b52064322921/include/net/tcp.h#L2231
+# Rationale: reduce tail latency for API-style connections after sporadic loss; no effect on larger transfers.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between d0a3d8a and f20619e.

📒 Files selected for processing (1)
  • buildroot-external/rootfs-overlay/usr/lib/sysctl.d/20-network.conf (1 hunks)
🔇 Additional comments (1)
buildroot-external/rootfs-overlay/usr/lib/sysctl.d/20-network.conf (1)

14-14: Verification Complete: No Conflicts and Broad Kernel Support Confirmed

  • No other occurrences or overrides of net.ipv4.tcp_thin_linear_timeouts found in the repo.
  • Confirmed present and not deprecated in Linux 6.1, 6.6, 6.10 (and later) kernels per kernel docs and source.

LGTM—enabling linear RTO for thin streams is a safe, targeted improvement.

Copy link
Member

@sairon sairon left a comment

Choose a reason for hiding this comment

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

I don't see this change as aggressive as #4239 (as it only changes behavior for thin streams) but I have similar concerns as I raised in the other issue.

Eventually, any sysctl parameters can be changed by power users who know what they're doing via override in /etc/sysctl.d/ (which is writable on HAOS) but to make the change global, I'd like to see some measurable impact to be convinced the RFC violation is worth it.

@RubenKelevra
Copy link
Contributor Author

@sairon while technically true, it violates the compliance with RFC 6298, the positive effect of doing something like this has been proven in real world applications quite often and is implemented as TLP with SACK-enabled streams. While both approaches cannot be 1:1 compared, the idea behind both is very similar. TLP is enabled by default in the Linux kernel.

However, TLP's limitation of requiring RACK, which is requiring TCP SACK to work, makes it unavailable for non-SACK connections.

Non-SACK connections are extremely niche, so not much effort are put into them anymore to improve anything about them. The only use case are very small TCP stacks, like the one in embedded devices, which is why knobs like the linear timeout switch in the Linux kernel exists in the first place - there's no RFC but there's a need to improve the recovery time on latency sensitive non-SACK connections, because there's no TLP available.

Since Home Assistant is expected to communicate with a lot of embedded devices which do not support TCP SACK (all ESPHome devices for example come to mind here) enabling this setting does make sense IMHO. Especially since enabling it is not breaking any usecase.

@sairon
Copy link
Member

sairon commented Aug 26, 2025

Okay, that makes sense. Let's go with the change, I just remove the extra newlines in the file.

sairon
sairon approved these changes Aug 26, 2025
@sairon sairon merged commit 870baa9 into home-assistant:dev Aug 26, 2025
3 checks passed
@sairon sairon mentioned this pull request Aug 28, 2025
@RubenKelevra RubenKelevra deleted the feat/thin-tcp-linear-rto branch September 1, 2025 12:47
@sairon sairon mentioned this pull request Sep 8, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Sep 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants