nvme: Limit max completions in a single poll

For a single poll of the completion queue, if the user
submits I/O from within their completion callback and their
completion callback is particularly slow to execute, the loop
could potentially continue forever. To support this, we
need to limit the number of completions we'll process
in one batch.

Change-Id: If6bae47e52b36347dbe5622ace68c866ee88a0b2
Signed-off-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Ben Walker 2016-07-07 08:51:16 -07:00 committed by Daniel Verkamp
parent 20c1996756
commit c65e726acd

View File

@ -454,13 +454,14 @@ spdk_nvme_qpair_process_completions(struct spdk_nvme_qpair *qpair, uint32_t max_
return 0; return 0;
} }
if (max_completions == 0) { if (max_completions == 0 || (max_completions > (qpair->num_entries - 1U))) {
/* /*
* max_completions == 0 means unlimited; set it to the max uint32_t value * max_completions == 0 means unlimited, but complete at most one
* to avoid a special case in the loop. The maximum possible queue size is * queue depth batch of I/O at a time so that the completion
* only 64K, so num_completions will never reach this value. * queue doorbells don't wrap around.
*/ */
max_completions = UINT32_MAX; max_completions = qpair->num_entries - 1;
} }
while (1) { while (1) {