Rust-for-Linux / linux

Adding support for the Rust language to the Linux kernel.
https://rust-for-linux.com
Other
3.83k stars 399 forks source link

TCP CCAs in Rust #1062

Open vobst opened 4 months ago

vobst commented 4 months ago

Hi all!

I've been experimenting with writing TCP congestion control algorithms (CCAs) in Rust. These patches contain abstractions for writing modules that define a single CCA, a minimal proof-of-concept CCA, and a reimplementation of BIC (the predecessor of the CUBIC algorithm that is the default choice in the kernel).

The end goal of this work is to eventually have a new CCA, i.e., one with no current upstream implementation, implemented in Rust at some point in the (probably distant) future. With that in mind, I'd appreciate if you could give my abstraction design a close look. I'm happy about all kinds of feedback (design, structure, implementation, comments, docs,...) but since this is a pretty early stage, high-level things may be more useful that tiny details :) (Note: The relevant patches are the last three.)

By now, I've been using these patches for a few days on my host system (these very characters are sent on a connection that uses bic_rust ;) ), but I lack the knowledge/setup to perform proper testing against the C implementation in a lab setup; I'd appreciate some help/suggestions on that. For what it helps, here is an Arch Linux package that the Arch-users among you can use to easily build a kernel package for your host system.

In general, these choices select Rust BIC as the default for all connections:

Symbol: RUST_TCP_ABSTRACTIONS [=y]                                                                                              │
  │ Type  : bool                                                                                                                    │
  │ Defined at net/ipv4/Kconfig:469                                                                                                 │
  │   Prompt: TCP: Rust abstractions                                                                                                │
  │   Depends on: NET [=y] && INET [=y] && RUST [=y]                                                                                │
  │   Location:                                                                                                                     │
  │     -> Networking support (NET [=y])                                                                                            │
  │       -> Networking options                                                                                                     │
  │         -> TCP/IP networking (INET [=y])                                                                                        │
  │ (1)       -> TCP: Rust abstractions (RUST_TCP_ABSTRACTIONS [=y])
Symbol: TCP_CONG_BIC_RUST [=y]                                                                                                  │
  │ Type  : tristate                                                                                                                │
  │ Defined at net/ipv4/Kconfig:505                                                                                                 │
  │   Prompt: Binary Increase Congestion (BIC) control (Rust rewrite)                                                               │
  │   Depends on: NET [=y] && INET [=y] && TCP_CONG_ADVANCED [=y] && RUST_TCP_ABSTRACTIONS [=y]                                     │
  │   Location:                                                                                                                     │
  │     -> Networking support (NET [=y])                                                                                            │
  │       -> Networking options                                                                                                     │
  │         -> TCP/IP networking (INET [=y])                                                                                        │
  │           -> TCP: advanced congestion control (TCP_CONG_ADVANCED [=y])                                                          │
  │ (4)         -> Binary Increase Congestion (BIC) control (Rust rewrite) (TCP_CONG_BIC_RUST [=y])
  │ Symbol: DEFAULT_BIC_RUST [=y]                                                                                                   │
  │ Type  : bool                                                                                                                    │
  │ Defined at net/ipv4/Kconfig:709                                                                                                 │
  │   Prompt: Bic (Rust)                                                                                                            │
  │   Depends on: <choice>                                                                                                          │
  │   Visible if: <choice> && TCP_CONG_BIC_RUST [=y]=y                                                                              │
  │   Location:                                                                                                                     │
  │     -> Networking support (NET [=y])                                                                                            │
  │       -> Networking options                                                                                                     │
  │         -> TCP/IP networking (INET [=y])                                                                                        │
  │           -> TCP: advanced congestion control (TCP_CONG_ADVANCED [=y])                                                          │
  │             -> Default TCP congestion control (<choice> [=y])                                                                   │
  │ (2)           -> Bic (Rust) (DEFAULT_BIC_RUST [=y])

And these sysctl knobs can be used to set it at runtime:

$ cat /proc/sys/net/ipv4/tcp_available_congestion_control
reno bic bic_rust cubic my_cca
$ echo bic_rust | sudo tee /proc/sys/net/ipv4/tcp_congestion_control

Note: There are a bunch of print statements that are obviously not intended to remain there forever, but I helps to see the algorithm "at work".