Search

A technology, a device or an article

How an SSD distinguishes a new NVMe completion from an old ring entry

A completion entry stays in memory after it is read. Phase tags, SQID/CID and doorbells let NVMe distinguish ring laps and coordinate ownership of queue slots.

A ceramic ring with four recesses and two-color tokens, one slightly lifted
ITNWS AI-generated conceptual illustration. A sculptural metaphor for queue laps and phase changes; not an SSD design or a literal CQ.ITNWS · image_gen · Original ITNWS AI-generated conceptual editorial illustration

An entry that has been read does not disappear from memory. If the driver has processed the completion of the SSD command, the corresponding bytes may remain in the same place. After some time, the queue will return to the same slot. To understand whether a new result has appeared there, it is not enough to see the familiar identifier and plausible status again. We need an agreement that separates the next lap of the ring from the previous one. In NVMe over PCIe, this is done using the phase tag – a small flag, the meaning of which exists together with the position of the consumer and the rules for memory reuse.

We are talking specifically about the NVMe queue model with exchange through memory. It is impossible to transfer all of its fields to NVMe over Fabrics: for the network model, some of the fields in question are reserved or served differently. NVM Express Base 2.0e, dated July 29, 2024, describes these differences directly. Document verified November 3, 2026. This is an analysis of the existing SSD interface mechanism, and not a message about a new standard, a new drive model, or a detected editorial system failure.

Submission Queue, SQ, contains commands submitted by the host. Completion Queue, CQ, accepts records of their completion. These are two different rings with different producers and consumers. The host advances the SQ tail, announcing new commands; the controller advances its side of processing and publishes CQ entries. After reading completions, the host reports a new CQ head, freeing the corresponding slots. Reducing both directions to one word “queue” is convenient in conversation, but is not enough to prove correct memory ownership.

It’s not just the slot number that matters. A command receives a Command Identifier, CID, within its SQ. The completion record contains the SQ Identifier and CID, allowing it to be matched to the original command. Multiple SQs in a supported configuration can share the same CQ, so one CID is not the global name for all controller operations. The command with CID 7 from SQ 2 and the command with CID 7 from SQ 3 are distinguishable. If the diagnostic log threw out the SQ number, it may have lost some of the identity needed to correctly reconstruct the events.

The identifier is not necessarily equal to the command’s position in the ring and does not have to remain unique forever. It is needed to distinguish between corresponding outstanding commands within its scope. Once completed and resources have been properly released, it can be used again according to the protocol. Therefore, when reading a long trace, a temporal context is required: the same SQID/CID pair at different times can refer to different operations. Uniqueness among current work and eternal uniqueness of the journal are different requirements, and the interface does not automatically promise the latter.

The order in which CQ entries appear cannot be considered a list of submitted commands in the order they were sent either. The controller is capable of completing independent operations in a different order. It is the identifiers that allow you to associate the response with the request without guessing the connection by order. If an application requires an order of effects, it must be specified by the provided tools and the rules of specific commands. Returning the status for a later submission does not in itself prove that all earlier operations have already ended. For SSDs, this distinction is especially important when multiple independent requests are running in parallel.

One bit identifies a particular lap

Let’s consider an illustrative CQ of four slots with numbers 0, 1, 2 and 3. Before creating the queue, the host initializes the phase bits to zero. The controller publishes the first new completions with P equal to 1. The host starts at position 0 and waits for this phase. As long as the P in the current slot does not match the expected one, there is no new completion to process at that position. When it matches, the entry belongs to the desired turn. Other fields by themselves do not replace this check.

Suppose the controller placed the first completion in slot 0. The host processed it and moved to slot 1, then similarly went through the remaining positions, promptly reporting the release. After position 3, the consumer returns to 0 and changes the expected phase to 0. Old first-pass records may still contain P = 1. Therefore, they no longer look new. On the next pass, the controller publishes P = 0 in the corresponding slots; this makes the new entry distinguishable again. The next lap changes the phase again.

Zero here does not mean “empty forever,” and one does not mean “ready forever.” This is the relative agreement between the content of the record, the current position and the expected phase. After two laps the value will be repeated again. The scheme remains correct thanks to the management of free slots: the producer does not have the right to uncontrollably rewrite records that have not yet been consumed. Phase tag does not replace the rules for filling the ring. One bit does not store an endless history, but with established ownership of slots, such a history is not required for the next consumer decision.

Therefore, the host does not need to clear each CQ entry after reading for the sake of a processing flag. Its head and expected phase contain the required consumer state. Excessive nulling is not the essence of the protocol and can interfere with memory exchange. The argument revolves around who has the right to use the slot now and how the parties communicate the transfer of this right. If you take one buffer out of its temporal context, its bytes will not tell you which entries have already been consumed and which are still pending.

The initial state is especially indicative. If the queue memory is not prepared as required, a random old P is able to match the expected phase and present garbage as a new result. Correct initialization is part of the proof, not tidying up for appearance’s sake. After re-creating the queue, you need to honor the new initial contract, and not continue the same wait based on the memory of the old ring. Reset and restore require their own management of pending requests. One phase bit seen does not determine the fate of the operation before the reset.

