bpf: Initialize same number of free nodes for each pcpu_freelist
authorXu Kuohai <xukuohai@huawei.com>
Thu, 10 Nov 2022 12:21:28 +0000 (07:21 -0500)
committerAndrii Nakryiko <andrii@kernel.org>
Fri, 11 Nov 2022 20:05:14 +0000 (12:05 -0800)
commit4b45cd81f737d79d0fbfc0d320a1e518e7f0bbf0
tree29b8acb33922e5d8489342c09dfecc6cb0fe539f
parentc20572600e16d13d5d6a081bdc84c95491101d34
bpf: Initialize same number of free nodes for each pcpu_freelist

pcpu_freelist_populate() initializes nr_elems / num_possible_cpus() + 1
free nodes for some CPUs, and then possibly one CPU with fewer nodes,
followed by remaining cpus with 0 nodes. For example, when nr_elems == 256
and num_possible_cpus() == 32, CPU 0~27 each gets 9 free nodes, CPU 28 gets
4 free nodes, CPU 29~31 get 0 free nodes, while in fact each CPU should get
8 nodes equally.

This patch initializes nr_elems / num_possible_cpus() free nodes for each
CPU firstly, then allocates the remaining free nodes by one for each CPU
until no free nodes left.

Fixes: e19494edab82 ("bpf: introduce percpu_freelist")
Signed-off-by: Xu Kuohai <xukuohai@huawei.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/20221110122128.105214-1-xukuohai@huawei.com
kernel/bpf/percpu_freelist.c