History

bpf: Add batch ops to all htab bpf map

htab can't use generic batch support due some problematic behaviours inherent to the data structre, i.e. while iterating the bpf map a concurrent program might delete the next entry that batch was about to use, in that case there's no easy solution to retrieve the next entry, the issue has been discussed multiple times (see [1] and [2]). The only way hmap can be traversed without the problem previously exposed is by making sure that the map is traversing entire buckets. This commit implements those strict requirements for hmap, the implementation follows the same interaction that generic support with some exceptions: - If keys/values buffer are not big enough to traverse a bucket, ENOSPC will be returned. - out_batch contains the value of the next bucket in the iteration, not the next key, but this is transparent for the user since the user should never use out_batch for other than bpf batch syscalls. This commits implements BPF_MAP_LOOKUP_BATCH and adds support for new command BPF_MAP_LOOKUP_AND_DELETE_BATCH. Note that for update/delete batch ops it is possible to use the generic implementations. [1] https://lore.kernel.org/bpf/20190724165803.87470-1-brianvv@google.com/ [2] https://lore.kernel.org/bpf/20190906225434.3635421-1-yhs@fb.com/

Yonghong Song committed 6 years ago

Commit 05799631 parent c60f2d24 files · +276 −1Browse files

Showing the changes to include/uapi/linux (1 of 4 files). Show all

Unified · Split

include/uapi/linux/bpf.h+1−0
@@ -108,6 +108,7 @@ enum bpf_cmd { · 107 unmodified lines
108108 BPF_MAP_FREEZE,
109109 BPF_BTF_GET_NEXT_ID,
110110 BPF_MAP_LOOKUP_BATCH,
111+ BPF_MAP_LOOKUP_AND_DELETE_BATCH,
111112 BPF_MAP_UPDATE_BATCH,
112113 BPF_MAP_DELETE_BATCH,
113114 };