|
|
Subscribe / Log in / New account

bpf: BPF specific memory allocator.

From:  Alexei Starovoitov <alexei.starovoitov-AT-gmail.com>
To:  davem-AT-davemloft.net
Subject:  [PATCH bpf-next 0/5] bpf: BPF specific memory allocator.
Date:  Wed, 22 Jun 2022 17:32:25 -0700
Message-ID:  <20220623003230.37497-1-alexei.starovoitov@gmail.com>
Cc:  daniel-AT-iogearbox.net, andrii-AT-kernel.org, tj-AT-kernel.org, kafai-AT-fb.com, bpf-AT-vger.kernel.org, kernel-team-AT-fb.com
Archive-link:  Article

From: Alexei Starovoitov <ast@kernel.org>

Introduce any context BPF specific memory allocator.

Tracing BPF programs can attach to kprobe and fentry. Hence they
run in unknown context where calling plain kmalloc() might not be safe.
Front-end kmalloc() with per-cpu per-bucket cache of free elements.
Refill this cache asynchronously from irq_work.

There is a lot more work ahead, but this set is useful base.
Future work:
- get rid of call_rcu in hash map
- get rid of atomic_inc/dec in hash map
- tune watermarks per allocation size
- adopt this approach alloc_percpu_gfp
- expose bpf_mem_alloc as uapi FD to be used in dynptr_alloc, kptr_alloc
- add sysctl to force bpf_mem_alloc in hash map when safe even if pre-alloc
  requested to reduce memory consumption
- convert lru map to bpf_mem_alloc

Alexei Starovoitov (5):
  bpf: Introduce any context BPF specific memory allocator.
  bpf: Convert hash map to bpf_mem_alloc.
  selftests/bpf: Improve test coverage of test_maps
  samples/bpf: Reduce syscall overhead in map_perf_test.
  bpf: Relax the requirement to use preallocated hash maps in tracing
    progs.

 include/linux/bpf_mem_alloc.h           |  26 ++
 kernel/bpf/Makefile                     |   2 +-
 kernel/bpf/hashtab.c                    |  16 +-
 kernel/bpf/memalloc.c                   | 512 ++++++++++++++++++++++++
 kernel/bpf/verifier.c                   |  31 +-
 samples/bpf/map_perf_test_kern.c        |  22 +-
 tools/testing/selftests/bpf/test_maps.c |  38 +-
 7 files changed, 610 insertions(+), 37 deletions(-)
 create mode 100644 include/linux/bpf_mem_alloc.h
 create mode 100644 kernel/bpf/memalloc.c

-- 
2.30.2



Copyright © 2022, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds