History

Merge patch series "bpf, riscv: use BPF prog pack allocator in BPF JIT"

Puranjay Mohan <puranjay12@gmail.com> says: Here is some data to prove the V2 fixes the problem: Without this series: root@rv-selftester:~/src/kselftest/bpf# time ./test_tag test_tag: OK (40945 tests) real 7m47.562s user 0m24.145s sys 6m37.064s With this series applied: root@rv-selftester:~/src/selftest/bpf# time ./test_tag test_tag: OK (40945 tests) real 7m29.472s user 0m25.865s sys 6m18.401s BPF programs currently consume a page each on RISCV. For systems with many BPF programs, this adds significant pressure to instruction TLB. High iTLB pressure usually causes slow down for the whole system. Song Liu introduced the BPF prog pack allocator[1] to mitigate the above issue. It packs multiple BPF programs into a single huge page. It is currently only enabled for the x86_64 BPF JIT. I enabled this allocator on the ARM64 BPF JIT[2]. It is being reviewed now. This patch series enables the BPF prog pack allocator for the RISCV BPF JIT. ====================================================== Performance Analysis of prog pack allocator on RISCV64 ====================================================== Test setup: =========== Host machine: Debian GNU/Linux 11 (bullseye) Qemu Version: QEMU emulator version 8.0.3 (Debian 1:8.0.3+dfsg-1) u-boot-qemu Version: 2023.07+dfsg-1 opensbi Version: 1.3-1 To test the performance of the BPF prog pack allocator on RV, a stresser tool[4] linked below was built. This tool loads 8 BPF programs on the system and triggers 5 of them in an infinite loop by doing system calls. The runner script starts 20 instances of the above which loads 8*20=160 BPF programs on the system, 5*20=100 of which are being constantly triggered. The script is passed a command which would be run in the above environment. The script was run with following perf command: ./run.sh "perf stat -a \ -e iTLB-load-misses \ -e dTLB-load-misses \ -e dTLB-store-misses \ -e instructions \ --timeout 60000" The output of the above command is discussed below before and after enabling the BPF prog pack allocator. The tests were run on qemu-system-riscv64 with 8 cpus, 16G memory. The rootfs was created using Bjorn's riscv-cross-builder[5] docker container linked below. Results ======= Before enabling prog pack allocator: ------------------------------------ Performance counter stats for 'system wide': 4939048 iTLB-load-misses 5468689 dTLB-load-misses 465234 dTLB-store-misses 1441082097998 instructions 60.045791200 seconds time elapsed After enabling prog pack allocator: ----------------------------------- Performance counter stats for 'system wide': 3430035 iTLB-load-misses 5008745 dTLB-load-misses 409944 dTLB-store-misses 1441535637988 instructions 60.046296600 seconds time elapsed Improvements in metrics ======================= It was expected that the iTLB-load-misses would decrease as now a single huge page is used to keep all the BPF programs compared to a single page for each program earlier. -------------------------------------------- The improvement in iTLB-load-misses: -30.5 % -------------------------------------------- I repeated this expriment more than 100 times in different setups and the improvement was always greater than 30%. This patch series is boot tested on the Starfive VisionFive 2 board[6]. The performance analysis was not done on the board because it doesn't expose iTLB-load-misses, etc. The stresser program was run on the board to test the loading and unloading of BPF programs [1] https://lore.kernel.org/bpf/20220204185742.271030-1-song@kernel.org/ [2] https://lore.kernel.org/all/20230626085811.3192402-1-puranjay12@gmail.com/ [3] https://lore.kernel.org/all/20230626085811.3192402-2-puranjay12@gmail.com/ [4] https://github.com/puranjaymohan/BPF-Allocator-Bench [5] https://github.com/bjoto/riscv-cross-builder [6] https://www.starfivetech.com/en/site/boards * b4-shazam-merge: bpf, riscv: use prog pack allocator in the BPF JIT riscv: implement a memset like function for text riscv: extend patch_text_nosync() for multiple pages bpf: make bpf_prog_pack allocator portable

Palmer Dabbelt committed 3 years ago

Commit 77eea552 parents f578055 48a8f786 files · +255 −37Browse files

Showing the changes to kernel (1 of 6 files). Show all

Unified · Split

kernel/bpf/core.c+4−4
@@ -870,7 +870,7 @@ static struct bpf_prog_pack *alloc_new_pack(bpf_jit_fill_hole_t bpf_fill_ill_ins · 869 unmodified lines
870 GFP_KERNEL);870 GFP_KERNEL);
871 if (!pack)871 if (!pack)
872 return NULL;872 return NULL;
873 pack->ptr = module_alloc(BPF_PROG_PACK_SIZE);873 pack->ptr = bpf_jit_alloc_exec(BPF_PROG_PACK_SIZE);
874 if (!pack->ptr) {874 if (!pack->ptr) {
875 kfree(pack);875 kfree(pack);
876 return NULL;876 return NULL;
@@ -894,7 +894,7 @@ void *bpf_prog_pack_alloc(u32 size, bpf_jit_fill_hole_t bpf_fill_ill_insns) · 17 unmodified lines
894 mutex_lock(&pack_mutex);894 mutex_lock(&pack_mutex);
895 if (size > BPF_PROG_PACK_SIZE) {895 if (size > BPF_PROG_PACK_SIZE) {
896 size = round_up(size, PAGE_SIZE);896 size = round_up(size, PAGE_SIZE);
897 ptr = module_alloc(size);897 ptr = bpf_jit_alloc_exec(size);
898 if (ptr) {898 if (ptr) {
899 bpf_fill_ill_insns(ptr, size);899 bpf_fill_ill_insns(ptr, size);
900 set_vm_flush_reset_perms(ptr);900 set_vm_flush_reset_perms(ptr);
@@ -932,7 +932,7 @@ void bpf_prog_pack_free(struct bpf_binary_header *hdr) · 31 unmodified lines
932 932
933 mutex_lock(&pack_mutex);933 mutex_lock(&pack_mutex);
934 if (hdr->size > BPF_PROG_PACK_SIZE) {934 if (hdr->size > BPF_PROG_PACK_SIZE) {
935 module_memfree(hdr);935 bpf_jit_free_exec(hdr);
936 goto out;936 goto out;
937 }937 }
938 938
@@ -956,7 +956,7 @@ void bpf_prog_pack_free(struct bpf_binary_header *hdr) · 17 unmodified lines
956 if (bitmap_find_next_zero_area(pack->bitmap, BPF_PROG_CHUNK_COUNT, 0,956 if (bitmap_find_next_zero_area(pack->bitmap, BPF_PROG_CHUNK_COUNT, 0,
957 BPF_PROG_CHUNK_COUNT, 0) == 0) {957 BPF_PROG_CHUNK_COUNT, 0) == 0) {
958 list_del(&pack->list);958 list_del(&pack->list);
959 module_memfree(pack->ptr);959 bpf_jit_free_exec(pack->ptr);
960 kfree(pack);960 kfree(pack);
961 }961 }
962out:962out:

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t