-
Notifications
You must be signed in to change notification settings - Fork 119
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
feat(s2n-quic-dc): Use a new fixed-size map for path secret storage #2337
Conversation
d39e5aa
to
5f9c41a
Compare
} | ||
|
||
// Balance of speed of access (put or get) and likelihood of false positive eviction. | ||
const SLOT_CAPACITY: usize = 32; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this something we'll need to revisit in the future with benchmarks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we'll want to revisit this. Hopefully the entropy will be enough to make this a non-issue in practice.
@@ -0,0 +1,33 @@ | |||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not blocking but as a follow up we should probably fuzz the map. Additionally, it would be nice to add a stress test where we have a bunch of threads performing random operations and trying to break it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed on both, though I'm not particularly worried - logic seems relatively simple. Let's follow up with this.
5f9c41a
to
994250c
Compare
This tightly bounds the maximum memory usage of the path secret storage.
994250c
to
4580638
Compare
This tightly bounds the maximum memory usage of the path secret storage.
Description of changes:
This introduces a new data structure (fixed-space HashMap) and refactors our existing flurry maps for by-IP and by-ID path secret storage to utilize it. Under the new design, a given entry is hashed and placed in at most one of 8 slots -- currently replacement just rotates through if there are no empty slots left (this can be improved with LFU/LRU in the future). The new data structure is all safe code and has some tests inline (plus the existing testing from the path secret map).
Call-outs:
Due to the fixed-size slots, we are very likely much more prone to evicting entries from the map. In some sense, with as few as 32 peers (particularly for the IP map) we might start evicting entries (and permanently be unable to make use of much of the map). It seems likely that we should consider tweaking the fixed constant upwards -- or re-design around an open-addressing map that is able to make use of ~50% or more of the map (albeit chasing pointers) area if needed on particularly long hash collision chains.
On the other hand, the current map avoids slowing down as occupancy increases -- we expect at most 32 checks, and since they're memory-local it should be super fast to do so.
Testing:
See added tests.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.