Skip to content

Commit b26476b

Browse files
authored
Merge pull request #10 from bpftools/new/add-maps
Maps!
2 parents 1b25834 + 1a299b3 commit b26476b

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

content/bpf-vm/304-bpfvm-maps.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
title: "bpfvm-bpf-maps"
3+
weight: 304
4+
---
5+
6+
# Maps
7+
8+
- BPF Maps data stores that live in the kernel;
9+
- Can be accessed by any BPF program that knows about them;
10+
- Programs that run in user-space can also access these maps by using file descriptors;
11+
- You can store any kind of data in a map, as long as you specify the data size correctly before hand;
12+
- The kernel treats keys and values as binary blobs and it doesn’t care about what you keep in a map;
13+
- This is what we use to let userspace programs to extract or feed information into BPF programs running in the kernel!
14+
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
title: "bpfvm-bpf-maps-types"
3+
weight: 305
4+
---
5+
6+
**Many different types of maps**
7+
8+
- Hash table: BPF_MAP_TYPE_HASH
9+
- Array: BPF_MAP_TYPE_ARRAY
10+
- Program array maps: BPF_MAP_TYPE_PROG_ARRAY, this one is magic, allows you to store references to bpf programs so that you can do jumps between bpf programs;
11+
- Perf events array maps: BPF_MAP_TYPE_PERF_EVENT_ARRAY
12+
- Per-CPU hash maps: BPF_MAP_TYPE_PERCPU_HASH
13+
- Per-CPU array maps: BPF_MAP_TYPE_PERCPU_ARRAY
14+
- Stack trace maps: BPF_MAP_TYPE_STACK_TRACE
15+
- Cgroup array maps: BPF_MAP_TYPE_CGROUP_ARRAY
16+
- Hash and per cpu has with LRU cache: BPF_MAP_TYPE_LRU_PERCPU_HASH, BPF_MAP_TYPE_LRU_HASH
17+
- Longest Prefix Match(LPM) Trie: BPF_MAP_TYPE_LPM_TRIE
18+
- Array of maps, and hash of maps, maps: `BPF_MAP_TYPE_ARRAY_OF_MAPS` and `BPF_MAP_TYPE_HASH_OF_MAPS`
19+
- And many more! Find all of them `man 2 bpf`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
title: "bpfvm-bpf-maps-operations"
3+
weight: 306
4+
---
5+
6+
**Maps operations**
7+
8+
- Lookup a single element value, `bpf_map_lookup_elem`
9+
- Remove an element, `bpf_map_delete_element`
10+
- Iterating over elements
11+
- Updating an element, `bpf_map_update_elem`
12+
- Get the next key in the map, `bpf_map_get_next_key`
13+
- Search, get the value and delete in a single atomic operation, `bpf_map_lookup_and_delete_element`
14+
- Concurrent access is regulated using a mechanism called `bpf_spin_lock` that is essentially a semaphore;

0 commit comments

Comments
 (0)