Skip to content

realm-io: fix bidi_zero_copy#157

Merged
zephyrchien merged 1 commit into
zhboner:masterfrom
liusen373:fix-zero-copy
Aug 18, 2025
Merged

realm-io: fix bidi_zero_copy#157
zephyrchien merged 1 commit into
zhboner:masterfrom
liusen373:fix-zero-copy

Conversation

@liusen373

Copy link
Copy Markdown
Contributor

修复linux下失效的零拷贝函数bidi_zero_copy

系统调用总是失败,错误信息为:

splice(7, NULL, 10, NULL, 18446744073709551615, SPLICE_F_MOVE|SPLICE_F_NONBLOCK) = -1 EINVAL (Invalid argument)

原因是调用splice函数时,长度参数超过了内核最大限制,usize_t在强制转换成ssize_t时溢出
https://github.com/torvalds/linux/blob/c17b750b3ad9f45f2b6f7e6f7f4679844244f0b9/fs/splice.c#L1340
https://github.com/torvalds/linux/blob/c17b750b3ad9f45f2b6f7e6f7f4679844244f0b9/fs/read_write.c#L451-L457

@liusen373

Copy link
Copy Markdown
Contributor Author

下面是一份简单的性能测试

在本机搭建 speedtest-rust 服务器,使用 librespeed-cli 作为客户端,realm 在回环接口上转发。

原版realm的性能(单线程)

下载

> ./librespeed-cli --local-json ./servers.json --server 1 --no-icmp --no-upload
Using local JSON server list: ./servers.json
Selected server: Rust Local [127.0.0.1]
You're testing from: 127.0.0.1 - localhost IPv4 access
Ping: 0.00 ms   Jitter: 0.00 ms
Download rate:  7388.81 Mbps
Upload test is disabled

上传

> ./librespeed-cli --local-json ./servers.json --server 1 --no-icmp --no-download
Using local JSON server list: ./servers.json
Selected server: Rust Local [127.0.0.1]
You're testing from: 127.0.0.1 - localhost IPv4 access
Ping: 0.00 ms   Jitter: 0.00 ms
Download test is disabled
Upload rate:    7391.85 Mbps

zero copy版realm的性能(单线程)

下载

> ./librespeed-cli --local-json ./servers.json --server 1 --no-icmp --no-upload
Using local JSON server list: ./servers.json
Selected server: Rust Local [127.0.0.1]
You're testing from: 127.0.0.1 - localhost IPv4 access
Ping: 0.00 ms   Jitter: 0.00 ms
Download rate:  38859.67 Mbps
Upload test is disabled

上传

> ./librespeed-cli --local-json ./servers.json --server 1 --no-icmp --no-download
Using local JSON server list: ./servers.json
Selected server: Rust Local [127.0.0.1]
You're testing from: 127.0.0.1 - localhost IPv4 access
Ping: 0.00 ms   Jitter: 0.00 ms
Download test is disabled
Upload rate:    12786.49 Mbps

注意:39Gbps/13Gbps 不是 realm 的性能极限,是speedtest-rust和librespeed-cli的性能极限

@zephyrchien

Copy link
Copy Markdown
Collaborator

LGTM. Thank you for the fix and detailed reasoning!

@zephyrchien
zephyrchien merged commit 5b0878a into zhboner:master Aug 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants