refactor(net): bitmap-backed TCP/UDP local port allocation#700
Open
ytakano wants to merge 2 commits into
Open
Conversation
Replace the BTreeMap/BTreeSet-backed port tracking in port_alloc with a fixed [u64; 1024] bitmap per (tcp/udp)x(v4/v6) set, making claim/release allocation-free and finding a free ephemeral port by scanning whole u64 words. TCP keeps a small overflow refcount map for ports shared by 2+ sockets. Pure logic lives in the new port_bitmap module so it can be unit-tested under the --features std host test build. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors local port allocation in awkernel_lib networking to use bitmap-backed port tracking instead of BTreeMap/BTreeSet, enabling allocation-free claim/release and faster ephemeral-port selection via word scanning. It factors the pure bitmap/refcount logic into a standalone module that can be unit-tested under --features std.
Changes:
- Added
port_bitmapmodule implementing[u64; 1024]port bitmaps, UDP single-owner sets, and TCP sets with an overflow refcount map. - Reworked
port_allocto delegate TCP/UDP IPv4/IPv6 tracking and ephemeral allocation to the new bitmap-backed sets. - Wired the new module into
netand added host-test coverage for the bitmap/refcount logic.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
awkernel_lib/src/net/port_bitmap.rs |
Introduces bitmap-backed port sets and TCP refcount overflow handling with unit tests. |
awkernel_lib/src/net/port_alloc.rs |
Replaces map/set-based tracking with TcpPortSet/UdpPortSet usage under the existing locking/RAII API. |
awkernel_lib/src/net.rs |
Registers the new port_bitmap module. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Description
Replace the BTreeMap/BTreeSet-backed port tracking in port_alloc with a fixed [u64; 1024] bitmap per (tcp/udp)x(v4/v6) set, making claim/release allocation-free and finding a free ephemeral port by scanning whole u64 words. TCP keeps a small overflow refcount map for ports shared by 2+ sockets. Pure logic lives in the new port_bitmap module so it can be unit-tested under the --features std host test build.
Related links
How was this PR tested?
Added tests in
port_bitmap.rs.Notes for reviewers