Repository navigation
Reduce chain generation and loading time - #625
Merged
Merged
Conversation
Prevent bpfilter from polluting the benchmark output by increase the default log level during benchmarking to warning.
The userspace benchmarks currently focus on sets loading time (single rule, large set). This change introduces a new benchmark to evaluate the full generation and loading duration for a larger chain. The benchmarked chain has 1000 rules, 4 sets of various size, uses logging and counters. This will be used as a baseline for reducing the duration of the program generation.
Replace the serialization round trip with direct copies of chains and sets to avoid temporary pack buffers and serialization overhead. Add copy constructors for rules and matchers to preserve configuration and independently owned payloads. Reserve space for sets and their elements before copying them. Preserve the existing reset of runtime counters. Use the chain API to add copied rules, validate set references, and recalculate derived state. Leave the destination unchanged if copying fails.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Reduce the work done to generate and load a chain, and add a benchmark to measure it.
bf_chain_set()on a chain of 1000 rules with counters. 4 rules matchip4.saddragainst sets of 8, 65,536, or 1,048,576 elements. The other 996 rules each match one randomip4.saddr, and one of them logs. The benchmarks now set the log level to warning, so bpfilter's info logs don't appear in the benchmark output.bf_cgen_load()callsbf_cgen_dump()only when debug logging is enabled. Before, every load called it, whatever the log level.log_level = 1, even without a buffer. A load that fails without logs is retried with a log buffer, so the error still includes the verifier output.bf_rule_new_from_copy()andbf_matcher_new_from_copy()copy rules and matchers.bf_btf_teardown(). The code generator looks up a BTF ID for every kfunc call it emits.Related issue
None. The new benchmark measures how long
bf_chain_set()takes to generate and load a large chain, and the other commits remove work from that path.Testing
Full test suite passed.
Benchmark results before and after the changes:
chain_set__ip4_saddr__x_elem_set/8chain_set__ip4_saddr__x_elem_set/65536chain_set__ip4_saddr__x_elem_set/1048576chain_set__1000_ip4_saddr__x_elem_sets_c_l/8chain_set__1000_ip4_saddr__x_elem_sets_c_l/65536chain_set__1000_ip4_saddr__x_elem_sets_c_l/1048576Notes for the reviewer
bf_btf_setup()now fails with-EBUSYwhen BTF is already loaded. Before, a second call replaced the loaded BTF without freeing it.AI disclosure
Peer programming with Claude.
Checklist
make -C $BUILD test_bin testpasses and the code follows the style guidecomponent: subcomponent: short description