Skip to content

Commit

Permalink
Enhance conntrack map flexibility with CPU-based scaling
Browse files Browse the repository at this point in the history
Previously, BPFMapSizeConntrack was set to a fixed value, which lacked
flexibility across different spec of machines. Now, with the introduction
of BPFMapSizePerCPUConntrack, the conntrack map size can be adjusted
dynamically as BPFMapSizeConntrackPerCPU * (Number of CPUs). This allows
for larger map sizes on high-spec machines and smaller map sizes on
lower-spec machines, optimizing resource usage accordingly.

BTW, recently, we added several high-spec machines to the data center,
which led to the conntrack map size being filled up on these machines. It
could have been avoided with BPFMapSizePerCPUConntrack IMHO.

Suggested-by: Tomas Hruby <[email protected]>
Signed-off-by: Mingzhe Yang <[email protected]>
Co-Authored-By: Amaindex <[email protected]>
Co-Authored-By: Lance Yang <[email protected]>
  • Loading branch information
ioworker0 and Amaindex committed Jan 3, 2025
1 parent 5d7c855 commit 61369e6
Show file tree
Hide file tree
Showing 18 changed files with 136 additions and 1 deletion.
6 changes: 6 additions & 0 deletions api/pkg/apis/projectcalico/v3/felixconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,12 @@ type FelixConfigurationSpec struct {
// an entry for each active connection. Warning: changing the size of the conntrack map can cause disruption.
BPFMapSizeConntrack *int `json:"bpfMapSizeConntrack,omitempty"`

// BPFMapSizePerCPUConntrack determines the size of conntrack map based on the number of CPUs. If set to a
// non-zero value, overrides BPFMapSizeConntrack with `BPFMapSizePerCPUConntrack * (Number of CPUs)`.
// This map must be large enough to hold an entry for each active connection. Warning: changing the size of the
// conntrack map can cause disruption.
BPFMapSizePerCPUConntrack *int `json:"bpfMapSizePerCpuConntrack,omitempty"`

// BPFMapSizeConntrackCleanupQueue sets the size for the map used to hold NAT conntrack entries that are queued
// for cleanup. This should be big enough to hold all the NAT entries that expire within one cleanup interval.
// +kubebuilder:validation:Minimum=1
Expand Down
5 changes: 5 additions & 0 deletions api/pkg/apis/projectcalico/v3/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions api/pkg/openapi/generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions felix/config/config_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ type Config struct {
BPFMapSizeNATAffinity int `config:"int;65536;non-zero"`
BPFMapSizeRoute int `config:"int;262144;non-zero"`
BPFMapSizeConntrack int `config:"int;512000;non-zero"`
BPFMapSizePerCPUConntrack int `config:"int;0"`
BPFMapSizeConntrackCleanupQueue int `config:"int;100000;non-zero"`
BPFMapSizeIPSets int `config:"int;1048576;non-zero"`
BPFMapSizeIfState int `config:"int;1000;non-zero"`
Expand Down
1 change: 1 addition & 0 deletions felix/dataplane/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ func StartDataplaneDriver(
BPFMapSizeNATBackend: configParams.BPFMapSizeNATBackend,
BPFMapSizeNATAffinity: configParams.BPFMapSizeNATAffinity,
BPFMapSizeConntrack: configParams.BPFMapSizeConntrack,
BPFMapSizePerCPUConntrack: configParams.BPFMapSizePerCPUConntrack,
BPFMapSizeConntrackCleanupQueue: configParams.BPFMapSizeConntrackCleanupQueue,
BPFMapSizeIPSets: configParams.BPFMapSizeIPSets,
BPFMapSizeIfState: configParams.BPFMapSizeIfState,
Expand Down
8 changes: 7 additions & 1 deletion felix/dataplane/linux/int_dataplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ type Config struct {
BPFPSNATPorts numorstring.Port
BPFMapSizeRoute int
BPFMapSizeConntrack int
BPFMapSizePerCPUConntrack int
BPFMapSizeConntrackCleanupQueue int
BPFMapSizeNATFrontend int
BPFMapSizeNATBackend int
Expand Down Expand Up @@ -789,10 +790,15 @@ func NewIntDataplaneDriver(config Config) *InternalDataplane {
bpfmaps.DisableRepin()
}

bpfMapSizeConntrack := config.BPFMapSizeConntrack
if config.BPFMapSizePerCPUConntrack > 0 {
bpfMapSizeConntrack = config.BPFMapSizePerCPUConntrack * bpfmaps.NumPossibleCPUs()
}

bpfipsets.SetMapSize(config.BPFMapSizeIPSets)
bpfnat.SetMapSizes(config.BPFMapSizeNATFrontend, config.BPFMapSizeNATBackend, config.BPFMapSizeNATAffinity)
bpfroutes.SetMapSize(config.BPFMapSizeRoute)
bpfconntrack.SetMapSize(config.BPFMapSizeConntrack)
bpfconntrack.SetMapSize(bpfMapSizeConntrack)
bpfconntrack.SetCleanupMapSize(config.BPFMapSizeConntrackCleanupQueue)
bpfifstate.SetMapSize(config.BPFMapSizeIfState)

Expand Down
26 changes: 26 additions & 0 deletions felix/docs/config-params.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions felix/docs/config-params.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions manifests/calico-bpf.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions manifests/calico-policy-only.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions manifests/calico-typha.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions manifests/calico-vxlan.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions manifests/calico.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions manifests/canal.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions manifests/crds.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions manifests/flannel-migration/calico.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions manifests/operator-crds.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 61369e6

Please sign in to comment.