diff mbox series

[RFC,bpf-next,5/6] bpf: Use BPF_MA_NO_REUSE in htab map

Message ID 20221230041151.1231169-6-houtao@huaweicloud.com (mailing list archive)
State New, archived
Headers show
Series bpf: Handle reuse in bpf memory alloc | expand

Commit Message

Hou Tao Dec. 30, 2022, 4:11 a.m. UTC
From: Hou Tao <houtao1@huawei.com>

Use BPF_MA_NO_REUSE in htab map to disable the immediate reuse of free
elements, so the lookup procedure will not return incorrect result.

After the change, the performance of "./map_perf_test 4 18 8192" will
drop from 520K to 330K events per sec on one CPU.

Signed-off-by: Hou Tao <houtao1@huawei.com>
---
 kernel/bpf/hashtab.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/kernel/bpf/hashtab.c b/kernel/bpf/hashtab.c
index 623111d4276d..e1636c5d0051 100644
--- a/kernel/bpf/hashtab.c
+++ b/kernel/bpf/hashtab.c
@@ -574,14 +574,14 @@  static struct bpf_map *htab_map_alloc(union bpf_attr *attr)
 				goto free_prealloc;
 		}
 	} else {
-		err = bpf_mem_alloc_init(&htab->ma, htab->elem_size, 0,
+		err = bpf_mem_alloc_init(&htab->ma, htab->elem_size, BPF_MA_NO_REUSE,
 					 htab_elem_ctor);
 		if (err)
 			goto free_map_locked;
 		if (percpu) {
 			err = bpf_mem_alloc_init(&htab->pcpu_ma,
 						 round_up(htab->map.value_size, 8),
-						 BPF_MA_PERCPU, NULL);
+						 BPF_MA_PERCPU | BPF_MA_NO_REUSE, NULL);
 			if (err)
 				goto free_map_locked;
 		}