Green and burgundy ribbons with embossed shapes converge on a shared white strip
ITNWS AI-generated conceptual illustration. An image of matching a completion to its submission queue and command. The shapes are not protocol bit fields. — ITNWS · image_gen · Original ITNWS AI-generated conceptual editorial illustration

The entry also contains SQ Head Pointer, SQHD. It reports the head value of the original SQ when the completion entry was created, allowing the host to understand which submission slots holding command descriptions have already been consumed by the controller and can be used again. However, the specification specifically warns that advancing SQHD does not imply the execution or completion of every corresponding command. The controller could take the description into its own processing, freeing the SQ slot before the end of the operation. Space for a new command and readiness of the old command’s result refer to different resources.

This implies a significant difference in lifetime. An SQ slot with a description can become reusable while the data of the operation itself and related resources are still needed. You can’t release everything just because of the SQHD movement. Conversely, the completion of a particular CID does not need to be the only source of information about the number of SQ entries already consumed: a single response can report the progress of a head through several slots. The fields describe different relationships. Trying to force them to be one universal meter of completed work defeats the purpose of both.

For CQ, the release boundary is communicated by the host via the Completion Queue Head Doorbell. Such a doorbell does not re-run the processed command and is not a request to write its data to the medium. It passes the new position of the consumer so that the controller can reuse the corresponding completion slots. SQ Tail Doorbell has a different subject: announce submitted commands. Both actions can group multiple records, and a single signal need not correspond to exactly one application request. The number of register writes is also not equal to the number of user operations.

Phase tag must publish a complete entry. If a CQ entry is constructed by several memory writes, the specification requires that P be updated in the last write. Otherwise, the consumer might see the new result indicator before the rest of its fields. On the host side, the platform’s read ordering is required. Knowing that "the new bit is already visible" is not enough to randomly read the remaining bytes outside of DMA and memory rules. This protocol connects the device and the CPU, and does not exist only in the abstract array of a single sequential thread.

Source code for PCI NVMe driver on Linux, reviewed on preparation day, shows a concrete implementation of this responsibility. The nvme_cqe_pending function compares phase with the expected state, and dma_rmb() is used in the processing path before reading the rest. After moving through the end of the ring, the expected phase is inverted. This is an example from the researched live branch, not a promise of the same code in all versions of the kernel, and not a guide to independently implement the driver based on one fragment of the article.

NVMe definitions in the Linux header help map field names to the software representation of completion. But the raw byte format and a status field already extracted by a library need to be distinguished. In a word containing a status, P occupies its own least significant bit. Therefore, a raw word with its phase bit set does not turn a successful completion into an error. Before decoding, it must be determined whether the previous layer has removed the phase bit and how the remaining fields are represented. A number without a format description can sound convincing and mean something completely different.

Interrupt notification is another separate event. It helps the host pay attention to the work, but does not replace reading the CQ according to the rules of the protocol. Notification grouping can combine multiple completions, and polling can bypass the need to wait for a separate interrupt for each. In any case, the consumer needs to determine the presence of new records and associate them with commands. From the number of interrupts, it is not possible to reconstruct without additional conditions the exact number of completed user requests, the size of the transferred data, or the number of internal NAND operations.

You should not look in CQE for a complete internal data movement log. Completion refers to a specific command with its documented guarantees. The controller can serve it with many internal actions that the entry does not list. Likewise, after a slot is reused, the bytes of the new result do not retain access to the old one. For subsequent investigation, the driver or observer must separately record the event in question with time and context. The working ring is an exchange channel, and not an archive designed to restore the entire past sequence of operations.

If the host processes several ready CQ entries in one pass, it can report the new head position with a single doorbell write. This reduces the number of consumption notifications while maintaining the meaning of each individual record processed. However, release cannot be delayed indefinitely: the finite capacity of the ring limits the space for further results. Thus, the effectiveness of grouping remains related to resource ownership. Deferring more doorbell writes does not give the controller more slots until the new head has actually been communicated.

Queue depth also does not promise a given speed on its own. The large capacity of the ring allows a certain amount of work to be represented, but useful parallelism depends on the load, the controller, and the path forward. Even instantaneous CQ processing does not cancel the media latency, and fast media does not help a command that the host has not yet issued. Therefore, the considered scheme is a proof of the correct exchange of results, and not an IOPS formula. The four illustrative slots provide no measured timing for a real drive.

The application’s work may finish later still. A completed command with a certain status does not automatically complete a file system transaction, permanently store all associated data, or complete a user request. These statements require their own rules and observations. The SSD ring solves the exact problem of distinguishing a new entry, associating it with a command, and negotiating space reuse. Memory may retain old bytes indefinitely after they are read; correctness is preserved because the right to read them as a new event is specified by the protocol.

Sources & documentation

  1. NVM Express Base 2.0e ↗
  2. Linux NVMe PCI host driver ↗
  3. Linux NVMe protocol definitions ↗