第 9 章 Avoiding listen queue lock contention


Queue lock contention can cause packet drops and higher CPU usage and, consequently, a higher latency. You can avoid queue lock contention on the receive (RX) and transmit (TX) queue by tuning your application and using transmit packet steering.

Improving the performance of multi-threaded network server applications on multi-core systems can be done by opening the port with the SO_REUSEPORT or SO_REUSEPORT_BPF socket option. Without these, all threads must share a single socket to receive incoming traffic.

Using a single socket causes:

  • Significant contention on the receive buffer, which can cause packet drops and higher CPU usage.
  • A significant increase of CPU usage
  • Possibly packet drops
Packet flow diagram: Lock contention caused by using only a single UDP socket

With the SO_REUSEPORT or SO_REUSEPORT_BPF socket option, multiple sockets on one host can bind to the same port:

Packet flow diagram: Using the `SO_REUSEPORT` and `SO_REUSEPORT_BPF` socket options to avoid lock contention

For further details, see the socket(7) man page and the /usr/src/debug/kernel-<version>/linux-<version>/tools/testing/selftests/net/reuseport_bpf_cpu.c file on your system.

Red Hat Enterprise Linux provides a code example of how to use the SO_REUSEPORT socket options in the kernel sources. To access the code example:

  1. Enable the rhel-9-for-x86_64-baseos-debug-rpms repository:

    # subscription-manager repos --enable rhel-10-for-x86_64-baseos-debug-rpms
  2. Install the kernel-debuginfo-common-x86_64 package:

    # dnf install kernel-debuginfo-common-x86_64
  3. The code example is now available in the /usr/src/debug/kernel-<version>/linux-<version>/tools/testing/selftests/net/reuseport_bpf_cpu.c file.
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2026 Red Hat
返回顶部