From patchwork Thu Dec 21 14:14:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hou Tao X-Patchwork-Id: 13502216 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6068336086 for ; Thu, 21 Dec 2023 14:14:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4SwsqP5gYyz4f3l13 for ; Thu, 21 Dec 2023 22:13:53 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 0DE7E1A0600 for ; Thu, 21 Dec 2023 22:13:59 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.124.27]) by APP1 (Coremail) with SMTP id cCh0CgDHyhAkSIRl5A8DEQ--.16750S4; Thu, 21 Dec 2023 22:13:58 +0800 (CST) From: Hou Tao To: bpf@vger.kernel.org Cc: Martin KaFai Lau , Alexei Starovoitov , Andrii Nakryiko , Song Liu , Hao Luo , Yonghong Song , Daniel Borkmann , KP Singh , Stanislav Fomichev , Jiri Olsa , John Fastabend , houtao1@huawei.com Subject: [PATCH bpf-next 0/2] bpf: Add benchmark for bpf memory allocator Date: Thu, 21 Dec 2023 22:14:59 +0800 Message-Id: <20231221141501.3588586-1-houtao@huaweicloud.com> X-Mailer: git-send-email 2.29.2 Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: cCh0CgDHyhAkSIRl5A8DEQ--.16750S4 X-Coremail-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udrp/ X-Patchwork-Delegate: bpf@iogearbox.net From: Hou Tao Hi, The patch set aims to add a benchmark for bpf memory allocator to test both its alloc/free ratio and the memory usage. Patch #1 is a preparatory patch which moves bench specific metrics into union of structs, so newly-added benchmark can add metrics which doesn't fit with the existing one easily. Patch #2 is the benchmark patch. It tests the performance through the following steps: 1) find the inner array by using the cpu number as key 2) allocate at most 64 128-bytes-sized objects through bpf_obj_new() 3) stash these objectes into the inner array through bpf_kptr_xchg() 4) account the time used in step 1)~3) 5) calculate the performance in M/s: alloc_cnt * 1000 / alloc_tim_ns 6) calculate the memory usage by reading slub field in memory.stat file and get the final value after subtracting the base value. Please see individual patches for more details. And comments are always welcome. Hou Tao (2): selftests/bpf: Move bench specific metrics into union of structs selftests/bpf: Add benchmark for bpf memory allocator tools/testing/selftests/bpf/Makefile | 2 + tools/testing/selftests/bpf/bench.c | 13 +- tools/testing/selftests/bpf/bench.h | 22 +- .../selftests/bpf/benchs/bench_bpf_ma.c | 273 ++++++++++++++++++ .../selftests/bpf/benchs/bench_htab_mem.c | 10 +- .../bench_local_storage_rcu_tasks_trace.c | 10 +- .../selftests/bpf/progs/bench_bpf_ma.c | 222 ++++++++++++++ 7 files changed, 535 insertions(+), 17 deletions(-) create mode 100644 tools/testing/selftests/bpf/benchs/bench_bpf_ma.c create mode 100644 tools/testing/selftests/bpf/progs/bench_bpf_ma.c Acked-by: Jiri Olsa