Accepted
BPF maps are kernel data structures that allow:
We needed to design an API that:
Map types are specified as keywords:
(maps/create {:type :hash :key-size 4 :value-size 8 :max-entries 1024})
(maps/create {:type :ringbuf :max-entries 4096})
Map operations return results rather than mutating in place:
(maps/lookup map key) ; Returns value or nil
(maps/update! map key val) ; Returns true/false
(maps/delete! map key) ; Returns true/false
For bulk operations, we provide batch functions:
(maps/lookup-batch map keys) ; Returns seq of values
(maps/update-batch! map pairs) ; Updates multiple key-value pairs
Map iteration is lazy to handle large maps:
(maps/entries-seq map) ; Returns lazy seq of [key value] pairs
Maps are resources that must be closed:
(with-open [m (maps/create {...})]
(maps/update! m key val))
Or using the macro:
(maps/with-map [m {:type :hash ...}]
(maps/update! m key val))
with-open/with-map| Type | Description |
|---|---|
:hash | Hash table |
:array | Array with integer keys |
:percpu-hash | Per-CPU hash table |
:percpu-array | Per-CPU array |
:lru-hash | LRU hash table |
:lru-percpu-hash | Per-CPU LRU hash |
:ringbuf | Ring buffer for events |
:stack | LIFO stack |
:queue | FIFO queue |
:lpm-trie | Longest prefix match trie |
:hash-of-maps | Hash containing map FDs |
:array-of-maps | Array containing map FDs |
Can you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |