Use rhashtable_lookup_likely() for lookups, rhashtable_remove_fast() for deletes, and rhashtable_lookup_get_insert_fast() for inserts. Updates modify values in place under RCU rather than allocating a new element and swapping the pointer (as regular htab does). This trades read consistency for performance: concurrent readers may see partial updates. BPF_F_LOCK support and special-field handling (timers, kptrs, etc.) follow in a later commit. Initialize rhashtable with bpf_mem_alloc element cache. Require BPF_F_NO_PREALLOC. Limit max_entries to 2^31. Free elements via rhashtable_free_and_destroy().
Showing the changes to tools/include/uapi/linux (1 of 6 files). Show all
Unified · Split
| @@ -1047,6 +1047,7 @@ enum bpf_map_type { · 1046 unmodified lines | ||
| 1047 | 1047 | BPF_MAP_TYPE_CGRP_STORAGE, |
| 1048 | 1048 | BPF_MAP_TYPE_ARENA, |
| 1049 | 1049 | BPF_MAP_TYPE_INSN_ARRAY, |
| 1050 | + BPF_MAP_TYPE_RHASH, | |
| 1050 | 1051 | __MAX_BPF_MAP_TYPE |
| 1051 | 1052 | }; |
| 1052 | 1053 | |
| @@ -1545,6 +1546,11 @@ union bpf_attr { · 492 unmodified lines | ||
| 1545 | 1546 | * |
| 1546 | 1547 | * BPF_MAP_TYPE_ARENA - contains the address where user space |
| 1547 | 1548 | * is going to mmap() the arena. It has to be page aligned. |
| 1549 | + * | |
| 1550 | + * BPF_MAP_TYPE_RHASH - initial table size hint | |
| 1551 | + * (nelem_hint). 0 = use rhashtable default. Must be | |
| 1552 | + * <= min(max_entries, U16_MAX). Upper 32 bits reserved, | |
| 1553 | + * must be zero. | |
| 1548 | 1554 | */ |
| 1549 | 1555 | __u64 map_extra; |
| 1550 | 1556 | |