Skip to contentSkip to conversation

bpf: Remove unnecessary cpu == 0 check in memalloc

PATCH Applied Yonghong Song 2 participants 2 messages Jan 4, 2024 BPF

lore
Share & tools
lore

Yonghong Song

author reviewer
#0 lore raw

PATCH 1/1 bpf: Remove unnecessary cpu == 0 check in memalloc

After merging the patch set [1] to reduce memory usage for bpf_global_percpu_ma, Alexei found a redundant check (cpu == 0) in function bpf_mem_alloc_percpu_unit_init() ([2]). Indeed, the check is unnecessary since c->unit_size will be all NULL or all non-NULL for all cpus before for_each_possible_cpu() loop.
Removing the check makes code less confusing.

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/

---
 kernel/bpf/memalloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/memalloc.c +1 -1
index 460c8f38fed6..550f02e2cb13 100644
@@ -613,7 +613,7 @@ int bpf_mem_alloc_percpu_unit_init(struct bpf_mem_alloc *ma, int size)
 	for_each_possible_cpu(cpu) {
 		cc = per_cpu_ptr(pcc, cpu);
 		c = &cc->cache[i];
-		if (cpu == 0 && c->unit_size)
+		if (c->unit_size)
 			break;
 
 		c->unit_size = unit_size;
Signature · 1 line
2.34.1
#1 lore raw
This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:

Hello:

This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:

Quoted 9 lines · On Thu, 4 Jan 2024 08:57:44 -0800 you wrote:

After merging the patch set [1] to reduce memory usage for bpf_global_percpu_ma, Alexei found a redundant check (cpu == 0) in function bpf_mem_alloc_percpu_unit_init() ([2]). Indeed, the check is unnecessary since c->unit_size will be all NULL or all non-NULL for all cpus before for_each_possible_cpu() loop.
Removing the check makes code less confusing.

[...]

Here is the summary with links:
- [bpf-next] bpf: Remove unnecessary cpu == 0 check in memalloc

    https://git.kernel.org/bpf/bpf-next/c/9ddf872b47e3

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html