Skip to content
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

Merged
merged 1 commit into from
Sep 28, 2024

Conversation

Mark-Simulacrum
Copy link
Collaborator

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.

dc/s2n-quic-dc/src/fixed_map.rs Outdated Show resolved Hide resolved
dc/s2n-quic-dc/src/fixed_map.rs Show resolved Hide resolved
dc/s2n-quic-dc/src/fixed_map.rs Outdated Show resolved Hide resolved
}

// Balance of speed of access (put or get) and likelihood of false positive eviction.
const SLOT_CAPACITY: usize = 32;
Copy link
Contributor

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?

Copy link
Collaborator Author

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.
Copy link
Contributor

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.

Copy link
Collaborator Author

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.

camshaft
camshaft previously approved these changes Sep 27, 2024
This tightly bounds the maximum memory usage of the path secret storage.
@camshaft camshaft changed the title Use a new fixed-size map for path secret storage feat(s2n-quic-dc): Use a new fixed-size map for path secret storage Sep 28, 2024
@camshaft camshaft enabled auto-merge (squash) September 28, 2024 00:16
@camshaft camshaft merged commit 09a33a8 into aws:main Sep 28, 2024
118 of 121 checks passed
@Mark-Simulacrum Mark-Simulacrum deleted the fixed-maps branch September 28, 2024 00:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants