简体   繁体   English

liburing / IORING_OP_PROVIDE_BUFFERS - 分配给读取操作的错误缓冲区

[英]liburing / IORING_OP_PROVIDE_BUFFERS - wrong buffer assigned to read op

I am playing with liburing and io_uring, the former is built from the master branch and for the latter i am using the kernel 5.8.0-rc3.我正在使用 liburing 和 io_uring,前者是从 master 分支构建的,而对于后者,我使用的是 kernel 5.8.0-rc3。

I am facing the issue I am going to explain on previous version of the kernel as well (5.7.6, 5.8.0-rc1).我也面临着我将在 kernel 的先前版本(5.7.6、5.8.0-rc1)上解释的问题。

The tests using the provide buffers look like working as expected.使用提供缓冲区的测试看起来像预期的那样工作。

I am trying to implement a network tcp/ip server using IORING_FEAT_FAST_POLL and IORING_OP_PROVIDE_BUFFERS and I am using https://github.com/frevib/io_uring-echo-server as code reference.我正在尝试使用IORING_FEAT_FAST_POLLIORING_OP_PROVIDE_BUFFERS实现网络 tcp/ip 服务器,并且我正在使用https://github.com/frevib/io_uring-echo-server作为代码参考。

The issue I am facing is that the buffer id is always set to the last of the registered buffers but I can see that the actual buffer used by the kernel is not that.我面临的问题是缓冲区 ID 始终设置为最后一个已注册的缓冲区,但我可以看到 kernel 使用的实际缓冲区并非如此。

I have reduced the amount of registered buffers to just 10 and added some debugging info, it's now printing the content of all the buffers我已将注册缓冲区的数量减少到只有 10 个并添加了一些调试信息,它现在正在打印所有缓冲区的内容

Upon the first RECV from the server I get in cqe->flags >> 16 the ID of the buffer containing the data and it's the last one of the list, and I can see that it's containing the data but upon the second RECV the kernel now used the buffer id 0 (the first one) but cqe->flags >> 16 is still containing the ID of the last one.在来自服务器的第一个 RECV 中,我进入cqe->flags >> 16包含数据的缓冲区的 ID,它是列表的最后一个,我可以看到它包含数据,但在第二个 RECV 中,kernel现在使用缓冲区 id 0(第一个),但cqe->flags >> 16仍然包含最后一个的 ID。

The cause of this is an invocation of io_uring_prep_provide_buffers , infact upon the second invocation the issues arise.其原因是调用io_uring_prep_provide_buffers ,实际上在第二次调用时出现问题。

Out of curiosity I have also tried to register the buffers one by one using出于好奇,我还尝试使用一个一个地注册缓冲区

    for(uint16_t i = 0; i<MAX_CONNECTIONS; i++) {
        sqe = io_uring_get_sqe(&ring);
        io_uring_prep_provide_buffers(sqe, bufs, MAX_MESSAGE_LEN, 1, group_id, i);
    }

instead of代替

    io_uring_prep_provide_buffers(sqe, bufs, MAX_MESSAGE_LEN, MAX_CONNECTIONS, group_id, 0);

The issue start immediately.问题立即开始。

I have also entirely disabled the re-registration of the freed buffer and everything works as expected (I commented out the invocation of the function add_provide_buf ).我还完全禁用了释放缓冲区的重新注册,一切都按预期工作(我注释掉了 function add_provide_buf的调用)。

From the documentation it looks like after the buffer is selected the expectation is to add it back if it's free to be used but clearly this is causing the issue.从文档来看,选择缓冲区后,如果可以免费使用,则期望将其添加回来,但显然这是导致问题的原因。

Any hint?有什么提示吗?

Thanks!谢谢!

There was a bug in the code with re-registering the buffer: https://github.com/frevib/io_uring-echo-server/commit/aa6f2a09ca14c6aa17779a22343b9e7d4b3c7994重新注册缓冲区的代码中存在错误: https://github.com/frevib/io_uring-echo-server/commit/aa6f2a09ca14c6aa17779a22343b9e7d4b3c7994

Checkout the latest master branch, it should work now: https://github.com/frevib/io_uring-echo-server查看最新的 master 分支,它现在应该可以工作了: https://github.com/frevib/io_uring-echo-server

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM