From: mrpre <mrpre@163.com>
To: yonghong.song@linux.dev, john.fastabend@gmail.com,
martin.lau@kernel.org, edumazet@google.com, jakub@cloudflare.com,
davem@davemloft.net, dsahern@kernel.org, kuba@kernel.org,
pabeni@redhat.com, netdev@vger.kernel.org, bpf@vger.kernel.org,
linux-kernel@vger.kernel.org
Cc: mrpre <mrpre@163.com>
Subject: [PATCH v2 0/2] bpf: Introduce cpu affinity for sockmap
Date: Sat, 2 Nov 2024 00:16:22 +0800 [thread overview]
Message-ID: <20241101161624.568527-1-mrpre@163.com> (raw)
Why we need cpu affinity:
Mainstream data planes, like Nginx and HAProxy, utilize CPU affinity
by binding user processes to specific CPUs. This avoids interference
between processes and prevents impact from other processes.
Sockmap, as an optimization to accelerate such proxy programs,
currently lacks the ability to specify CPU affinity. The current
implementation of sockmap handling backlog is based on workqueue,
which operates by calling 'schedule_delayed_work()'. It's current
implementation prefers to schedule on the local CPU, i.e., the CPU
that handled the packet under softirq.
For extremely high traffic with large numbers of packets,
'sk_psock_backlog' becomes a large loop.
For multi-threaded programs with only one map, we expect different
sockets to run on different CPUs. It is important to note that this
feature is not a general performance optimization. Instead, it
provides users with the ability to bind to specific CPU, allowing
them to enhance overall operating system utilization based on their
own system environments.
Implementation:
1.When updating the sockmap, support passing a CPU parameter and
save it to the psock.
2.When scheduling psock, determine which CPU to run on using the
psock's CPU information.
3.For thoes sockmap without CPU affinity, keep original logic by using
'schedule_delayed_work()'.
Performance Testing:
'client <-> sockmap proxy <-> server'
Using 'iperf3' tests, with the iperf server bound to CPU5 and the iperf
client bound to CPU6, performance without using CPU affinity is
around 34 Gbits/s, and CPU usage is concentrated on CPU5 and CPU6.
'''
[ 5] local 127.0.0.1 port 57144 connected to 127.0.0.1 port 10000
[ ID] Interval Transfer Bitrate
[ 5] 0.00-1.00 sec 3.95 GBytes 33.9 Gbits/sec
[ 5] 1.00-2.00 sec 3.95 GBytes 34.0 Gbits/sec
......
'''
With using CPU affinity, the performnce is close to direct connection
(without any proxy).
'''
[ 5] local 127.0.0.1 port 56518 connected to 127.0.0.1 port 10000
[ ID] Interval Transfer Bitrate
[ 5] 0.00-1.00 sec 7.76 GBytes 66.6 Gbits/sec
[ 5] 1.00-2.00 sec 7.76 GBytes 66.7 Gbits/sec
......
'''
---
v1 -> v2: fix compile error when some macro disabled
---
mrpre (2):
bpf: Introduce cpu affinity for sockmap
bpf: implement libbpf sockmap cpu affinity
include/linux/bpf.h | 5 ++--
include/linux/skmsg.h | 8 +++++++
include/uapi/linux/bpf.h | 4 ++++
kernel/bpf/syscall.c | 23 ++++++++++++++-----
net/core/skmsg.c | 14 +++++------
net/core/sock_map.c | 13 +++++------
tools/include/uapi/linux/bpf.h | 4 ++++
tools/lib/bpf/bpf.c | 22 ++++++++++++++++++
tools/lib/bpf/bpf.h | 9 ++++++++
tools/lib/bpf/libbpf.map | 1 +
.../selftests/bpf/prog_tests/sockmap_basic.c | 19 +++++++++++----
11 files changed, 96 insertions(+), 26 deletions(-)
--
2.43.5
next reply other threads:[~2024-11-01 16:17 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-01 16:16 mrpre [this message]
2024-11-01 16:16 ` [PATCH v2 1/2] bpf: Introduce cpu affinity for sockmap mrpre
2024-11-04 7:23 ` Dan Carpenter
2024-11-01 16:16 ` [PATCH v2 2/2] bpf: implement libbpf sockmap cpu affinity mrpre
2024-11-01 19:27 ` Andrii Nakryiko
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=20241101161624.568527-1-mrpre@163.com \
--to=mrpre@163.com \
--cc=bpf@vger.kernel.org \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=jakub@cloudflare.com \
--cc=john.fastabend@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=yonghong.song@linux.dev \
/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