Skip to contentSkip to conversation

bpf: Run deferred program freeing on system_dfl_long_wq

PATCH In review Richard Cheng 2 participants 2 messages Jul 20 – Jul 27

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bpf: Run deferred program freeing on system_dfl_long_wq

Destroying APT's seccomp BPF programs can spend over 20ms in arm64 JIT text invalidation. bpf_jit_free() calls kick_all_cpus_sync(), which is especially expensive on system with many CPUs.

schedule_work() uses a per-CPU workqueue, causing:

"""

[204351.169849] workqueue: bpf_prog_free_deferred hogged CPU for
Quoted 1 line

20000us 5 times, consider switching to WQ_UNBOUND

"""

This is triggered during a normal "sudo apt update -y"

Queue the cleanup on system_dfl_long_wq, the unbound queue intended for long-running work, to avoid delaying concurrency-managed per-CPU workers.

---
 kernel/bpf/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/core.c +1 -1
index 6e19a030da6f..a2ca6bdfb6f5 100644
@@ -3115,7 +3115,7 @@ void bpf_prog_free(struct bpf_prog *fp)
 		bpf_prog_put(aux->dst_prog);
 	bpf_token_put(aux->token);
 	INIT_WORK(&aux->work, bpf_prog_free_deferred);
-	schedule_work(&aux->work);
+	queue_work(system_dfl_long_wq, &aux->work);
 }
 EXPORT_SYMBOL_GPL(bpf_prog_free);
 
Signature · 1 line
2.43.0
#1 lore raw
Quoted 28 lines · Richard Cheng

Destroying APT's seccomp BPF programs can spend over 20ms in arm64 JIT text invalidation. bpf_jit_free() calls kick_all_cpus_sync(), which is especially expensive on system with many CPUs.

schedule_work() uses a per-CPU workqueue, causing:

"""

[204351.169849] workqueue: bpf_prog_free_deferred hogged CPU for
Quoted 1 line

20000us 5 times, consider switching to WQ_UNBOUND

"""

This is triggered during a normal "sudo apt update -y"

Queue the cleanup on system_dfl_long_wq, the unbound queue intended for long-running work, to avoid delaying concurrency-managed per-CPU workers.

---
 kernel/bpf/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/core.c +0 -0
index 6e19a030da6f..a2ca6bdfb6f5 100644

kernel/bpf/core.c void bpf_prog_free(struct bpf_prog *fp) · line 3118

Quoted 5 lines
kernel/bpf/core.c +1 -1
@@ -3115,7 +3115,7 @@ void bpf_prog_free(struct bpf_prog *fp)
                bpf_prog_put(aux->dst_prog);
        bpf_token_put(aux->token);
        INIT_WORK(&aux->work, bpf_prog_free_deferred);
-       schedule_work(&aux->work);
+       queue_work(system_dfl_long_wq, &aux->work);

schedule_work() is using system_percpu_wq, and it seems like the closest equivalent for long-running work would be system_long_wq (per-CPU queue), not system_dfl_long_wq (system-wide). I don't really know why we use per-CPU queue here, but wouldn't it be logical to stick to per-CPU queue to keep the behavior as close as possible to the original logic?

Quoted 6 lines
kernel/bpf/core.c +0 -1
 }
 EXPORT_SYMBOL_GPL(bpf_prog_free);
 
--

2.43.0