History

bpf: introduce BPF_F_LOCK flag

Introduce BPF_F_LOCK flag for map_lookup and map_update syscall commands and for map_update() helper function. In all these cases take a lock of existing element (which was provided in BTF description) before copying (in or out) the rest of map value. Implementation details that are part of uapi: Array: The array map takes the element lock for lookup/update. Hash: hash map also takes the lock for lookup/update and tries to avoid the bucket lock. If old element exists it takes the element lock and updates the element in place. If element doesn't exist it allocates new one and inserts into hash table while holding the bucket lock. In rare case the hashmap has to take both the bucket lock and the element lock to update old value in place. Cgroup local storage: It is similar to array. update in place and lookup are done with lock taken.

Alexei Starovoitov committed 7 years ago

Commit 96049f31 parent ab963be7 files · +110 −14Browse files

Showing the changes to include/uapi/linux (1 of 7 files). Show all

Unified · Split

include/uapi/linux/bpf.h+1−0
@@ -267,6 +267,7 @@ enum bpf_attach_type { · 266 unmodified lines
267#define BPF_ANY 0 /* create new element or update existing */267#define BPF_ANY 0 /* create new element or update existing */
268#define BPF_NOEXIST 1 /* create new element if it didn't exist */268#define BPF_NOEXIST 1 /* create new element if it didn't exist */
269#define BPF_EXIST 2 /* update existing element */269#define BPF_EXIST 2 /* update existing element */
270#define BPF_F_LOCK 4 /* spin_lock-ed map_lookup/map_update */
270 271
271/* flags for BPF_MAP_CREATE command */272/* flags for BPF_MAP_CREATE command */
272#define BPF_F_NO_PREALLOC (1U << 0)273#define BPF_F_NO_PREALLOC (1U << 0)