-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Policy mapstate cleanups redux #35305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jrajahalme
merged 7 commits into
cilium:main
from
jrajahalme:policy-mapstate-cleanups-redux
Oct 10, 2024
Merged
Policy mapstate cleanups redux #35305
jrajahalme
merged 7 commits into
cilium:main
from
jrajahalme:policy-mapstate-cleanups-redux
Oct 10, 2024
Conversation
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
5e16ef1
to
a70511f
Compare
ready for review |
/test |
…heck Deny all check it not necessary when we are already checking for covering deny entries. Clarify this by factoring out the common code from the deny/allow branches. Deny processing paths are now skipped when there are no deny rules, so we can also skip checking for deny feature. 'newKey' traffic direction sanity check is not needed any more as we no longer index 'allKey' with the traffic direction of 'newKey' (i.e., 'allKey[newKey.TrafficDirection()]' is removed by this commit. Signed-off-by: Jarno Rajahalme <jarno@isovalent.com>
Refactor to delete covered keys first, no functional changes. Signed-off-by: Jarno Rajahalme <jarno@isovalent.com>
Only store a changed entry again in 'deleteKeyWithChanges' if it is not going to be deleted. Fix comments. Signed-off-by: Jarno Rajahalme <jarno@isovalent.com>
Checking for auth feature before calling authPreferredInsert is faster than calling it and checking it there when there are no auth rules in the policy. No functional changes. Signed-off-by: Jarno Rajahalme <jarno@isovalent.com>
A map state key may have narrower keys when the destination port is at least partially wildcarded. Check for this so that we do not need to try find narrower keys when there can be none, and also initialize the slice for the related updates only when needed. This reduces allocations in cases when there will be no updates. Refactor authPerferred insert by factoring out common code to 'overrideAuthType()' helper. No functional changes. Signed-off-by: Jarno Rajahalme <jarno@isovalent.com>
Add Iterator interface and implementations that keep state explicitly instead of relying on Go closures. This form of iteration is faster and requires less allocations when called from Go 1.23 iterators. Policy MapState benchmark shows benefit for not preallocating space for nodes in these new iterators, so the 'nodes[K,T]' slices are left initially 'nil'. Signed-off-by: Jarno Rajahalme <jarno@isovalent.com>
It looks like converting mapstate iteration helpers into Go 1.23 iterators has no performance penalty with the new bitlpm explicit iterators. This change makes the business logic much more readable. Signed-off-by: Jarno Rajahalme <jarno@isovalent.com>
a70511f
to
161fe7c
Compare
Rebased to fix merge conflict, fixed gofmt. |
/test |
nathanjsweet
approved these changes
Oct 10, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
kind/cleanup
This includes no functional changes.
release-note/misc
This PR makes changes that have no direct user impact.
sig/policy
Impacts whether traffic is allowed or denied based on user-defined policies.
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.
Avoid unnecessary iteration for narrower keys when key has no port wildcarding.
Introduce
containers/bitlpm
explicit iterators that perform better when used from Go 1.23 iterators.Use Go 1.23 iterators in policy mapstate computation to simplify for better readability.
With these changes
BenchmarkRegenerateCIDRDenyPolicyRules
benchmark does 48% fewer allocations, uses 33% less memory, and performs 23% faster.denyPreferredInsertWithChanges
that contains the main business logic for policy mapstate generation, becomes a lot simpler as result, and is that much easier to understand and maintain in the future.