On 6/9/22 4:14 AM, Hao Xu wrote: > On 6/9/22 18:06, Jens Axboe wrote: >> On 6/9/22 1:53 AM, Hao Xu wrote: >>> Hi all, >>> I haven't done tests to demonstrate it. It is for partial io case, we >>> don't consume/release the buffer before arm_poll in ring-mapped mode. >>> But seems we should? Otherwise ring head isn't moved and other requests >>> may take that buffer. What do I miss? >> >> On vacation this week, so can't take a look at the code. But the >> principle is precisely not to consume the buffer if we arm poll, because >> then the next one can grab it instead. We don't want to consume a buffer >> over poll, as that defeats the purpose of a provided buffer. It should >> be grabbed and consumed only if we can use it right now. >> >> Hence the way it should work is that we DON'T consume the buffer in this >> case, and that someone else can just use it. At the same time, we should >> ensure that we grab a NEW buffer for this case, whenever the poll > > If we grab a new buffer for it, then we have to copy the data since we > have done partial io...this also defeats the purpose of this feature. For partial IO, we never drop the buffer. See the logic in io_kbuf_recycle(). It should be as follows: - If PARTIAL_IO is set, then hang on to the buffer. You can't consume a partial buffer anyway. - If no IO has been done and it's a ring provided buffer, just hang on to the bgid and clear the fact that we grabbed a buffer. That's all you need to do in this case, someone else may grab it and we'll grab a new one for this request whenever it's time to do so. > What the legacy provided buffer mode do in this case is just > keep/consume that buffer. So I'd think we should keep the consistency. > But yes, there may be a better way. The legacy mode has to do that, as it always has to grab the buffer. We don't need to do that in the ring case, it's an efficiency thing as well. If we do need to arm poll, we don't have to do anything but ensure that we grab a new one next time. Consuming it would be the wrong thing to do in that case, as it defeats the purpose of a provided buffer. You may as well just pass in a buffer at that point. -- Jens Axboe