nvme: CQ db_buf EventIdx should slightly lag CQ tail#1026
Merged
Conversation
hawkw
reviewed
Jan 28, 2026
Doorbell buffers want the CQ event index to roughly track with the tail, because most CQ doorbells are not interesting. If there are ten CQ entries, space for 54 more, and the guest has acknowledged one, we don't really care anything happened. If there are 64 CQ entries, 0 available, and one SQ entry that we're notified for, we'll try to reserve space in a full CQ, see it's at capacity, and the SQ will idle with the CQ aware that that SQ is corked. Without doorbell buffers, at some point the guest will process a CQE, ring a CQ doorbell, uncork the CQ, and we'll nudge the parked SQ worker thread into operation again. With doorbell buffers, if the event index matches the CQ tail we'll never get a doorbell when the CQ has been drained. If the guest never submits another I/O on the corked SQ, the pending I/O may never get processed. A more careful treatment would only have the event index lag if we are at risk of having a worker thread defer an I/O because this CQ would be full. This would look something like not letting EventIdx advance so far forward that there is less than one entry available for each SQ pointed at this CQ. Eating the unnecessary doorbell cost at least gets doorbell buffers correct in this case and we can turn it back on. The more careful treatment of EventIdx can come later.
This reverts commit d6cd957.
hawkw
approved these changes
Jan 28, 2026
Member
hawkw
left a comment
There was a problem hiding this comment.
looks good to me, though you may want a look from someone who knows more about the NVMe standard than I do.
3c8e3a4 to
9484c10
Compare
Contributor
Might be worth recording that in the source commentary for future-you (or someone else). It seems like implementing that wouldn't be too onerous at some point down the line, and would get things back to nearly full elision. |
pfmooney
approved these changes
Jan 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Doorbell buffers want the CQ event index to roughly track with the tail,
because most CQ doorbells are not interesting. If there are ten CQ
entries, space for 54 more, and the guest has acknowledged one, we don't
really care anything happened.
If there are 64 CQ entries, 0 available, and one SQ entry that we're
notified for, we'll try to reserve space in a full CQ, see it's at
capacity, and the SQ will idle with the CQ aware that that SQ is corked.
Without doorbell buffers, at some point the guest will process a CQE,
ring a CQ doorbell, uncork the CQ, and we'll nudge the parked SQ worker
thread into operation again.
With doorbell buffers, if the event index matches the CQ tail we'll
never get a doorbell when the CQ has been drained. If the guest never
submits another I/O on the corked SQ, the pending I/O may never get
processed.
A more careful treatment would only have the event index lag if we are
at risk of having a worker thread defer an I/O because this CQ would be
full. This would look something like not letting EventIdx advance so far
forward that there is less than one entry available for each SQ pointed
at this CQ.
Eating the unnecessary doorbell cost at least gets doorbell buffers
correct in this case and we can turn it back on. The more careful
treatment of EventIdx can come later.