TopTechnical DictionaryNCQ (Native Command Queuing)

NCQ (Native Command Queuing)

NCQ is a software-based extension of SATA interface in which received read and write commands are queued to improve efficiency (number of I/O per second) of both HDDs and SSDs.

 

In standard HDDs, up to 32 commands are buffered and queued to perform scheduled tasks with a minimum number of platter turns and head movements. It reduces the time required for I/O operations as well as the overall degradation of electromechanical components.

 

Fig. 1 Read/write operations: (a) NCQ disabled, (b) NCQ enabled

 

HDD shown in Fig. 1 performs I/O operations: (a) with NCQ disabled - in a sequence from A to F, while performing 3.5 platter turns; (b) with NCQ enabled - in the following sequence C → A → B → D → F → E while performing two complete platter turns.

 

NCQ is an extension of the queuing concept used in TCQ (Tagged Command Queuing) technology, previously implemented in SCSI and ATA drives and partially implemented in SATA-I drives. It differs from its precursor by the number of subsequent processed I/O operations and allows issuing the next command by the host while performing other tasks.
Native command queuing was introduced with SATA-II interface drives (later partially implemented in SATA-I drives).

 

NCQ is supported by three key protocols:

- (Status Return Mechanism) - transferring data on completing one or more scheduled I/O operations. The host is not informed on the start of the I/O operation, however it receives a signal about the end of the operation.

- Reducing the number of interruptions up to one per scheduled I/O operation (Interrupt Aggregation) – the host should be informed about each completed I/O command. The tasks related to the data physically close to each on the drive are grouped and queued. It may lead to a situation where several I/O commands end at the same time or in short time one after each other. The information about completing all 32 operations can be transmitted in a single 64-bit package instead of 64 packages with NCQ disabled. SATA-I and ATA drives require two interruptions for each I/O operation (command start and end).

- Direct memory access mechanism (First Party DMA – FPDMA) – NCQ is designed for HDD to select the next data transfer task to complete. The drive sends an I/O command tag/ID to the host memory controller and reserves a space for buffered data directly in the internal memory. Thus, the drive can effectively change the order of the commands, and may reserve the space for the buffered data without involving the host software.

 

Many new NCQ functions were introduced in SATA-III interface. The improvements included queueing management and commands for improved streaming of multimedia content by allowing the host to send information on operations to be stopped or assigned a higher priority. As a result, general system performance, as well as the number of I/O operations per second were improved.
An isochronous data transfer was also implemented to provide smooth transmission to high-throughput applications (audio/video) and parallel transfer for lower priority tasks.

 

NCQ implemented in SATA-II interface may also affect the performance of scheduled I/O tasks and reduce the operating system performance. The algorithm does not assign time slots for individual I/O operations, and the number of times a specific scheduled I/O operation can be moved to the end of the queue is not limited. Execution of a specific I/O command could have been delayed by other queries leading to process starvation.
It could be observed in Linux systems with RAID-5 matrix. During the test, a lower priority task was completed after 57,118 ms (and after 2,021 ms with NCQ disabled). In 2008, Google Inc. performed a series of internal tests proving that under specific conditions, some scheduled I/O processes may be delayed by up to 2 seconds (in any operating system).
Those issues have been solved by introducing SATA-III interface – and adding "Deadline Handling" subcommand to the queue manager to control the time limit for I/O operations with the lowest priority.

 

Due to the SSD drive design (multiple NAND memory chips connected to a single controller and no mechanical components), NCQ tasks are performed using a deep queueing function where the scheduled I/O tasks are grouped by the controller and run on multiple NAND memory chips.

 

NCQ is supported by HDD/SSD drives with a compatible controller only.