-
Notifications
You must be signed in to change notification settings - Fork 136
optimize xDS bpf map #1029
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
optimize xDS bpf map #1029
Conversation
Signed-off-by: wuchangye <wuchangye@huawei.com>
Codecov ReportAttention: Patch coverage is
... and 30 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
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.
Overall LGTM, but this is not compatable with arm ithink. i would approve after a test report though cc @lec-bit
| "Map64", | ||
| "Map192", | ||
| "Map296", | ||
| "Map1600", |
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.
nit: I am not sure why select 296 and 1600, is there byte alignments then we need tp adjust to 2^N
bpf/include/bpf_common.h
Outdated
| __uint(value_size, MAP_VAL_SIZE_64); | ||
| __uint(max_entries, MAP_MAX_ENTRIES); | ||
| __uint(map_flags, BPF_F_NO_PREALLOC); | ||
| } map64 SEC(".maps"); |
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.
Add a kmesh_ prefix to all the maps
bpf/include/bpf_common.h
Outdated
| __u32 outer_key = (__u32)(uintptr_t)ptr; | ||
|
|
||
| kmesh_parse_outer_key(outer_key, &type, &inner_idx); | ||
| if (type != map_type) |
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.
I think the error log is needed here.
bpf/include/bpf_common.h
Outdated
| else if (__builtin_types_compatible_p(type, void *)) \ | ||
| val_tmp = get_ptr_val_from_map(&map1600, MAP_TYPE_1600, ptr); \ | ||
| else if (__builtin_types_compatible_p(type, void **)) \ | ||
| val_tmp = get_ptr_val_from_map(&map1600, MAP_TYPE_1600, ptr); \ |
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.
Why is this the same as line 204?
bpf/include/bpf_common.h
Outdated
| if (__builtin_types_compatible_p(type, char *)) \ | ||
| val_tmp = get_ptr_val_from_map(&map192, MAP_TYPE_192, ptr); \ | ||
| else if (__builtin_types_compatible_p(type, void *)) \ | ||
| val_tmp = get_ptr_val_from_map(&map1600, MAP_TYPE_1600, ptr); \ |
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.
| val_tmp = get_ptr_val_from_map(&map1600, MAP_TYPE_1600, ptr); \ | |
| val_tmp = get_ptr_val_from_map(&map1600, MAP_TYPE_296, ptr); \ |
Signed-off-by: wuchangye <wuchangye@huawei.com>
| static inline int selected_oneof_field(void *value, const ProtobufCFieldDescriptor *field) | ||
| { | ||
| uint32_t n = *(uint32_t *)((char *)value + field->quantifier_offset); | ||
| unsigned int n = *(unsigned int *)((char *)value + field->quantifier_offset); |
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.
why not use uint32 anymore, aren't they same?
| static void free_elem(void *ptr) | ||
| { | ||
| if ((uintptr_t)ptr < MAX_OUTTER_MAP_ENTRIES) | ||
| if ((uintptr_t)ptr < UINT32_MAX) |
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.
What does this mean
| __uint(max_entries, MAP_MAX_ENTRIES); | ||
| __uint(map_flags, BPF_F_NO_PREALLOC); | ||
| } kmesh_map296 SEC(".maps"); | ||
| struct { |
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.
add a blank line before
| __uint(max_entries, MAP_MAX_ENTRIES); | ||
| __uint(map_flags, BPF_F_NO_PREALLOC); | ||
| } kmesh_map192 SEC(".maps"); | ||
| struct { |
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.
add a blank line
| struct bpf_map_info info = {}; | ||
| __u32 info_len = sizeof(info); | ||
| unsigned char type = MAP_GET_TYPE(*outer_key); | ||
| unsigned int inner_idx = MAP_GET_INDEX(*outer_key); |
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.
somewhere you use the parse function, should keep consistent
hzxuzhonghu
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.
YOu should also update the enahanced bpf2go package
| struct map_mng { | ||
| int inner_fds[MAP_TYPE_MAX]; | ||
| struct bpf_map_info inner_infos[MAP_TYPE_MAX]; | ||
| unsigned char mim_used_bitmap[MAP_TYPE_MAX][MIM_BITMAP_SIZE]; |
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.
what does mim abbrev for
| } | ||
|
|
||
| static int free_outter_map_entry(struct op_context *ctx, void *outter_key) | ||
| static int bitmap_find_first_clear(unsigned char *bitmap, int len) |
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.
This is a little too slow, i am thinking if we can use optimistic algorithm, record last allocated bit postion. And at the next time, we allocate from the last position, this can largely reduce the loop and compare
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.
Good idea~ It will be optimized.
| return fmt.Errorf("failed to set api env") | ||
| } | ||
|
|
||
| ret := C.deserial_init(restart.GetStartType() == restart.Restart) |
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.
so this does not support restart now
Signed-off-by: wuchangye <wuchangye@huawei.com>
| } | ||
| #endif | ||
|
|
||
| #define KMESH_GET_PTR_VAL(ptr, type) \ |
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.
Defined as whether a function can reduce the number of instructions?
hzxuzhonghu
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.
much vbetter
/lgtm
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: hzxuzhonghu The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind enhancement
What this PR does / why we need it:
As discussed at the community meeting, the current xDS bpf map has the following problems:
Solution:
After the modification, the content of the xDS pointer is as follows:
ptr(outer_key):
Reserved(4 bytes) + map_type(1 byte) + inner_idx(3 bytes)
Known issues:
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?: