diff options
author | Hou Tao <houtao1@huawei.com> | 2025-03-15 23:09:30 +0800 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2025-03-15 12:06:50 -0700 |
commit | bb2243f4328bc2e4aa4d8566a5a0a7f9ce947570 (patch) | |
tree | 1a136a59609641be3b4cecd2946543532669b13a | |
parent | 8c10109a979a5cc04b144d2fa6a6cacd57f390b3 (diff) |
bpf: Check map->record at the beginning of check_and_free_fields()
When there are no special fields in the map value, there is no need to
invoke bpf_obj_free_fields(). Therefore, checking the validity of
map->record in advance.
After the change, the benchmark result of the per-cpu update case in
map_perf_test increased by 40% under a 16-CPU VM.
Signed-off-by: Hou Tao <houtao1@huawei.com>
Acked-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Link: https://lore.kernel.org/r/20250315150930.1511727-1-houtao@huaweicloud.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
-rw-r--r-- | kernel/bpf/hashtab.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/kernel/bpf/hashtab.c b/kernel/bpf/hashtab.c index c308300fc72f..877298133fda 100644 --- a/kernel/bpf/hashtab.c +++ b/kernel/bpf/hashtab.c @@ -787,6 +787,9 @@ static int htab_lru_map_gen_lookup(struct bpf_map *map, static void check_and_free_fields(struct bpf_htab *htab, struct htab_elem *elem) { + if (IS_ERR_OR_NULL(htab->map.record)) + return; + if (htab_is_percpu(htab)) { void __percpu *pptr = htab_elem_get_ptr(elem, htab->map.key_size); int cpu; |