From: Feng zhou <zhoufeng.zf@bytedance.com>
To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
kafai@fb.com, songliubraving@fb.com, yhs@fb.com,
john.fastabend@gmail.com, kpsingh@kernel.org
Cc: netdev@vger.kernel.org, bpf@vger.kernel.org,
linux-kernel@vger.kernel.org, duanxiongchun@bytedance.com,
songmuchun@bytedance.com, wangdongdong.6@bytedance.com,
cong.wang@bytedance.com, zhouchengming@bytedance.com,
zhoufeng.zf@bytedance.com
Subject: [PATCH v4 0/2] Optimize performance of update hash-map when free is zero
Date: Wed, 1 Jun 2022 16:41:47 +0800 [thread overview]
Message-ID: <20220601084149.13097-1-zhoufeng.zf@bytedance.com> (raw)
From: Feng Zhou <zhoufeng.zf@bytedance.com>
We encountered bad case on big system with 96 CPUs that
alloc_htab_elem() would last for 1ms. The reason is that after the
prealloc hashtab has no free elems, when trying to update, it will still
grab spin_locks of all cpus. If there are multiple update users, the
competition is very serious.
0001: Add is_empty to check whether the free list is empty or not before taking
the lock.
0002: Add benchmark to reproduce this worst case.
Changelog:
v3->v4: Addressed comments from Daniel Borkmann.
- Use READ_ONCE/WRITE_ONCE.
some details in here:
https://lore.kernel.org/all/20220530091340.53443-1-zhoufeng.zf@bytedance.com/
v2->v3: Addressed comments from Alexei Starovoitov, Andrii Nakryiko.
- Adjust the way the benchmark is tested.
- Adjust the code format.
some details in here:
https://lore.kernel.org/all/20220524075306.32306-1-zhoufeng.zf@bytedance.com/T/
v1->v2: Addressed comments from Alexei Starovoitov.
- add a benchmark to reproduce the issue.
- Adjust the code format that avoid adding indent.
some details in here:
https://lore.kernel.org/all/877ac441-045b-1844-6938-fcaee5eee7f2@bytedance.com/T/
Feng Zhou (2):
bpf: avoid grabbing spin_locks of all cpus when no free elems
selftest/bpf/benchs: Add bpf_map benchmark
kernel/bpf/percpu_freelist.c | 28 +++++-
kernel/bpf/percpu_freelist.h | 1 +
tools/testing/selftests/bpf/Makefile | 4 +-
tools/testing/selftests/bpf/bench.c | 2 +
.../benchs/bench_bpf_hashmap_full_update.c | 96 +++++++++++++++++++
.../run_bench_bpf_hashmap_full_update.sh | 11 +++
.../bpf/progs/bpf_hashmap_full_update_bench.c | 40 ++++++++
7 files changed, 178 insertions(+), 4 deletions(-)
create mode 100644 tools/testing/selftests/bpf/benchs/bench_bpf_hashmap_full_update.c
create mode 100755 tools/testing/selftests/bpf/benchs/run_bench_bpf_hashmap_full_update.sh
create mode 100644 tools/testing/selftests/bpf/progs/bpf_hashmap_full_update_bench.c
--
2.20.1
next reply other threads:[~2022-06-01 8:42 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-01 8:41 Feng zhou [this message]
2022-06-01 8:41 ` [PATCH v4 1/2] bpf: avoid grabbing spin_locks of all cpus when no free elems Feng zhou
2022-06-01 9:50 ` Alexei Starovoitov
2022-06-01 11:10 ` [External] " Feng Zhou
2022-06-01 11:35 ` Alexei Starovoitov
2022-06-02 3:27 ` Feng Zhou
2022-06-06 6:12 ` Feng Zhou
2022-06-01 8:41 ` [PATCH v4 2/2] selftest/bpf/benchs: Add bpf_map benchmark Feng zhou
2022-06-01 9:53 ` Alexei Starovoitov
2022-06-01 11:17 ` Feng Zhou
2022-06-01 11:37 ` Alexei Starovoitov
2022-06-02 3:29 ` Feng Zhou
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220601084149.13097-1-zhoufeng.zf@bytedance.com \
--to=zhoufeng.zf@bytedance.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=cong.wang@bytedance.com \
--cc=daniel@iogearbox.net \
--cc=duanxiongchun@bytedance.com \
--cc=john.fastabend@gmail.com \
--cc=kafai@fb.com \
--cc=kpsingh@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=songliubraving@fb.com \
--cc=songmuchun@bytedance.com \
--cc=wangdongdong.6@bytedance.com \
--cc=yhs@fb.com \
--cc=zhouchengming@bytedance.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®