All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf 0/2] bpf/memalloc: Allow non-atomic alloc_bulk
@ 2023-07-20 20:44 YiFei Zhu
  2023-07-20 20:44 ` [PATCH bpf 1/2] bpf/memalloc: Non-atomically allocate freelist during prefill YiFei Zhu
  2023-07-20 20:44 ` [PATCH bpf 2/2] bpf/memalloc: Schedule highprio wq for non-atomic alloc when atomic fails YiFei Zhu
  0 siblings, 2 replies; 11+ messages in thread
From: YiFei Zhu @ 2023-07-20 20:44 UTC (permalink / raw)
  To: bpf
  Cc: Alexei Starovoitov, Daniel Borkmann, Stanislav Fomichev,
	Martin KaFai Lau, Andrii Nakryiko

In internal testing of test_maps, we sometimes observed failures like:
  test_maps: test_maps.c:173: void test_hashmap_percpu(unsigned int, void *):
    Assertion `bpf_map_update_elem(fd, &key, value, BPF_ANY) == 0' failed.
where the errno is ENOMEM. After some troubleshooting and enabling the
warnings, we saw:
  [   91.304708] percpu: allocation failed, size=8 align=8 atomic=1, atomic alloc failed, no space left
  [   91.304716] CPU: 51 PID: 24145 Comm: test_maps Kdump: loaded Tainted: G                 N 6.1.38-smp-DEV #7
  [   91.304719] Hardware name: Google Astoria/astoria, BIOS 0.20230627.0-0 06/27/2023
  [   91.304721] Call Trace:
  [   91.304724]  <TASK>
  [   91.304730]  [<ffffffffa7ef83b9>] dump_stack_lvl+0x59/0x88
  [   91.304737]  [<ffffffffa7ef83f8>] dump_stack+0x10/0x18
  [   91.304738]  [<ffffffffa75caa0c>] pcpu_alloc+0x6fc/0x870
  [   91.304741]  [<ffffffffa75ca302>] __alloc_percpu_gfp+0x12/0x20
  [   91.304743]  [<ffffffffa756785e>] alloc_bulk+0xde/0x1e0
  [   91.304746]  [<ffffffffa7566c02>] bpf_mem_alloc_init+0xd2/0x2f0
  [   91.304747]  [<ffffffffa7547c69>] htab_map_alloc+0x479/0x650
  [   91.304750]  [<ffffffffa751d6e0>] map_create+0x140/0x2e0
  [   91.304752]  [<ffffffffa751d413>] __sys_bpf+0x5a3/0x6c0
  [   91.304753]  [<ffffffffa751c3ec>] __x64_sys_bpf+0x1c/0x30
  [   91.304754]  [<ffffffffa7ef847a>] do_syscall_64+0x5a/0x80
  [   91.304756]  [<ffffffffa800009b>] entry_SYSCALL_64_after_hwframe+0x63/0xcd

This makes sense, because in atomic context, percpu allocation would
not create new chunks; it would only create in non-atomic contexts.

This series attempts to add ways where the allocation could occur
non-atomically, allowing the allocator to take mutexes, perform IO,
and/or sleep.

Patch 1 addresses the prefill case. Since prefill already runs in
sleepable context this is simply just conditionally adding
GFP_KERNEL instead of GFP_NOWAIT.

Patch 2 addresses the refill case. Since refill always runs in
atomic context, we instead add workqueue work to perform non-atomic
allocation when the atomic attempt failed.

YiFei Zhu (2):
  bpf/memalloc: Non-atomically allocate freelist during prefill
  bpf/memalloc: Schedule highprio wq for non-atomic alloc when atomic
    fails

 kernel/bpf/memalloc.c | 59 ++++++++++++++++++++++++++++++-------------
 1 file changed, 41 insertions(+), 18 deletions(-)

-- 
2.41.0.487.g6d72f3e995-goog


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2023-07-27  1:21 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-20 20:44 [PATCH bpf 0/2] bpf/memalloc: Allow non-atomic alloc_bulk YiFei Zhu
2023-07-20 20:44 ` [PATCH bpf 1/2] bpf/memalloc: Non-atomically allocate freelist during prefill YiFei Zhu
2023-07-21  1:44   ` Hou Tao
2023-07-21  2:31     ` YiFei Zhu
2023-07-26 11:38       ` Hou Tao
2023-07-26 18:44         ` YiFei Zhu
2023-07-27  1:21           ` Hou Tao
2023-07-20 20:44 ` [PATCH bpf 2/2] bpf/memalloc: Schedule highprio wq for non-atomic alloc when atomic fails YiFei Zhu
2023-07-21  2:24   ` Hou Tao
2023-07-21  3:02     ` YiFei Zhu
2023-07-26 11:37       ` Hou Tao

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.