Skip to content

Commit 204e5b3

Browse files
committed
nvme_vfio: limit max submission batch size to 32
We can't let hardware wait too long, otherwise performance hurts. Signed-off-by: Ming Lei <tom.leiming@gmail.com>
1 parent c164750 commit 204e5b3

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

targets/nvme/ublk.nvme_vfio.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,16 +1393,21 @@ static inline void nvme_sq_flush(struct nvme_queue *nvmeq)
13931393
/* Submit command to SQ */
13941394
static inline void nvme_sq_submit_cmd(struct nvme_queue *nvmeq)
13951395
{
1396-
__u16 next_tail;
1396+
__u16 next_tail, pending;
13971397

13981398
if (++nvmeq->sq_tail == nvmeq->qsize)
13991399
nvmeq->sq_tail = 0;
14001400

1401-
next_tail = nvmeq->sq_tail + 1;
1402-
if (next_tail == nvmeq->qsize)
1403-
next_tail = 0;
1404-
if (next_tail != nvmeq->last_sq_tail)
1405-
return;
1401+
/* Flush when batch reaches 32 or SQ is full */
1402+
pending = (nvmeq->sq_tail + nvmeq->qsize - nvmeq->last_sq_tail)
1403+
% nvmeq->qsize;
1404+
if (pending < 32) {
1405+
next_tail = nvmeq->sq_tail + 1;
1406+
if (next_tail == nvmeq->qsize)
1407+
next_tail = 0;
1408+
if (next_tail != nvmeq->last_sq_tail)
1409+
return;
1410+
}
14061411

14071412
nvme_sq_flush(nvmeq);
14081413
}

0 commit comments

Comments
 (0)