xref: /openbmc/linux/Documentation/bpf/maps.rst (revision c94b731d)
1
2=========
3eBPF maps
4=========
5
6'maps' is a generic storage of different types for sharing data between kernel
7and userspace.
8
9The maps are accessed from user space via BPF syscall, which has commands:
10
11- create a map with given type and attributes
12  ``map_fd = bpf(BPF_MAP_CREATE, union bpf_attr *attr, u32 size)``
13  using attr->map_type, attr->key_size, attr->value_size, attr->max_entries
14  returns process-local file descriptor or negative error
15
16- lookup key in a given map
17  ``err = bpf(BPF_MAP_LOOKUP_ELEM, union bpf_attr *attr, u32 size)``
18  using attr->map_fd, attr->key, attr->value
19  returns zero and stores found elem into value or negative error
20
21- create or update key/value pair in a given map
22  ``err = bpf(BPF_MAP_UPDATE_ELEM, union bpf_attr *attr, u32 size)``
23  using attr->map_fd, attr->key, attr->value
24  returns zero or negative error
25
26- find and delete element by key in a given map
27  ``err = bpf(BPF_MAP_DELETE_ELEM, union bpf_attr *attr, u32 size)``
28  using attr->map_fd, attr->key
29
30- to delete map: close(fd)
31  Exiting process will delete maps automatically
32
33userspace programs use this syscall to create/access maps that eBPF programs
34are concurrently updating.
35
36maps can have different types: hash, array, bloom filter, radix-tree, etc.
37
38The map is defined by:
39
40  - type
41  - max number of elements
42  - key size in bytes
43  - value size in bytes
44
45Map Types
46=========
47
48.. toctree::
49   :maxdepth: 1
50   :glob:
51
52   map_*