-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: optimize packet struct in DropReason plugin (#637)
Fixes #645 `DropReason::packet` struct is copied to and from the bpf perf array for each packet intercepted by the eBPF program for pod-level metrics, making it a prime target for improving throughput and latency. We can reduce its size `from 56 to 32 bytes` by: - removing unecessary padding, - unusued member fields, and - too large member types. Removing `14 bytes` of padding and `10 bytes` of unused member fields - new struct layout can be confirmed by looking at `pkg/plugin/dropreason/kprobe_bpfel_x86.go` ## Performance As measured with `k8s-netperf`, latency and throughput gain is unclear, due to large sample variance of 5-10%. To follow up with latency/throughput numbers in a packet drop-instensive scenario. ## Details on member fields changes: - `direction` is not currently used by this plugin - `skb_len` now matches `sk_buff::len` from `vmlinux.h` (4 vs. 8 bytes) - `drop_type` in `metrics_map_key` is very unlikely to need >65k different values, so can be reduced to a `uint16_t` - `metrics_map_key` is used both as a map key, and a wrapper struct for the `return_val` and `drop_type` fields in `struct packet` passed to the BPF perf array - the latter is not necessary and breaking it up combined with shrinking `drop_type` allows us to fit `proto` and `in_filtermap` in the new empty space; (just shrinking `drop_type` doesn't reduce size because of padding for nested structs: https://www.reddit.com/r/Compilers/comments/1dwmyus/would_replacing_a_nested_struct_by_its_members/) As additional reference, below is a sequence of changes I made to the `DropReason::packet` struct: 56B- baseline ``` uint32_t src_ip; uint32_t dst_ip; uint16_t src_port; uint16_t dst_port; uint8_t proto; uint64_t skb_len; direction_type direction; struct metrics_map_key key; uint64_t ts; // timestamp in nanoseconds bool in_filtermap; ``` 48B - reorder `in_filtermap` ``` uint32_t src_ip; uint32_t dst_ip; uint16_t src_port; uint16_t dst_port; uint8_t proto; bool in_filtermap; uint64_t skb_len; direction_type direction; struct metrics_map_key key; uint64_t ts; // timestamp in nanoseconds ``` 40B - remove `direction` + its padding ``` uint32_t src_ip; uint32_t dst_ip; uint16_t src_port; uint16_t dst_port; uint8_t proto; bool in_filtermap; uint64_t skb_len; struct metrics_map_key key; uint64_t ts; // timestamp in nanoseconds ``` 32B - shrink `skb_len` to match `sk_buff`, shrink `drop_type` to uint16_t from uint32_t, split up `metrics_map_key` ``` __u32 src_ip; __u32 dst_ip; __u16 src_port; __u16 dst_port; __u32 skb_len; __u32 return_val; __u16 drop_type; __u8 proto; bool in_filtermap; __u64 ts; // timestamp in nanoseconds ``` --------- Signed-off-by: Igor Klemenski <[email protected]>
- Loading branch information
1 parent
fae9250
commit 3eaa9fe
Showing
14 changed files
with
1,029 additions
and
1,022 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.