Skip to content
WebsiteHosting.com

concept Linux & administration

io_uring submission and completion queues

An io_uring completion identifies the request that finished, not necessarily the first one submitted. For an ordinary single-shot read, match its terminal result to its buffer before reuse.

Latest recorded source check · P0170

What it means

In io_uring, submitting a request does not mean it has finished. The submission queue describes work to do; the completion queue reports results. If you submit two independent reads, A and then B, the first result can belong to B. To decide whether a buffer can be reused, match the result to the request that uses that buffer, then check what counts as completion for that operation.

Try it

Simulation: A and B are ordinary single-shot reads, each with its own buffer. Each read has one final result, called its terminal completion. The simulation uses supplied observations; it does not perform I/O.

io_uring submission and completion queues

Explain asynchronous submission/completion ordering and buffer lifecycle

Simulation
Modeled outcome: Wait

Target operation has no terminal CQE; cancellation request status is not a buffer-release proof.

io_uring submission and completion queues: synthetic scenario inputs
Replaces all inputs with the documented starting example and the indicated change. Reset restores the starting example.
Submission versus completion identity

Submission queue

  1. OperationA
  2. OperationB

Completion queue

  1. Bsuccess

Buffer reuse

  1. Selected operationA
  2. Terminal statepending
  3. Reusable under premiseNo

The completion list uses the fixture’s stipulated order. A cancellation-request completion is not the selected operation’s terminal completion.

Evaluated inputs

Required scenario evidence
provided
Operation A CQE evidence observed by caller
pending
Operation B CQE evidence observed by caller
success
Cancel request CQE
not-issued
Buffer proposed for reuse
A

Two independent ordinary single-shot buffered read-like operations, distinct synthetic buffers and identifiers, CQE observations supplied, shown B-before-A order is stipulated for both complete. Cancel-A request tracked separately. No actual I/O, kernel API, real pointer, multishot, zero-copy send notification, registered buffers or linked operations; those have different lifetime contracts. Only target terminal CQE permits reuse in this example. In this conservative caller-evidence model, pending means target terminal CQE not yet observed by the caller, not proof that it was not posted. The liburing cancellation manual states successful cancel posts the target completion by submit return; EALREADY can require waiting.

About this model

The controls set only a local, bounded scenario. The computed branch is not a verdict about a live system. Inputs listed as not evaluated did not participate in this branch after validation.

Reset restores the original inputs. It does not change the open or closed state of help or FAQ answers.

Start with the two submission queue entries (SQEs) in order: A, then B. There is just one observed completion queue entry (CQE): B: success. No cancellation was issued. With buffer A selected for reuse, the result is wait: the caller has a result for B, not for A.

  1. Change Buffer proposed for reuse from A to B. The entries in both queues stay the same, but the result changes to release. The one observed CQE matches the request that uses the selected buffer.
  2. Select buffer A again. Set Cancel request CQE to accepted. The observed entries now include cancel-A: accepted alongside B: success. The result for A is still wait.
  3. Leave the cancel result alone and change Operation A CQE evidence observed by caller from pending to canceled. Now there is an A: canceled entry. The result changes to release because A itself has a terminal result, not because the cancel request was accepted.

Reset restores A to pending, B to success, cancellation to not-issued, and the proposed buffer to A, with scenario evidence provided. If you instead set the required evidence to missing, the result is unknown: the simulation does not evaluate either buffer.

Read the identifier before the result

The caller can put an identifier in an SQE’s user_data and get that value back in the CQE. In the starting example, reading only success tells you that a read succeeded. Reading the identifier B tells you which read succeeded. Assigning that result to A just because A was submitted first would release the wrong buffer.

Cancellation makes that distinction especially important. cancel-A identifies a request about A; it is not A’s identifier. Also, posting a CQE and observing it are different events. The liburing cancellation manual says that on successful cancellation, the target CQE has been posted by the time submission of the cancellation request returns. With EALREADY, the caller may still need to wait for the target completion. In the simulation, A: pending means the caller has not observed A’s terminal CQE. It does not mean the kernel has not posted one.

A terminal result need not be a successful read. Suppose the caller sees A: error and cancel-A: not-found, while B is still pending. A’s read failed, but its use of its buffer is over under this single-shot contract. It is A: error that justifies reuse; cancel-A: not-found alone would not.

Select buffer A while A is pending, B has completed and the cancellation request reports accepted. The completion list includes B and the cancellation request, yet A remains unavailable for reuse. Select B instead and the completed target permits reuse under this fixture. Completion identity matters even when two operations involve similar buffers; the example does not model multishot or zero-copy lifetime rules.

In practice

When reviewing a completion handler, start with the buffer it proposes to reuse. Find the request associated with that buffer, match its identifier to the observed CQE, and check whether that CQE ends the operation’s use of the buffer. Keep the result of a cancel request separate. “Can I reuse this memory?” and “Did the read succeed?” are different questions.

The two reads here are independent, and the simulation lists B before A when both have results. That order illustrates a possibility, not a scheduling rule. The example does not cover linked operations or registered buffers. A multishot request can produce several CQEs, and a zero-copy send may require a separate notification before the buffer can be modified. If a CQE matches the right request but you do not know whether it ends buffer use, check that operation’s completion or notification contract before reusing the memory.

Frequently asked questions

Editorial questions based on the listed sources and explicitly labeled local examples.

Does submission mean the kernel has finished with the buffer?

No. A submitted asynchronous operation may still use its buffer. Follow the specific operation lifetime contract and completion evidence.

How can completions be matched to operations?

An operation’s user_data can carry an identifier returned with its completion. A queue position alone is not proof of which request completed.

Does the cancellation result substitute for the target completion?

No. A completion for a cancellation request and the terminal completion of its target are different records. In this fixed single-operation fixture the target must be terminal before its buffer is reusable.

Does this rule cover multishot or zero-copy operations?

No. A multishot request can produce several completions. A zero-copy send may require a separate notification before the buffer can be modified. The example is restricted to its ordinary single-shot target/cancel completion contract; check the actual operation before reusing memory.

Sources & model boundaries

Primary references used for this explanation. The interactive example is an educational model, not a live check.

  1. io_uring(7)

    DESCRIPTION. io_uring submission and completion rings are distinct. user_data identifies a completion; submission is not completion.

    Checked .

  2. liburing: io_uring_prep_cancel(3)

    ERRORS and NOTES. Cancellation reports its own outcome; missing target or progressed operation can have different results; successful cancellation posts target completion by submit return, EALREADY can require waiting.

    Checked .

  3. io_uring_enter(2)

    Multishot and zero-copy notification completions. Multishot requests may yield multiple completions. Zero-copy sends can need a later notification before buffer reuse. Check the operation-specific contract.

    Checked .

Report an issue. Include the article URL and ID, not passwords or access keys.