Lines Matching +full:key +full:- +full:code
1 .. SPDX-License-Identifier: GPL-2.0-only
9 - ``BPF_MAP_TYPE_HASH`` was introduced in kernel version 3.19
10 - ``BPF_MAP_TYPE_PERCPU_HASH`` was introduced in version 4.6
11 - Both ``BPF_MAP_TYPE_LRU_HASH`` and ``BPF_MAP_TYPE_LRU_PERCPU_HASH``
15 purpose hash map storage. Both the key and the value can be structs,
18 The kernel is responsible for allocating and freeing key/value pairs, up
19 to the max_entries limit that you specify. Hash maps use pre-allocation
21 used to disable pre-allocation when it is too memory expensive.
24 CPU. The per-cpu values are stored internally in an array.
38 long bpf_map_update_elem(struct bpf_map *map, const void *key, const void *value, u64 flags)
44 - ``BPF_ANY`` will create a new element or update an existing element
45 - ``BPF_NOEXIST`` will create a new element only if one did not already
47 - ``BPF_EXIST`` will update an existing element
53 void *bpf_map_lookup_elem(struct bpf_map *map, const void *key)
57 ``key``, or ``NULL`` if no entry was found.
60 long bpf_map_delete_elem(struct bpf_map *map, const void *key)
67 --------------
74 void *bpf_map_lookup_percpu_elem(struct bpf_map *map, const void *key, u32 cpu)
78 ``key`` on ``cpu`` , or ``NULL`` if no entry was found or ``cpu`` is
82 -----------
90 ---------
96 libbpf's ``bpf_map_get_next_key()`` function. The first key can be fetched by
98 ``NULL``. Subsequent calls will fetch the next key that follows the
99 current key. ``bpf_map_get_next_key()`` returns 0 on success, -ENOENT if
100 cur_key is the last key in the hash, or negative error in case of
104 will instead return the *first* key in the hash table which is
106 to be key deletion intermixed with ``bpf_map_get_next_key()``.
112 examples. The code snippets below demonstrates API usage.
114 This example shows how to declare an LRU Hash with a struct key and a
117 .. code-block:: c
122 struct key {
134 __type(key, struct key);
141 .. code-block:: c
145 struct key key = {
148 struct value *value = bpf_map_lookup_elem(&packet_stats, &key);
151 __sync_fetch_and_add(&value->packets, 1);
152 __sync_fetch_and_add(&value->bytes, bytes);
156 bpf_map_update_elem(&packet_stats, &key, &newval, BPF_NOEXIST);
162 .. code-block:: c
169 struct key *cur_key = NULL;
170 struct key next_key;
181 // Use key and value here