Libbpf userspace function bpf_map_lookup_batch
Allows for batch lookup of BPF map elements.
Definition
int bpf_map_lookup_batch(int fd, void *in_batch, void *out_batch, void *keys, void *values, __u32 *count, const struct bpf_map_batch_opts *opts);
Parameters
fd: BPF map file descriptorin_batch: address of the first element in batch to read, can passNULLto indicate that the batched lookup starts from the beginning of the map.out_batch: output parameter that should be passed to next call asin_batchkeys: pointer to an array large enough forcountkeysvalues: pointer to an array large enough forcountvaluescount: input and output parameter; on input it's the number of elements in the map to read in batch; on output it's the number of elements that were successfully read. If a non-EFAULTerror is returned, count will be set as the number of elements that were read before the error occurred. If-EFAULTis returned,countshould not be trusted to be correct.opts: options for configuring the way the batch lookup works
Return
0, on success; negative error code, otherwise (errno is also set to the error code)
Usage
The parameter in_batch is the address of the first element in the batch to read. out_batch is an output parameter that should be passed as in_batch to subsequent calls to bpf_map_lookup_batch. NULL can be passed for in_batch to indicate that the batched lookup starts from the beginning of the map. Both in_batch and out_batch must point to memory large enough to hold a single key, except for maps of type BPF_MAP_TYPE_{HASH, PERCPU_HASH, LRU_HASH, LRU_PERCPU_HASH}, for which the memory size must be at least 4 bytes wide regardless of key size.
The keys and values are output parameters which must point to memory large enough to hold count items based on the key and value size of the map map_fd. The keys buffer must be of key_size * count. The values buffer must be of value_size * count.
Example
Docs could be improved
This part of the docs is incomplete, contributions are very welcome