OSDN Git Service

block/nvme: switch to a NVMeRequest freelist
authorStefan Hajnoczi <stefanha@redhat.com>
Wed, 17 Jun 2020 13:21:58 +0000 (14:21 +0100)
committerStefan Hajnoczi <stefanha@redhat.com>
Tue, 23 Jun 2020 14:46:08 +0000 (15:46 +0100)
commit1086e95da1705087db542276dcbb8ba4d55cb97f
tree902fab085bd0d37440711bc03acd15647c41af5c
parent04b3fb39c815e6de67c5003e610d1cdecc911980
block/nvme: switch to a NVMeRequest freelist

There are three issues with the current NVMeRequest->busy field:
1. The busy field is accidentally accessed outside q->lock when request
   submission fails.
2. Waiters on free_req_queue are not woken when a request is returned
   early due to submission failure.
2. Finding a free request involves scanning all requests. This makes
   request submission O(n^2).

Switch to an O(1) freelist that is always accessed under the lock.

Also differentiate between NVME_QUEUE_SIZE, the actual SQ/CQ size, and
NVME_NUM_REQS, the number of usable requests. This makes the code
simpler than using NVME_QUEUE_SIZE everywhere and having to keep in mind
that one slot is reserved.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Sergio Lopez <slp@redhat.com>
Message-id: 20200617132201.1832152-5-stefanha@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
block/nvme.c