Conversation
At least it's failing in my laptop with 128 SQ entries, which should be handled well with 64GB of memory
|
|
||
| # Get buffer from the buffer ring | ||
| var buf_ring_ptr = buf_ring[] | ||
| var buffer = buf_ring_ptr.unsafe_buf(index=buffer_idx, len=UInt32(MAX_MESSAGE_LEN)) |
There was a problem hiding this comment.
In this case, this is the wrong way to use the buffer ring. The method is named unsafe_buf for a reason. The buffer ring has a head that is owned by the kernel and a tail that is shared between the kernel and user space. When a buffer ring is created, ownership of all buffers is transferred to the kernel. The kernel selects buffers from the ring, for example for a Recv operation, and increments the ring head, and after it completes, the kernel transfers ownership of the buffer to user-space. The buffer identifier will be passed using cqe. So it is safe for us to call unsafe_buf only when we have IoUringCqeFlags of the completed operation. When we are done with Buf, its destructor will be called and ownership will be transferred back to the kernel by incrementing the ring tail. We also have the option to prevent the ownership transfer by calling the into_index method (this could potentially be combined with converting to some new buffer type that can be used for any operation, such as Send). The "extracted" buffer (the one that has been converted to an index) can later be returned to the kernel by calling unsafe_recycle and passing the saved buffer index (this can only be done safely when we can guarantee that the buffer will no longer be used by user-space code and that there are no operations in progress that can use that buffer).
The reference C implementation is a good source of examples, io_uring-udp.c - is one example of using a buffer ring. buf-ring.c - another one.
There was a problem hiding this comment.
@dmitry-salin sorry, I'm far from being an expert on io_uring. I hugely appreciate any help from you and this was a good explanation. Unfortunately, the C example is not easily transferrable to the Mojo code, and, with my current expertise, I'm not sure the exact change I need to do.
However, I've tried and this change seems to work well, but not sure if it's correct: msaelices@8244e65
Could you please take a look?
There was a problem hiding this comment.
Any chance of taking a look to the example? Thanks in advance
11314e0 to
62be884
Compare
Disclaimer: Not sure if this change is right or not
62be884 to
8244e65
Compare
Echo server example that uses ring mapped buffers