-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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 bpf_map_lookup_batch and bpf_map_delete_batch in bcc #3363
Conversation
* add bpf_map_lookup_batch in bcc * add bpf_map_delete_batch in bcc * add test_map_batch_ops.py to test batch lookup and delete on map * add items_lookup_batch() and items_delete_batch() in the reference guide
[buildbot, test this please] |
Thanks @egobillot for the contribution. To answer some of your questions below:
Currently, to BPF_MAP_DELETE_BATCH needs an array of keys, most likely these keys will come from BPF_MAP_LOOKUP_BATCH or BPF_MAP_LOOKUP_AND_DELETE_BATCH. With these keys, you can delete them in one syscall.
It is tricky to use table.clear() without using proceeding BPF_MAP_LOOKUP_BATCH, e.g., example, user space may lookup some keys like k1, k2, k3, and then when you call table.clear(), maybe some new keys are already added like k4. In this case, k4 will be removed. and this may make analysis result in-precise. I know today we already have this issue, but it would be good we can use the interface to improve the situation. You can test whether /proc/kallsyms having this symbol
|
src/python/bcc/table.py
Outdated
for i in range(0, count.value): | ||
yield (keys[i], values[i]) | ||
|
||
def items_delete_batch(self): |
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 would like items_delete_patch takes an optional argument which is an array of keys. If users provide this array, we should be call self.items_delete_batch to delete these keys only. If user provides no keys, we can call items_lookup_and_delete_batch() to delete all of keys in the map. WDYT?
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, good idea. Here is my proposal : 4dbaeef
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.
And to be consistent, I should also provide the same optional argument, an array of keys, for items_lookup_and_delete_batch() and items_lookup_batch(). The src code should be almost the same than items_delete_batch(). If you are Ok with this commit 4dbaeef, I will continue with the 2 other functions.
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.
And to be consistent, I should also provide the same optional argument, an array of keys, for items_lookup_and_delete_batch() and items_lookup_batch(). The src code should be almost the same than items_delete_batch(). If you are Ok with this commit 4dbaeef, I will continue with the 2 other functions.
@egobillot The new change looks good to me. Agree that let us make API consistent to have keys for batched lookup, lookup_and_delete as well. Thanks for working on this!
…k/v pairs present in this array
[buildbot, test this please] |
. add bpf_map_lookup_batch and bpf_map_delete_batch in bcc . add test_map_batch_ops.py to test batch lookup and delete on map . add items_lookup_batch() and items_delete_batch() in the reference guide . add keys as an optional argument to items_delete_batch
Add bpf_map_lookup_batch and bpf_map_delete_batch in bcc
The bpf_map_delete_batch in table.py is not using bpf_map_delete_batch from libbcc. It rather uses bpf_map_lookup_and_delete_batch without using the return values. I did not succeed in writing bpf_map_delete_batch with only one BPF syscall with BPF_MAP_DELETE_BATCH. I doubt this is possible.
bpf_map_delete_batch could be used to improve the table.clear() (less system calls) but it would only works for kernel v5.6 and later. How do you you manage this ? Do you let the kernel dependencies management in libbpf ?