97 Commits
Author SHA1 Message Date
Kevin KrakauerandgVisor bot 113b24b432 netstack: move TCP state to tcp package and cleanup probe
TCP probe support is implemented, unnecessarily, across the stack and and tcp
packages. It can live entirely in tcp. Additionally, it is only ever set at
initialization time, so support for dynamically adding/removing the probe isn't
necesary.

The probe is getting in the way of adding debugging for b/339664055.

PiperOrigin-RevId: 699330364
2024-11-22 17:11:04 -08:00
Nayana BidariandgVisor bot 50d46c627c Initiliaze rand variables after netstack is restored.
Add a afterLoad method on netstack.Stack to initialize rand variables after
netstack is restored.

PiperOrigin-RevId: 675278982
2024-09-16 13:59:04 -07:00
Andrei VaginandgVisor bot 0d20b827d2 netstack: implement bridge devices
Implement the core part. All packets are broadcast-ed to all ports. The next
step will be to implement forwarding and multicast group databases.

PiperOrigin-RevId: 644471256
2024-06-18 12:15:19 -07:00
Kevin KrakauerandgVisor bot 597bc5f90d netstack: remove timing and locking from GRO
Having read more GRO kernel code and NAPI, I believe the previous design was
overly complex and resulted in poor performance.

- Netstack GRO uses a `time.Timer` to periodically clear GRO'd packets. It's
  got... several problems.
  1. The timer can be configured via CLI flag with arbitrary granularity, but
    (IIUC) `time.Timer` relies on the netpoller, which [has millisecond
    granularity].
  2. The timer creates new goroutines when it fires.
  3. There's a complex atomic value song and dance to setting up the timer,
    canceling it when no packets are pending, and resuming it for incoming
    packets.
- Linux GRO doesn't quite work this way.
  - Typically, [Linux flushes GRO whenever it can] (unless running with high
    HZ; Go preempts goroutines every 10ms so this does not apply). IIUC,
    receiving packets triggers the scheduling of a softirq that batch reads as
    many packets from a device as possible. softirqs are run as kernel threads,
    so this is getting scheduled with jiffy-ish granularity.
  - There's no special scheduling of a timer to flush GRO.

In Netstack our "interrupt" is that we return from a poll, then we read
multiple packets at once via recvmmsg/readv/XDP. So we've already got a delay
analogous to "trigger a ksoftirq and wait for the thread to get scheduled."
Thus, we should use zero-timeout GRO that does the following:

- When recvmmsg/poll/etc returns a single packet, just pass it directly and
  immediately up the stack.
- When multiple packets are returned, coalesce them with GRO and flush them
  without waiting. We never have 1000+ HZ situation.
- We can remove all atomics and locking from GRO, as there will be one
  `groDispatcher` per dispatcher goroutine and no timer-spawned goroutines to
  synchronize with.

**Performance**: The previous GRO implementation yielded a few percentage points
increase in performance. This is markedly better.

The following is from tcp_benchmark. It is running with host GRO/GSO disabled,
as there's nothing to GRO when the host does it for us. The RecvMMsg dispatcher
is used, as the PacketMMap dispatcher does not return multiple packets at once
(RecvMMsg averages 8 per syscall in these benchmarks).

```
                                              │ /tmp/old.log │            /tmp/new.log             │
                                              │     Mb/s     │    Mb/s      vs base                │
TCP/role=server/host-gso=false/host-gro=false    1.764k ± 2%   2.139k ± 2%  +21.29% (p=0.000 n=20)
```

PiperOrigin-RevId: 622366744
2024-04-05 21:48:37 -07:00
Fabricio VoznikaandgVisor bot 1676e8a877 Add restore context to netstack
PiperOrigin-RevId: 613295366
2024-03-06 12:04:24 -08:00
Jing ChenandgVisor bot be48200c0e Re-order loads in BUILD files to make transformations reversible in Copybara.
PiperOrigin-RevId: 598898756
2024-01-16 11:21:40 -08:00
Kevin KrakauerandgVisor bot 89d6bf18c8 have gVisor use renamed buffer package
PiperOrigin-RevId: 537209194
2023-06-01 21:27:49 -07:00
Kevin KrakauerandgVisor bot c3da0e4f0d Automated rollback of changelist 531020857
PiperOrigin-RevId: 532863869
2023-05-17 12:09:12 -07:00
Kevin KrakauerandgVisor bot d207727b3a netstack: replace slice-based PacketBufferList with linked list
This is effectively a rollback of cl/450976957. The original motivation never
panned out, and it's easier to work with the lists. They also are easier to
avoid allocations with.

PiperOrigin-RevId: 531020857
2023-05-10 15:43:59 -07:00
Kevin KrakauerandgVisor bot dd9a3d10bd netstack: change PacketBufferPtr back to *PacketBuffer
The benefits of PacketBufferPtr never materialized and it makes the type
difficult to work with, e.g. it can't be used with go_generics to make a
(performant) list.

This is effectively a rollback of cl/480518221.

PiperOrigin-RevId: 530954630
2023-05-10 11:16:28 -07:00
Adin ScannellandgVisor bot 1ceb814544 Add default_applicable_licenses rules to packages.
PiperOrigin-RevId: 513581243
2023-03-02 10:50:04 -08:00
Andrei VaginandgVisor bot 41009e886e stack/conntrack: suppress the nested locking warning
reapEverything intentionally takes the second bucket lock.

PiperOrigin-RevId: 495967790
2022-12-16 14:59:49 -08:00
gVisor bot 024b627d17 Merge pull request #8212 from avagin:addressStateRefs
PiperOrigin-RevId: 494016953
2022-12-08 15:55:10 -08:00
Andrei VaginandgVisor bot 2e0cc62d82 tcpip/stack: use lockdep mutexes
PiperOrigin-RevId: 493749454
2022-12-07 17:14:03 -08:00
Andrei Vagin 461a15be35 tcpip/stack: use atomic refs for addressState
In this case, we don't need to take a read-write lock in IncRef and DecRef.
2022-12-01 15:15:09 -08:00
Ayush RanjanandgVisor bot 175db901ca Replace pkg/refs with pkg/refsvfs2.
All VFS1 only bits have been deleted.

Updates #1624

PiperOrigin-RevId: 492273183
2022-12-01 12:46:11 -08:00
Kevin KrakauerandgVisor bot 619801c72a netstack: GRO
A 20,000 ns interval yields (depending on the run) a roughly 10-30% throughput
boost in the TCP benchmark. Under heavier load with more contention the boost
should be larger.

As noted in the TODOs, there are a large number of low-hanging optimizations to
be made. This CL just implements a simple form of GRO.

Tested via existing tests (there should be no user-visible behavior changes).
Unit tests coming in a child CL.

GRO is off by default and so users are unaffected unless they enable it
explicitly.

PiperOrigin-RevId: 489313603
2022-11-17 14:51:37 -08:00
Kevin KrakauerandgVisor bot 70d7f5033f netstack: setup basic structure for GRO
PiperOrigin-RevId: 487055867
2022-11-08 14:43:50 -08:00
Kevin KrakauerandgVisor bot 607fdc536d DecRef ptr niling
PiperOrigin-RevId: 480518221
2022-10-11 20:27:23 -07:00
Lucas ManningandgVisor bot 22ca20c0f1 Move checksum to its own package and optimize bufferv2 checksumming.
Checksum capabilities are logically separate from tcpip header definitions
and operations. It makes sense to extract this logic into its own package.
This is also necessary to avoid circular dependencies with bufferv2.

PiperOrigin-RevId: 473096480
2022-09-08 15:17:00 -07:00
Lucas ManningandgVisor bot 1f2b30d70c Refactor netstack to use bufferv2 instead of buffer.
This change has significant performance implications. bufferv2 is reference
counted and pooled, which alleviates heap/GC pressure. Below are the results
from running the iperf benchmark.

HEAD:
BenchmarkIperf/operation.Upload-16    1552  ns/op   46.6GiB total allocations
BenchmarkIperf/operation.Download-16  1114  ns/op   68.6GiB total allocations

w/ change:
BenchmarkIperf/operation.Upload-16    1139  ns/op (-27%)   1.41GiB total allocations (-97%)
BenchmarkIperf/operation.Download-16  753.2 ns/op (-33%)   706MiB  total allocations (-99%)

PiperOrigin-RevId: 462453185
2022-07-21 13:09:31 -07:00
Lucas ManningandgVisor bot e64458ff08 Remove VectorisedView everywhere.
PiperOrigin-RevId: 453471156
2022-06-07 10:36:23 -07:00
Lucas ManningandgVisor bot f175fb526f Move prependable to its own package.
#CodeHealth

PiperOrigin-RevId: 452099435
2022-05-31 11:39:06 -07:00
Lucas ManningandgVisor bot 6103b4b3b6 Replace VectorisedView in network endpoints.
PiperOrigin-RevId: 451267391
2022-05-26 16:25:30 -07:00
Nate HurleyandgVisor bot 006bbe78ca Implement IPv4 multicast forwarding.
This change implements AddMulticastRoute and the requisite routing logic.
Subsequent changes will still be needed to:

1. Emit events for missing route or unexpected input interface
2. Implement DelRoute
3. Implement GetRouteStats

Updates #7338.

PiperOrigin-RevId: 451026594
2022-05-25 15:18:13 -07:00