Christoph Hellwig | bc84e95 | 2021-11-19 17:32:14 +0100 | [diff] [blame] | 1 | |
Dave Tucker | 5931d9a | 2021-11-12 21:17:24 +0000 | [diff] [blame] | 2 | ========= |
Christoph Hellwig | bc84e95 | 2021-11-19 17:32:14 +0100 | [diff] [blame] | 3 | eBPF maps |
| 4 | ========= |
| 5 | |
| 6 | 'maps' is a generic storage of different types for sharing data between kernel |
| 7 | and userspace. |
| 8 | |
| 9 | The 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 | |
| 33 | userspace programs use this syscall to create/access maps that eBPF programs |
| 34 | are concurrently updating. |
| 35 | |
| 36 | maps can have different types: hash, array, bloom filter, radix-tree, etc. |
| 37 | |
| 38 | The map is defined by: |
| 39 | |
| 40 | - type |
| 41 | - max number of elements |
| 42 | - key size in bytes |
| 43 | - value size in bytes |
| 44 | |
Dave Tucker | 5931d9a | 2021-11-12 21:17:24 +0000 | [diff] [blame] | 45 | Map Types |
| 46 | ========= |
| 47 | |
| 48 | .. toctree:: |
| 49 | :maxdepth: 1 |
| 50 | :glob: |
| 51 | |
| 52 | map_* |