Skip to content

Commit eb398e9

Browse files
authored
io_uring: update API and docs (#38677)
1 parent 22a07c3 commit eb398e9

File tree

7 files changed

+107
-19
lines changed

7 files changed

+107
-19
lines changed

api/envoy/extensions/network/socket_interface/v3/default_socket_interface.proto

+10-9
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,31 @@ option (udpa.annotations.file_status).package_version_status = ACTIVE;
1616

1717
// Configuration for default socket interface that relies on OS dependent syscall to create
1818
// sockets.
19-
// [#next-free-field: 6]
2019
message DefaultSocketInterface {
21-
// Enable io_uring for socket operations if the kernel supports. io_uring is only valid in
22-
// Linux with at least kernel version 5.6. Otherwise, Envoy will fall back to use the default
23-
// socket operations. The default is false.
24-
bool enable_io_uring = 1;
20+
// io_uring options. io_uring is only valid in Linux with at least kernel version 5.11. Otherwise,
21+
// Envoy will fall back to use the default socket API. If not set then io_uring will not be
22+
// enabled.
23+
IoUringOptions io_uring_options = 1;
24+
}
2525

26+
message IoUringOptions {
2627
// The size for io_uring submission queues (SQ). io_uring is built with a fixed size in each
2728
// thread during configuration, and each io_uring operation creates a submission queue
2829
// entry (SQE). The default is 1000.
29-
google.protobuf.UInt32Value io_uring_size = 2;
30+
google.protobuf.UInt32Value io_uring_size = 1;
3031

3132
// Enable io_uring submission queue polling (SQPOLL). io_uring SQPOLL mode polls all SQEs in the
3233
// SQ in the kernel thread. io_uring SQPOLL mode may reduce latency and increase CPU usage as a
3334
// cost. The default is false.
34-
bool enable_io_uring_submission_queue_polling = 3;
35+
bool enable_submission_queue_polling = 2;
3536

3637
// The size of an io_uring socket's read buffer. Each io_uring read operation will allocate a
3738
// buffer of the given size. If the given buffer is too small, the socket will have read multiple
3839
// times for all the data. The default is 8192.
39-
google.protobuf.UInt32Value io_uring_read_buffer_size = 4;
40+
google.protobuf.UInt32Value read_buffer_size = 3;
4041

4142
// The write timeout of an io_uring socket on closing in ms. io_uring writes and closes
4243
// asynchronously. If the remote stops reading, the io_uring write operation may never complete.
4344
// The operation is canceled and the socket is closed after the timeout. The default is 1000.
44-
google.protobuf.UInt32Value io_uring_write_timeout_ms = 5;
45+
google.protobuf.UInt32Value write_timeout_ms = 4;
4546
}

changelogs/current.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ new_features:
234234
``envoy.tcp_proxy.receive_before_connect``.
235235
- area: sockets
236236
change: |
237-
Added :ref:`enable_io_uring <envoy_v3_api_field_extensions.network.socket_interface.v3.DefaultSocketInterface.enable_io_uring>` to
238-
support io_uring.
237+
Added an :ref:`io_uring <envoy_v3_api_field_extensions.network.socket_interface.v3.DefaultSocketInterface.io_uring_options>` option in
238+
default socket interface to support io_uring.
239239
240240
deprecated:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
static_resources:
2+
listeners:
3+
- address:
4+
socket_address:
5+
address: 0.0.0.0
6+
port_value: 80
7+
filter_chains:
8+
- filters:
9+
- name: envoy.filters.network.http_connection_manager
10+
typed_config:
11+
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
12+
codec_type: AUTO
13+
stat_prefix: ingress_http
14+
route_config:
15+
name: local_route
16+
virtual_hosts:
17+
- name: app
18+
domains:
19+
- "*"
20+
routes:
21+
- match:
22+
prefix: "/"
23+
route:
24+
cluster: local_service
25+
http_filters:
26+
- name: envoy.filters.http.router
27+
typed_config:
28+
"@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
29+
30+
clusters:
31+
- name: local_service
32+
type: STRICT_DNS
33+
lb_policy: ROUND_ROBIN
34+
load_assignment:
35+
cluster_name: local_service
36+
endpoints:
37+
- lb_endpoints:
38+
- endpoint:
39+
address:
40+
socket_address:
41+
address: 127.0.0.1
42+
port_value: 8080
43+
44+
bootstrap_extensions:
45+
- name: envoy.extensions.network.socket_interface.default_socket_interface
46+
typed_config:
47+
"@type": type.googleapis.com/envoy.extensions.network.socket_interface.v3.DefaultSocketInterface
48+
io_uring_options: {}
49+
default_socket_interface: "envoy.extensions.network.socket_interface.default_socket_interface"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
.. _config_io_uring:
2+
3+
io_uring
4+
========
5+
6+
* :ref:`v3 API reference <envoy_v3_api_msg_extensions.network.socket_interface.v3.IoUringOptions>`
7+
8+
.. attention::
9+
10+
io_uring is experimental and is currently under active development.
11+
12+
.. note::
13+
14+
This feature is not supported on Windows.
15+
16+
io_uring is an API for asynchronous I/O available in modern Linux kernels, designed to reduce system
17+
calls in network I/O and enhance performance. Envoy can be configured to use io_uring for all TCP
18+
listeners and connections.
19+
20+
To enable io_uring in Envoy, the Linux kernel must be at least version 5.11.
21+
22+
Example Configuration
23+
---------------------
24+
25+
.. literalinclude:: _include/io_uring.yaml
26+
:language: yaml
27+
:linenos:
28+
:lines: 44-49
29+
:caption: :download:`io_uring.yaml <_include/io_uring.yaml>`
30+
31+
In this configuration, io_uring is enabled in the bootstrap extension, and the default socket
32+
interface is explicitly defined. As a result, Envoy initializes a socket interface with io_uring
33+
support, replacing the default socket interface that uses the traditional socket API.
34+
35+
If the kernel does not support io_uring, Envoy will fall back to the traditional socket API.

docs/root/configuration/other_features/other_features.rst

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Other features
88
hyperscan
99
internal_listener
1010
rate_limit
11+
io_uring
1112
vcl
1213
wasm
1314
wasm_service

source/common/network/socket_interface_impl.cc

+6-5
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,14 @@ Server::BootstrapExtensionPtr SocketInterfaceImpl::createBootstrapExtension(
171171
const auto& message = MessageUtil::downcastAndValidate<
172172
const envoy::extensions::network::socket_interface::v3::DefaultSocketInterface&>(
173173
config, context.messageValidationVisitor());
174-
if (message.enable_io_uring() && Io::isIoUringSupported()) {
174+
if (message.has_io_uring_options() && Io::isIoUringSupported()) {
175+
const auto& options = message.io_uring_options();
175176
std::shared_ptr<Io::IoUringWorkerFactoryImpl> io_uring_worker_factory =
176177
std::make_shared<Io::IoUringWorkerFactoryImpl>(
177-
PROTOBUF_GET_WRAPPED_OR_DEFAULT(message, io_uring_size, 1000),
178-
message.enable_io_uring_submission_queue_polling(),
179-
PROTOBUF_GET_WRAPPED_OR_DEFAULT(message, io_uring_read_buffer_size, 8192),
180-
PROTOBUF_GET_WRAPPED_OR_DEFAULT(message, io_uring_write_timeout_ms, 1000),
178+
PROTOBUF_GET_WRAPPED_OR_DEFAULT(options, io_uring_size, 1000),
179+
options.enable_submission_queue_polling(),
180+
PROTOBUF_GET_WRAPPED_OR_DEFAULT(options, read_buffer_size, 8192),
181+
PROTOBUF_GET_WRAPPED_OR_DEFAULT(options, write_timeout_ms, 1000),
181182
context.threadLocal());
182183
io_uring_worker_factory_ = io_uring_worker_factory;
183184

test/integration/socket_interface_integration_test.cc

+4-3
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,16 @@ class SocketInterfaceIntegrationTest : public BaseIntegrationTest,
2525

2626
static std::string config(bool enable_io_uring = false) {
2727
// At least one empty filter chain needs to be specified.
28-
return absl::StrCat(echoConfig(), absl::StrFormat(R"EOF(
28+
return absl::StrCat(echoConfig(),
29+
absl::StrFormat(R"EOF(
2930
bootstrap_extensions:
3031
- name: envoy.extensions.network.socket_interface.default_socket_interface
3132
typed_config:
3233
"@type": type.googleapis.com/envoy.extensions.network.socket_interface.v3.DefaultSocketInterface
33-
enable_io_uring: %s
34+
%s
3435
default_socket_interface: "envoy.extensions.network.socket_interface.default_socket_interface"
3536
)EOF",
36-
enable_io_uring ? "true" : "false"));
37+
enable_io_uring ? "io_uring_options: {}" : ""));
3738
}
3839
static std::string echoConfig() {
3940
return absl::StrCat(ConfigHelper::baseConfig(), R"EOF(

0 commit comments

Comments
 (0)