BPF_MAP_TYPE_BLOOM_FILTER — The Linux Kernel documentation #534
Labels
Algorithms
Sorting, Learning or Classifying. All algorithms go here.
CLI-UX
Command Line Interface user experience and best practices
Code-Interpreter
OpenAI Code-Interpreter
dataset
public datasets and embeddings
linux
Linux notes tools links
New-Label
Choose this option if the existing labels are insufficient to describe the content accurately
Software2.0
Software development driven by AI and neural networks.
BPF_MAP_TYPE_BLOOM_FILTER — The Linux Kernel documentation
DESCRIPTION: BPF_MAP_TYPE_BLOOM_FILTER
Note
BPF_MAP_TYPE_BLOOM_FILTER was introduced in kernel version 5.16
BPF_MAP_TYPE_BLOOM_FILTER provides a BPF bloom filter map. Bloom filters are a space-efficient probabilistic data structure used to quickly test whether an element exists in a set. In a bloom filter, false positives are possible whereas false negatives are not.
The bloom filter map does not have keys, only values. When the bloom filter map is created, it must be created with a key_size of 0. The bloom filter map supports two operations:
BPF programs must use
bpf_map_push_elem
to add an element to the bloom filter map andbpf_map_peek_elem
to query the map. These operations are exposed to userspace applications using the existing bpf syscall in the following way:The
max_entries
size that is specified at map creation time is used to approximate a reasonable bitmap size for the bloom filter, and is not otherwise strictly enforced. If the user wishes to insert more entries into the bloom filter thanmax_entries
, this may lead to a higher false positive rate.The number of hashes to use for the bloom filter is configurable using the lower 4 bits of
map_extra
in unionbpf_attr
at map creation time. If no number is specified, the default used will be 5 hash functions. In general, using more hashes decreases both the false positive rate and the speed of a lookup.It is not possible to delete elements from a bloom filter map. A bloom filter map may be used as an inner map. The user is responsible for synchronising concurrent updates and lookups to ensure no false negative lookups occur.
Usage
Kernel BPF
bpf_map_push_elem()
A value can be added to a bloom filter using the
bpf_map_push_elem()
helper. Theflags
parameter must be set toBPF_ANY
when adding an entry to the bloom filter. This helper returns 0 on success, or negative error in case of failure.bpf_map_peek_elem()
The
bpf_map_peek_elem()
helper is used to determine whethervalue
is present in the bloom filter map. This helper returns 0 ifvalue
is probably present in the map, or-ENOENT
ifvalue
is definitely not present in the map.Userspace
bpf_map_update_elem()
A userspace program can add a value to a bloom filter using libbpf's
bpf_map_update_elem
function. Thekey
parameter must be set toNULL
andflags
must be set toBPF_ANY
. Returns 0 on success, or negative error in case of failure.bpf_map_lookup_elem()
A userspace program can determine the presence of
value
in a bloom filter using libbpf'sbpf_map_lookup_elem
function. Thekey
parameter must be set toNULL
. Returns 0 ifvalue
is probably present in the map, or-ENOENT
ifvalue
is definitely not present in the map.Examples
Kernel BPF
This snippet shows how to declare a bloom filter in a BPF program:
This snippet shows how to determine presence of a value in a bloom filter in a BPF program:
Userspace
This snippet shows how to use libbpf to create a bloom filter map from userspace:
This snippet shows how to add an element to a bloom filter from userspace:
URL: https://docs.kernel.org/bpf/map_bloom_filter.html
Suggested labels
{'label-name': 'Bloom-Filters', 'label-description': 'A space-efficient probabilistic data structure for quick set membership tests.', 'confidence': 96.66}
The text was updated successfully, but these errors were encountered: