-
Notifications
You must be signed in to change notification settings - Fork 269
Add user reference for nested maps. #4661
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
Add user reference for nested maps. #4661
Conversation
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.
Pull Request Overview
This PR adds user reference counting for nested maps (BPF_MAP_TYPE_ARRAY_OF_MAPS, BPF_MAP_TYPE_HASH_OF_MAPS, BPF_MAP_TYPE_PROG_ARRAY) and removes weak reference logic. The change enables outer maps to maintain both user and total references, ensuring proper cleanup when user references reach zero.
- Introduces user reference counting alongside existing reference counting in the object system
- Updates nested maps to take direct references on inner objects instead of using weak ID-based references
- Removes the ID reference counting logic that supported weak references
Reviewed Changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| libs/runtime/ebpf_object.h | Adds user reference count field and function signatures for user reference tracking |
| libs/runtime/ebpf_object.c | Implements user reference counting logic and removes ID-based reference functions |
| libs/execution_context/ebpf_maps.c | Updates nested maps to use direct object references and adds cleanup logic for user reference zeroing |
| tests/end_to_end/end_to_end.cpp | Adds comprehensive tests for nested map user reference behavior |
| tests/api_test/api_test.cpp | Adds API-level tests for user reference functionality and code formatting cleanup |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Alan-Jowett
left a comment
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.
Can we get macros for acquire user reference and acquire kernel reference?
Fixes #4272
This pull request adds user reference for nested maps (BPF_MAP_TYPE_ARRAY_OF_MAPS, BPF_MAP_TYPE_HASH_OF_MAPS, BPF_MAP_TYPE_PROG_ARRAY), and removes the logic of weak references.
With this change, outer maps maintain both user and total references. User reference corresponds to references taken when the object is pinned or a handle is created. When an object is inserted in the outer map, a reference is taken on the inner object (program or map). Once the user reference of the outer map is 0, the outer map is cleaned up and references to the underlying objects are released.
The PR also removes the refcount logic for the IDs as the weak reference is no longer used.
Note: There is a follow up PR #4684 that should be merged after this PR is merged.
Testing
The PR add news tests to validate the new scenario.
Documentation
No
Installation
No