diff options
author | Roman Gushchin <guro@fb.com> | 2018-09-28 10:45:43 -0400 |
---|---|---|
committer | Daniel Borkmann <daniel@iogearbox.net> | 2018-10-01 10:18:32 -0400 |
commit | b741f1630346defcbc8cc60f1a2bdae8b3b0036f (patch) | |
tree | c5698184b5398cea8e288276844232d0101b64da /kernel/bpf/helpers.c | |
parent | f294b37ec7b24a574884cd157497a3748081c0f0 (diff) |
bpf: introduce per-cpu cgroup local storage
This commit introduced per-cpu cgroup local storage.
Per-cpu cgroup local storage is very similar to simple cgroup storage
(let's call it shared), except all the data is per-cpu.
The main goal of per-cpu variant is to implement super fast
counters (e.g. packet counters), which don't require neither
lookups, neither atomic operations.
>From userspace's point of view, accessing a per-cpu cgroup storage
is similar to other per-cpu map types (e.g. per-cpu hashmaps and
arrays).
Writing to a per-cpu cgroup storage is not atomic, but is performed
by copying longs, so some minimal atomicity is here, exactly
as with other per-cpu maps.
Signed-off-by: Roman Gushchin <guro@fb.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Alexei Starovoitov <ast@kernel.org>
Acked-by: Song Liu <songliubraving@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'kernel/bpf/helpers.c')
-rw-r--r-- | kernel/bpf/helpers.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c index e42f8789b7ea..6502115e8f55 100644 --- a/kernel/bpf/helpers.c +++ b/kernel/bpf/helpers.c | |||
@@ -206,10 +206,16 @@ BPF_CALL_2(bpf_get_local_storage, struct bpf_map *, map, u64, flags) | |||
206 | */ | 206 | */ |
207 | enum bpf_cgroup_storage_type stype = cgroup_storage_type(map); | 207 | enum bpf_cgroup_storage_type stype = cgroup_storage_type(map); |
208 | struct bpf_cgroup_storage *storage; | 208 | struct bpf_cgroup_storage *storage; |
209 | void *ptr; | ||
209 | 210 | ||
210 | storage = this_cpu_read(bpf_cgroup_storage[stype]); | 211 | storage = this_cpu_read(bpf_cgroup_storage[stype]); |
211 | 212 | ||
212 | return (unsigned long)&READ_ONCE(storage->buf)->data[0]; | 213 | if (stype == BPF_CGROUP_STORAGE_SHARED) |
214 | ptr = &READ_ONCE(storage->buf)->data[0]; | ||
215 | else | ||
216 | ptr = this_cpu_ptr(storage->percpu_buf); | ||
217 | |||
218 | return (unsigned long)ptr; | ||
213 | } | 219 | } |
214 | 220 | ||
215 | const struct bpf_func_proto bpf_get_local_storage_proto = { | 221 | const struct bpf_func_proto bpf_get_local_storage_proto = { |